Some fix for syndication and webmentions

This commit is contained in:
fundor333
2025-01-24 14:06:51 +01:00
parent db90f26796
commit 6c62b5c749
5 changed files with 51 additions and 17 deletions

View File

@@ -9,7 +9,7 @@ import hashlib
http_domain = "https://fundor333.com" http_domain = "https://fundor333.com"
domain = "fundor333.com" domain = "fundor333.com"
token = os.getenv("WEBMENTIONS_TOKEN") token = os.getenv("WEBMENTIONS_TOKEN")
since_days = 31 since_days = 360 * 20 # 31
class WebmentionFinder: class WebmentionFinder:
@@ -71,10 +71,43 @@ class WebmentionFinder:
files = os.listdir(path_f) files = os.listdir(path_f)
out_dict = [] out_dict = {
"source": [],
"stats": {
"like-of": 0,
"bookmark-of": 0,
"mention-of": 0,
"repost-of": 0,
"in-reply-to": 0,
"comments": [],
},
}
source = []
for e in files: for e in files:
with open(os.path.join(path_f, e)) as file: with open(os.path.join(path_f, e)) as file:
out_dict.append(json.load(file)) for element in json.load(file):
source.append(element)
out_dict["source"] += source
comments = []
links = []
for e in source:
wm_property = e["wm-property"]
out_dict["stats"][wm_property] += 1
link = e["wm-source"]
if e.get("content", False):
if not (link in links):
single_data = {
"content": e["content"]["text"],
"link": e["wm-source"],
"author_name": e["author"]["name"],
"author_photo": e["author"]["photo"],
"author_url": e["author"]["url"],
}
comments.append(single_data)
links.append(link)
out_dict["stats"]["comments"] = comments
with open(os.path.join("data", "webmentions", folder + ".json"), "w") as fp: with open(os.path.join("data", "webmentions", folder + ".json"), "w") as fp:
json.dump(out_dict, fp) json.dump(out_dict, fp)

View File

@@ -1,19 +1,13 @@
{{if in site.Params.commentSections .Type}} {{if in site.Params.commentSections .Type}}
<hr> <hr>
<script src="/js/webmention.min.js" {{ partial "webmention" . }}
data-wordcount='50'
data-page-url='{{replace (absURL .RelPermalink) "localhost:1313" "fundor333.com"}}'
data-alternative-url='{{ range .Aliases }}{{ (absURL .) }}{{ end }}' async>
</script>
<div id="webmentions"></div>
<p>To reply to this post, you can send a <a href="https://indieweb.org/Webmention" target="_blank">Webmention</a> or you can toot me at <a href="https://mastodon.social/@fundor333">fundor333@mastodon.social</a> <br> <p>To reply to this post, you can send a <a href="https://indieweb.org/Webmention" target="_blank">Webmention</a> or you can toot me at <a href="https://mastodon.social/@fundor333">fundor333@mastodon.social</a> <br>
You mentioned this post on your site? Send a <a href="https://indieweb.org/Webmention" target="_blank">Webmention</a></p> You mentioned this post on your site? Send a <a href="https://indieweb.org/Webmention" target="_blank">Webmention</a></p>
{{end}} {{end}}
{{if in site.Params.suggestionSections .Type}} {{if in site.Params.suggestionSections .Type}}

View File

@@ -1,3 +1,5 @@
{{ $urlized := (replace (absURL .RelPermalink) "http://localhost:1313" "https://fundor333.com") | md5 }}
{{ $urlized := .Page.Permalink | md5 }} {{ $urlized := .Page.Permalink | md5 }}
{{ if index .Site.Data.syndication $urlized }} {{ if index .Site.Data.syndication $urlized }}

View File

@@ -0,0 +1,7 @@
<script src="/js/webmention.min.js"
data-wordcount='50'
data-page-url='{{replace (absURL .RelPermalink) "localhost:1313" "fundor333.com"}}'
data-alternative-url='{{ range .Aliases }}{{ (absURL .) }}{{ end }}' async>
</script>
<div id="webmentions"></div>

View File

@@ -1,17 +1,15 @@
<h1> ----- </h1> <h1> ----- </h1>
{{ $urlized := .Page.Permalink | md5 }} {{ $urlized := (replace (absURL .RelPermalink) "http://localhost:1313" "https://fundor333.com") | md5 }}
{{index .Site.Data.webmentions $urlized }} {{index .Site.Data.webmentions $urlized }}
{{ if index .Site.Data.webmentions $urlized }} {{ if index .Site.Data.webmentions $urlized }}
{{ $data:= index .Site.Data.webmentions $urlized }} {{ $data:= index (index .Site.Data.webmentions $urlized ) "stats" }}
<h1>---</h1>
{{ range (index .Site.Data.webmentions $urlized )}}
{{ . }}
{{ end }}
{{ $likes := index (index .Site.Data $urlized) "like-of" }} {{ $likes := index (index .Site.Data $urlized) "like-of" }}
{{ $replys := index (index .Site.Data $urlized) "in-reply-to" }} {{ $replys := index (index .Site.Data $urlized) "in-reply-to" }}