Refactor comments handling and update syndication links across multiple posts

This commit is contained in:
Fundor333
2025-06-16 23:33:47 +02:00
parent 74de9cfbfa
commit 265dd76750
17 changed files with 57 additions and 16 deletions

View File

@@ -9,7 +9,23 @@ CARTELLA_POST = "content"
CSV_LOG = "log_feed.csv" CSV_LOG = "log_feed.csv"
MASTODON_FEED = "https://mastodon.social/users/fundor333.rss" MASTODON_FEED = "https://mastodon.social/users/fundor333.rss"
BSKY_FEED = "https://bsky.app/profile/did:plc:u7piwonv4s27ysugjaa6im2q/rss" # facoltativo, se disponibile BSKY_FEED = "https://bsky.app/profile/did:plc:u7piwonv4s27ysugjaa6im2q/rss" # facoltativo, se disponibile
MEDIUM_FEED = "https://medium.com/feed/@fundor333" MEDIUM_FEED = None # "https://medium.com/feed/@fundor333"
def parse_fediverse_url(url):
# Mastodon / Akkoma / Pleroma
match1 = re.match(r"https?://([^/]+)/@([^/]+)/(\d+)", url)
if match1:
host, username, post_id = match1.groups()
return {"host": host, "username": username, "id": post_id}
# Misskey / Firefish
match2 = re.match(r"https?://([^/]+)/notes/([a-zA-Z0-9]+)", url)
if match2:
host, post_id = match2.groups()
return {"host": host, "username": None, "id": post_id}
return None
def process_feed_medium(feed_url, fonte): def process_feed_medium(feed_url, fonte):
@@ -83,7 +99,7 @@ def aggiungi_syndication_a_post(percorso_file, nuovi_link):
content = f.read() content = f.read()
if content.startswith("+++"): if content.startswith("+++"):
raise NotImplementedError("Supporto TOML non ancora gestito.") raise NotImplementedError("Supporto TOML non gestito.")
elif content.startswith("---"): elif content.startswith("---"):
parts = content.split("---") parts = content.split("---")
if len(parts) < 3: if len(parts) < 3:
@@ -92,6 +108,8 @@ def aggiungi_syndication_a_post(percorso_file, nuovi_link):
frontmatter = yaml.safe_load(parts[1]) frontmatter = yaml.safe_load(parts[1])
esistenti = frontmatter.get("syndication", []) esistenti = frontmatter.get("syndication", [])
if isinstance(esistenti, str):
esistenti = [esistenti]
esistenti_norm = set(map(normalizza_url, esistenti)) esistenti_norm = set(map(normalizza_url, esistenti))
nuovi_norm = set(map(normalizza_url, nuovi_link)) nuovi_norm = set(map(normalizza_url, nuovi_link))
@@ -99,7 +117,17 @@ def aggiungi_syndication_a_post(percorso_file, nuovi_link):
da_aggiungere = list(nuovi_norm - esistenti_norm) da_aggiungere = list(nuovi_norm - esistenti_norm)
if da_aggiungere: if da_aggiungere:
# Aggiorna il campo syndication
frontmatter["syndication"] = sorted(esistenti_norm.union(nuovi_norm)) frontmatter["syndication"] = sorted(esistenti_norm.union(nuovi_norm))
# Se troviamo un link Mastodon, estrai info nei meta commenti
for link in da_aggiungere:
parsed = parse_fediverse_url(link)
if parsed:
frontmatter["comments"] = (
parsed # Sostituisce se già esiste (puoi estendere a lista se vuoi)
)
nuovo_frontmatter = yaml.dump( nuovo_frontmatter = yaml.dump(
frontmatter, sort_keys=False, allow_unicode=True frontmatter, sort_keys=False, allow_unicode=True
) )

View File

@@ -27,10 +27,5 @@ repost:
like: like:
rsvp: rsvp:
bookmark: bookmark:
comments:
host: mastodon.social
username: fundor333
id:
--- ---

View File

@@ -16,7 +16,7 @@ bookmark: null
comments: comments:
host: mastodon.social host: mastodon.social
username: fundor333 username: fundor333
id: null id: '114587857806058272'
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lroqnpvein2o - https://bsky.app/profile/fundor333.bsky.social/post/3lroqnpvein2o
- https://mastodon.social/@fundor333/114587857806058272 - https://mastodon.social/@fundor333/114587857806058272

View File

@@ -15,7 +15,7 @@ bookmark: null
comments: comments:
host: mastodon.social host: mastodon.social
username: fundor333 username: fundor333
id: 114627452417111937 id: '114627452417111937'
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lroqna6rpn2o - https://bsky.app/profile/fundor333.bsky.social/post/3lroqna6rpn2o
- https://mastodon.social/@fundor333/114627452417111937 - https://mastodon.social/@fundor333/114627452417111937

View File

@@ -16,7 +16,7 @@ bookmark: null
comments: comments:
host: mastodon.social host: mastodon.social
username: fundor333 username: fundor333
id: 114689671753564243 id: '114689671753564243'
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lroici3xqz22 - https://bsky.app/profile/fundor333.bsky.social/post/3lroici3xqz22
- https://mastodon.social/@fundor333/114689671753564243 - https://mastodon.social/@fundor333/114689671753564243

View File

@@ -12,7 +12,7 @@ bookmark: null
comments: comments:
host: mastodon.social host: mastodon.social
username: fundor333 username: fundor333
id: null id: '114615017065338141'
syndication: syndication:
- https://mastodon.social/@fundor333/114615017065338141 - https://mastodon.social/@fundor333/114615017065338141
--- ---

View File

@@ -15,7 +15,7 @@ bookmark: null
comments: comments:
host: mastodon.social host: mastodon.social
username: fundor333 username: fundor333
id: 114681429148697486 id: '114681429148697486'
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lrkt66xamq2s - https://bsky.app/profile/fundor333.bsky.social/post/3lrkt66xamq2s
- https://mastodon.social/@fundor333/114681429148697486 - https://mastodon.social/@fundor333/114681429148697486

View File

@@ -13,6 +13,7 @@ categories:
- fingerfood - fingerfood
description: If you have a static site you can also have forms description: If you have a static site you can also have forms
syndication: syndication:
- https://fundor333.medium.com/static-with-a-form-in-python-0a11c50a04cd?source=rss-48447ba4c2e
- https://fundor333.medium.com/static-with-a-form-in-python-0a11c50a04cd?source=rss-48447ba4c2e------2 - https://fundor333.medium.com/static-with-a-form-in-python-0a11c50a04cd?source=rss-48447ba4c2e------2
--- ---

View File

@@ -23,7 +23,7 @@ bookmark: null
comments: comments:
host: mastodon.social host: mastodon.social
username: fundor333 username: fundor333
id: 114689582471095983 id: '114689582471095983'
syndication: syndication:
- https://mastodon.social/@fundor333/114689582471095983 - https://mastodon.social/@fundor333/114689582471095983
--- ---

View File

@@ -23,7 +23,7 @@ bookmark: null
comments: comments:
host: mastodon.social host: mastodon.social
username: fundor333 username: fundor333
id: 114690259109867675 id: '114690259109867675'
syndication: syndication:
- https://mastodon.social/@fundor333/114690259109867675 - https://mastodon.social/@fundor333/114690259109867675
--- ---

View File

@@ -18,6 +18,7 @@ feature_text: by IA Midjourney
series: series:
- Tech News - Tech News
syndication: syndication:
- https://fundor333.medium.com/this-is-why-instagram-ruin-itself-5e939a3bd4c6?source=rss-48447ba4c2e
- https://fundor333.medium.com/this-is-why-instagram-ruin-itself-5e939a3bd4c6?source=rss-48447ba4c2e------2 - https://fundor333.medium.com/this-is-why-instagram-ruin-itself-5e939a3bd4c6?source=rss-48447ba4c2e------2
--- ---

View File

@@ -23,7 +23,7 @@ bookmark: https://mxb.dev/blog/webring-kit/
comments: comments:
host: mastodon.social host: mastodon.social
username: fundor333 username: fundor333
id: 114565534042467712 id: '114565534042467712'
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lpxe75uzk52r - https://bsky.app/profile/fundor333.bsky.social/post/3lpxe75uzk52r
- https://mastodon.social/@fundor333/114565534042467712 - https://mastodon.social/@fundor333/114565534042467712

View File

@@ -10,6 +10,10 @@ draft: false
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lroqnv2r652s - https://bsky.app/profile/fundor333.bsky.social/post/3lroqnv2r652s
- https://mastodon.social/@fundor333/114690259884567597 - https://mastodon.social/@fundor333/114690259884567597
comments:
host: mastodon.social
username: fundor333
id: '114690259884567597'
--- ---
- Changing some metadata for better control of what brid.gy publish from my site - Changing some metadata for better control of what brid.gy publish from my site

View File

@@ -10,6 +10,10 @@ draft: false
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lroqnfmvut2y - https://bsky.app/profile/fundor333.bsky.social/post/3lroqnfmvut2y
- https://mastodon.social/@fundor333/114690258752401420 - https://mastodon.social/@fundor333/114690258752401420
comments:
host: mastodon.social
username: fundor333
id: '114690258752401420'
--- ---
- Making some videoediting for a friend - Making some videoediting for a friend

View File

@@ -10,6 +10,10 @@ draft: false
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lr3n2pfd7f23 - https://bsky.app/profile/fundor333.bsky.social/post/3lr3n2pfd7f23
- https://mastodon.social/@fundor333/114647222339157952 - https://mastodon.social/@fundor333/114647222339157952
comments:
host: mastodon.social
username: fundor333
id: '114647222339157952'
--- ---
- And I went to vote for the Referendum - And I went to vote for the Referendum

View File

@@ -10,6 +10,10 @@ draft: false
syndication: syndication:
- https://bsky.app/profile/fundor333.bsky.social/post/3lroqmzb3zz2w - https://bsky.app/profile/fundor333.bsky.social/post/3lroqmzb3zz2w
- https://mastodon.social/@fundor333/114690257976586167 - https://mastodon.social/@fundor333/114690257976586167
comments:
host: mastodon.social
username: fundor333
id: '114690257976586167'
--- ---
- Setup Umami for my personals' sites - Setup Umami for my personals' sites

View File

@@ -8,7 +8,7 @@
{{ partial "webmention" . }} {{ partial "webmention" . }}
{{ $params := .Params.comments }} {{ $params := .Params.comments }}
{{ with .Params.comments.id}} {{ with .Params.comments}}
{{ partial "mastodon" $params }} {{ partial "mastodon" $params }}
{{ end }} {{ end }}