diff --git a/Locale/en.json b/Locale/en.json index e1bd395..a88f14e 100644 --- a/Locale/en.json +++ b/Locale/en.json @@ -2,5 +2,7 @@ "CreatedOn": "Created on", "EditedOn": "Edited on", "Categories": "Categories", - "ReadFullPost": "Read the full post" + "ReadFullPost": "Read the full post", + "Comments": "Comments", + "OpenInNewTab": "Open in a new tab" } diff --git a/Locale/it.json b/Locale/it.json index 5225153..6f71dd7 100644 --- a/Locale/it.json +++ b/Locale/it.json @@ -2,5 +2,7 @@ "CreatedOn": "Creato in data", "EditedOn": "Modificato in data", "Categories": "Categorie", - "ReadFullPost": "Leggi il post intero" + "ReadFullPost": "Leggi il post intero", + "Comments": "Commenti", + "OpenInNewTab": "Apri in una nuova scheda" } diff --git a/README.md b/README.md index 6efe8f5..9d00f09 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Feel free to experiment with all of this stuff! - [html2gmi](https://github.com/LukeEmmet/html2gmi) ## Features roadmap -- [ ] ActivityPub support (Feed + embedded comments) +- [x] ActivityPub (Mastodon) support (Feed + embedded comments) - [ ] Polished Gemtext generation - [x] Autodetection of pages and posts - [x] Info for posts shown on their page diff --git a/Source/Build.py b/Source/Build.py index 4601cef..481fb85 100755 --- a/Source/Build.py +++ b/Source/Build.py @@ -483,17 +483,37 @@ def Main(Args, FeedEntries): Lang=SiteLang, Minify=True if Args.Minify and Args.Minify not in ('False', 'None') else False) - if Args.GemtextOut: - GemtextCompileList(Pages) - if MastodonURL and MastodonToken and SiteDomain: - MastodonShare( + MastodonPosts = MastodonShare( MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Locale) + #print(MastodonPosts) + else: + MastodonPosts = [] + + for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages: + #if Meta['Type'] == 'Post': + File = 'public/{}.html'.format(StripExt(File)) + Content = ReadFile(File) + Post = '' + for p in MastodonPosts: + #print(SiteDomain + File[len('public/'):]) + if p['Link'] == SiteDomain + '/' + File[len('public/'):]: + Post = '

{StrComments}

{StrOpen} ↗️'.format( + StrComments=Locale['Comments'], + StrOpen=Locale['OpenInNewTab'], + URL=p['Post']) + break + #print(Post) + Content = Content.replace('[HTML:Comments]', Post) + WriteFile(File, Content) + + if Args.GemtextOut: + GemtextCompileList(Pages) DelTmp() os.system("cp -R Assets/* public/") diff --git a/Source/Modules/ActivityPub.py b/Source/Modules/ActivityPub.py index f6c2993..bcb427f 100644 --- a/Source/Modules/ActivityPub.py +++ b/Source/Modules/ActivityPub.py @@ -31,17 +31,22 @@ def MastodonDoPost(Session, Text, Lang=None, Visibility='public'): language=Lang, visibility=Visibility) +def MastodonGetLinkPosts(Session, Domain=None): + Posts = [] + for i,e in enumerate(MastodonGetPostsFromUserID(Session, MastodonGetMyID(Session))): + Parse = BeautifulSoup(e['content'], 'html.parser') + if Parse.a: + Link = Parse.find_all('a')[-1]['href'] + if not Domain or (Domain and Link.startswith(Domain)): + Posts += [{ + 'Post': e['uri'], + 'Link': Link}] + return Posts + # TODO: Set a limit/cooldown on how many new posts at a time can be posted, or ignore posts older than date X.. otherwise if someone starts using this after having written 100 blog posts, bad things will happen def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Locale): Session = MastodonGetSession(MastodonURL, MastodonToken) - Posts = MastodonGetPostsFromUserID( - Session, - MastodonGetMyID(Session)) - for i,e in enumerate(Posts): - Parse = BeautifulSoup(e['content'], 'html.parser') - Posts[i] = { - 'URL': e['uri'], - 'LastLink': Parse.find_all('a')[-1]['href'] if Parse.a else None} + Posts = MastodonGetLinkPosts(Session, SiteDomain) Pages.sort() for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages: if Meta['Type'] == 'Post': @@ -60,7 +65,7 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local Desc = p[:500-25-5-len(Read)] + '...' DoPost = True for p in Posts: - if p['LastLink'] == URL: + if p['Link'] == URL: DoPost = False break if DoPost: @@ -68,3 +73,4 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local Session, Desc + Read + URL, SiteLang) + return Posts