mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-05-12 23:58:58 +02:00
Add Mastodon comment embedding (incomplete)
This commit is contained in:
parent
cc7aaf19ec
commit
aff9a36c4a
@ -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"
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 = '<br><h3>{StrComments}</h3><a href="{URL}" rel="noopener" target="_blank">{StrOpen} ↗️</a>'.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/")
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user