mirror of https://gitlab.com/octtspacc/staticoso
Add Mastodon comment embedding (incomplete)
This commit is contained in:
parent
cc7aaf19ec
commit
aff9a36c4a
|
@ -2,5 +2,7 @@
|
||||||
"CreatedOn": "Created on",
|
"CreatedOn": "Created on",
|
||||||
"EditedOn": "Edited on",
|
"EditedOn": "Edited on",
|
||||||
"Categories": "Categories",
|
"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",
|
"CreatedOn": "Creato in data",
|
||||||
"EditedOn": "Modificato in data",
|
"EditedOn": "Modificato in data",
|
||||||
"Categories": "Categorie",
|
"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)
|
- [html2gmi](https://github.com/LukeEmmet/html2gmi)
|
||||||
|
|
||||||
## Features roadmap
|
## Features roadmap
|
||||||
- [ ] ActivityPub support (Feed + embedded comments)
|
- [x] ActivityPub (Mastodon) support (Feed + embedded comments)
|
||||||
- [ ] Polished Gemtext generation
|
- [ ] Polished Gemtext generation
|
||||||
- [x] Autodetection of pages and posts
|
- [x] Autodetection of pages and posts
|
||||||
- [x] Info for posts shown on their page
|
- [x] Info for posts shown on their page
|
||||||
|
|
|
@ -483,17 +483,37 @@ def Main(Args, FeedEntries):
|
||||||
Lang=SiteLang,
|
Lang=SiteLang,
|
||||||
Minify=True if Args.Minify and Args.Minify not in ('False', 'None') else False)
|
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:
|
if MastodonURL and MastodonToken and SiteDomain:
|
||||||
MastodonShare(
|
MastodonPosts = MastodonShare(
|
||||||
MastodonURL,
|
MastodonURL,
|
||||||
MastodonToken,
|
MastodonToken,
|
||||||
Pages,
|
Pages,
|
||||||
SiteDomain,
|
SiteDomain,
|
||||||
SiteLang,
|
SiteLang,
|
||||||
Locale)
|
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()
|
DelTmp()
|
||||||
os.system("cp -R Assets/* public/")
|
os.system("cp -R Assets/* public/")
|
||||||
|
|
|
@ -31,17 +31,22 @@ def MastodonDoPost(Session, Text, Lang=None, Visibility='public'):
|
||||||
language=Lang,
|
language=Lang,
|
||||||
visibility=Visibility)
|
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
|
# 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):
|
def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Locale):
|
||||||
Session = MastodonGetSession(MastodonURL, MastodonToken)
|
Session = MastodonGetSession(MastodonURL, MastodonToken)
|
||||||
Posts = MastodonGetPostsFromUserID(
|
Posts = MastodonGetLinkPosts(Session, SiteDomain)
|
||||||
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}
|
|
||||||
Pages.sort()
|
Pages.sort()
|
||||||
for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages:
|
for File, Content, Titles, Meta, HTMLContent, Description, Image in Pages:
|
||||||
if Meta['Type'] == 'Post':
|
if Meta['Type'] == 'Post':
|
||||||
|
@ -60,7 +65,7 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
|
||||||
Desc = p[:500-25-5-len(Read)] + '...'
|
Desc = p[:500-25-5-len(Read)] + '...'
|
||||||
DoPost = True
|
DoPost = True
|
||||||
for p in Posts:
|
for p in Posts:
|
||||||
if p['LastLink'] == URL:
|
if p['Link'] == URL:
|
||||||
DoPost = False
|
DoPost = False
|
||||||
break
|
break
|
||||||
if DoPost:
|
if DoPost:
|
||||||
|
@ -68,3 +73,4 @@ def MastodonShare(MastodonURL, MastodonToken, Pages, SiteDomain, SiteLang, Local
|
||||||
Session,
|
Session,
|
||||||
Desc + Read + URL,
|
Desc + Read + URL,
|
||||||
SiteLang)
|
SiteLang)
|
||||||
|
return Posts
|
||||||
|
|
Loading…
Reference in New Issue