updating service worker and things

This commit is contained in:
Miguel 2024-09-27 14:55:47 -04:00
parent c35080ca91
commit 8ffebe9543
10 changed files with 525 additions and 47 deletions

View file

@ -1,19 +1,22 @@
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c> <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Enable rewrite rules # Ensure that static files like .js, .css, and service worker are not affected by rewrite rules
RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(js|css|png|jpg|jpeg|gif|svg|ico|json|map)$ - [L]
# Base directory # Ensure service worker is served from the /dist/ folder
RewriteBase /Bludit/ RewriteRule ^dist/sw\.js$ - [L]
# Deny direct access to the next directories
RewriteRule ^bl-content/(databases|workspaces|pages|tmp)/.*$ - [R=404,L]
# All URL process by index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [PT,L]
# For Single Page Application (SPA) routing
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# Add the correct MIME type for .js and .json files
<IfModule mod_mime.c>
AddType application/javascript .js
AddType application/manifest+json .json
</IfModule> </IfModule>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

BIN
img/nostr_192x192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

@ -8,7 +8,13 @@
<meta name="description" content="Miguel's Landing Page"> <meta name="description" content="Miguel's Landing Page">
<meta name="keywords" content="global, template, html, sass, jquery"> <meta name="keywords" content="global, template, html, sass, jquery">
<link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="css/main.css">
<script rel="./service.worker.js"></script>
<script rel="./scripts.js"></script>
<link rel="manifest" href="./manifest.json">
<link rel="icon" type="image/x-icon" href="/img/Menu_Light.png"> <link rel="icon" type="image/x-icon" href="/img/Menu_Light.png">
<script src="https://unpkg.com/nostr-tools/lib/nostr.bundle.js"></script>
</head> </head>
<body> <body>
@ -53,12 +59,12 @@
<ul class="side-nav"> <ul class="side-nav">
<li class="is-active"><span>Home</span></li> <li class="is-active"><span>Home</span></li>
<li><span>Interests</span></li> <li><span>Interests</span></li>
<li><span>Social</span></li>
<li><span>About</span></li> <li><span>About</span></li>
<li><span>Contact</span></li> <li><span>Contact</span></li>
<!--Here I am commenting out a menu item from the vertical
left side nav, reducing from 4 to 5-->
<!--<li><span>Work with Me</span></li>-->
</ul> </ul>
</nav> </nav>
@ -211,6 +217,46 @@
</li> </li>
<!-- End of the second section --> <!-- End of the second section -->
<li class="l-section section">
<div class="intro">
<div class="intro--banner">
<h1>Social Media<br>Revolution.</h1>
<img src="img/nostr-logo-purple-transparent-928x363.png" alt="nostr">
</div>
<div class="intro--options">
<a href="https://uberspace.de">
<h3>Explore my asteroid!</h3>
<p>This site is hosted on asteroids
with Uberspace. I'm learning web development to
be able to make a better impact with my digital presence.
If you are curious about how to set up your own,
just reach out and ask so we can talk about it.
</p>
</a>
<a href="https://nostree.me/npub1ajt9gp0prf4xrp4j07j9rghlcyukahncs0fw5ywr977jccued9nqrcc0cs">
<h3>Creator Residency</h3>
<p>I'm in the Content Creator Residency with nos.social.
Nostr is social media that you control. Find me on nostr
miggymofongo@miguelalmodo.com Ask me to learn
more!</p>
</a>
<a href="https://yakihonne.com/article/naddr1qvzqqqr4gupzpmyk2sz7zxn2vxrtylay2x30lsfedm083q7jagguxtaa933ej6txqq2kgvrrd4zng32dv4fnx6mvgf8n2wr5dc68zlqdkj9">
<h3>Organizer</h3>
<p>Read about my recent trips to Cuba where I attended
this year's May Day celebrations in Havana with
organizers and union members from around
the world. #CubaSIBoqueoNO
</p>
</a>
</div>
</div>
</li>
<!-- Beginning of the third section --> <!-- Beginning of the third section -->
<li class="l-section section"> <li class="l-section section">
<div class="about"> <div class="about">
@ -267,7 +313,7 @@
<div id="result"></div> <div id="result"></div>
<form class="work-request" action="https://api.web3forms.com/submit" method="POST" id="form"> <form class="work-request" action="https://api.web3forms.com/submit" method="POST" id="form">
<input type="hidden" name="access_key" value=""> <input type="hidden" name="access_key" value="15117b52-27ee-40ba-8eef-f6e67c2a3292">
<input type="hidden" name="from_name" value="Asteroid"> <input type="hidden" name="from_name" value="Asteroid">
<div class="work-request--options"> <div class="work-request--options">
@ -532,13 +578,14 @@
<li class="is-active">Home</li> <li class="is-active">Home</li>
<li>Interests</li> <li>Interests</li>
<li>Social</li>
<li>About</li> <li>About</li>
<li>Contact</li> <li>Contact</li>
</ul> </ul>
<!-- <li>Work with Me</li> -->
</ul> </ul>
<!-- Outer nav bar ends --> <!-- Outer nav bar ends -->
@ -588,6 +635,7 @@ form.addEventListener('submit', function(e) {
}); });
}); });
</script> </script>
<script src="js/nostr.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-2.2.4.min.js"><\/script>')</script> <script>window.jQuery || document.write('<script src="js/vendor/jquery-2.2.4.min.js"><\/script>')</script>
<script src="js/functions-min.js"></script> <script src="js/functions-min.js"></script>
<script>window.onload = function() { <script>window.onload = function() {
@ -600,29 +648,3 @@ form.addEventListener('submit', function(e) {
</html> </html>

53
js/nostr.js Normal file
View file

@ -0,0 +1,53 @@
// Define the fetchProfileMetadata function as async
async function fetchProfileMetadata() {
const relay = await Relay.connect('wss://notes.miguelalmodo.com');
console.log(`connected to ${relay.url}`);
const pubkey = 'ec965405e11a6a6186b27fa451a2ffc1396ede7883d2ea11c32fbd2c63996966'; // Set the pubkey
// Subscribe to the profile information from the relay
const sub = relay.subscribe([
{
kinds: [0], // Profile kind
authors: [pubkey],
}
], {
onevent: (event) => {
const profileData = JSON.parse(event.content);
console.log(profileData);
this.aboutText = profileData.about || 'No about info available.';
this.profilePic = profileData.picture;
},
oneose: () => {
sub.close();
}
});
}
// Define the fetchComments function as async
async function fetchComments() {
const relay = await Relay.connect('wss://notes.miguelalmodo.com');
console.log(`connected to ${relay.url}`);
const pubkey = 'ec965405e11a6a6186b27fa451a2ffc1396ede7883d2ea11c32fbd2c63996966';
const comments = [];
const sub = relay.subscribe([
{
kinds: [1], // Nostr kind for text notes
authors: [pubkey], // Filter by your pubkey
limit: 10 // Fetch the last 10 notes
}
], {
onevent: (event) => {
const noteContent = event.content; // Assuming the content is a simple text note
comments.push(noteContent); // Add the comment to the array
this.requestUpdate(); // Trigger re-render
},
oneose: () => {
sub.close();
this.comments = comments; // Update the component's comments property
this.requestUpdate();
}
});
}

21
manifest.json Normal file
View file

@ -0,0 +1,21 @@
{
"name": "miggymofongo's website",
"short_name": "miggymofongo",
"start_url": "index.html",
"scope": "./",
"icons": [
{
"src": "/img/nostr_192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/img/nostr-icon-white-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#ffd31d",
"background_color": "#333",
"display": "standalone"
}

4
scripts.js Normal file
View file

@ -0,0 +1,4 @@
if ("serviceWorker" in navigator) {
// register service worker
navigator.serviceWorker.register("service-worker.js");
}

268
service-worker.js Normal file

File diff suppressed because one or more lines are too long

107
write-policy.py Normal file
View file

@ -0,0 +1,107 @@
#!/usr/bin/env python3
import sys
import json
# ENTER YOUR HEX PUBKEY(S) BELOW:
whitelist = {
"ec965405e11a6a6186b27fa451a2ffc1396ede7883d2ea11c32fbd2c63996966",
"11493e2efadce058f779ee4bd3b6bf9874fe571622704372b1b4d9051397ab32",
"60f1a5eb3310076ae334f432bc178f2ed4aac86abd704ee1626d4a283f1abdec",
"22f11e47397e83cdeb56933aad13a1dd2c4f70ed8c2f5d93dd70b1ea4cdfafa6",
"02f7fe308859d2d6178ada7caca89c2787e1ee2889378ee6e98d530e75cd77b8",
"d10a02474e3ff020d46753336e1c436a7373a84f6c22852749dabf63ea505515",
"c118d1b814a64266730e75f6c11c5ffa96d0681bfea594d564b43f3097813844",
"8f4761dcd2405aab2455bc66e7a54b8f8e5a88dc645e9717df665d1993b740fc",
"a4cc1ed588973e8ce1bf25f8cffed29ffc90838f2359531a54416236010e2dc0",
"e3d9e150b8688085e04a9c7ef079e92078a8f9cd2ce35a36433f34780420b6a3",
}
# ENTER YOUR ALLOWED IP(S) BELOW:
sources = {
"1.1.1.1",
"8.8.8.8"
}
# ENTER YOUR ALLOWED TYPE(S) BELOW:
types = {
"Stream",
"Import",
"Sync"
}
def eprint(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr, flush=True)
def accept(request):
response = {
'id' : request['event']['id']
}
response['action'] = 'accept'
r = json.dumps(response,separators=(',', ':')) # output JSONL
print(r, end='\n', file=sys.stdout, flush=True)
def reject(request):
response = {
'id' : request['event']['id']
}
response['action'] = 'reject'
response['msg'] = f"blocked: pubkey {request['event']['pubkey']} not in whitelist | SOURCE: {request['sourceInfo']}"
r = json.dumps(response,separators=(',', ':')) # output JSONL
print(r, end='\n', file=sys.stdout, flush=True)
def main():
for line in sys.stdin:
request = json.loads(line)
try:
if request['type'] == 'lookback':
continue
except KeyError:
eprint("input without type in write policy plugin")
continue
if request['type'] != 'new':
eprint("unexpected request type in write policy plugin")
continue
try:
if not request['event']['id']:
eprint("input without event id in write policy plugin")
continue
except KeyError:
eprint("input without event id in write policy plugin")
continue
try:
if request['event']['pubkey'] in whitelist:
accept(request)
continue
elif int(request['event']['kind']) == 10002:
accept(request)
continue
elif request['sourceType'] in types:
accept(request)
continue
elif request['sourceInfo'] in sources:
accept(request)
continue
elif request.get("event", {}).get("tags"):
if p_tags:= [x for x in request['event']['tags'] if x[0] == 'p']:
pubkeys = [x[1] for x in p_tags]
if whitelist.intersection(pubkeys):
accept(request)
continue
reject(request)
continue
else:
reject(request)
continue
except KeyError:
eprint("poorly formed event input in write policy plugin")
continue
if __name__=='__main__':
main()