mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-06-05 22:09:23 +02:00
Redirect generation patches, support as ActivityPub post URLs
This commit is contained in:
@ -40,7 +40,8 @@ Needed for Gemtext output support:
|
|||||||
|
|
||||||
## Features roadmap
|
## Features roadmap
|
||||||
|
|
||||||
- [ ] Showing percentage of build process
|
- [ ] Page redirects / Alt URLs (+ ActivityPub URL overrides)
|
||||||
|
- [x] Progress bars for the build process!
|
||||||
- [x] Multithreading
|
- [x] Multithreading
|
||||||
- [x] Differential building
|
- [x] Differential building
|
||||||
- [ ] Overriding internal HTML snippets for template-specific ones
|
- [ ] Overriding internal HTML snippets for template-specific ones
|
||||||
|
@ -246,13 +246,14 @@ def Main(Args, FeedEntries):
|
|||||||
DestFile = f"{OutDir}/{URL}"
|
DestFile = f"{OutDir}/{URL}"
|
||||||
if DestFile not in FinalPaths:
|
if DestFile not in FinalPaths:
|
||||||
DestURL = f"{GetPathLevels(URL)}{StripExt(File)}.html"
|
DestURL = f"{GetPathLevels(URL)}{StripExt(File)}.html"
|
||||||
|
mkdirps(os.path.dirname(DestFile))
|
||||||
WriteFile(
|
WriteFile(
|
||||||
DestFile,
|
DestFile,
|
||||||
RedirectPageTemplate.format(
|
RedirectPageTemplate.format(
|
||||||
DestURL=DestURL,
|
DestURL=DestURL,
|
||||||
TitlePrefix=f"{SiteName} - " if SiteName else '',
|
TitlePrefix=f"{SiteName} - " if SiteName else '',
|
||||||
StrClick=Locale["ClickHere"],
|
StrClick=Locale['ClickHere'],
|
||||||
StrRedirect=Locale["IfNotRedirected"]))
|
StrRedirect=Locale['IfNotRedirected']))
|
||||||
|
|
||||||
if Flags['GemtextOutput']:
|
if Flags['GemtextOutput']:
|
||||||
logging.info("Generating Gemtext")
|
logging.info("Generating Gemtext")
|
||||||
|
@ -61,11 +61,17 @@ def MastodonShare(Flags, Pages, Locale):
|
|||||||
Pages.sort()
|
Pages.sort()
|
||||||
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
for File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image in Pages:
|
||||||
if (not TypeFilter or (TypeFilter and (Meta['Type'] == TypeFilter or TypeFilter == '*'))) and (not CategoryFilter or (CategoryFilter and (CategoryFilter in Meta['Categories'] or CategoryFilter == '*'))):
|
if (not TypeFilter or (TypeFilter and (Meta['Type'] == TypeFilter or TypeFilter == '*'))) and (not CategoryFilter or (CategoryFilter and (CategoryFilter in Meta['Categories'] or CategoryFilter == '*'))):
|
||||||
Desc = ''
|
|
||||||
Parse = BeautifulSoup(ContentHTML, 'html.parser')
|
|
||||||
Paragraphs = Parse.p.get_text().split('\n')
|
|
||||||
Read = '...' + Locale['ReadFullPost'] + ':\n'
|
|
||||||
URL = f"{SiteDomain}/{StripExt(File)}.html"
|
URL = f"{SiteDomain}/{StripExt(File)}.html"
|
||||||
|
DoPost = True
|
||||||
|
for p in Posts:
|
||||||
|
if p['Link'] in [URL]+Meta['URL']:
|
||||||
|
DoPost = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if DoPost and Meta['Feed'] == 'True' and (not HoursLimit or (Meta['CreatedOn'] and time.time() - time.mktime(date_parse(Meta['CreatedOn']).timetuple()) < 60*60*HoursLimit)):
|
||||||
|
Desc = ''
|
||||||
|
Paragraphs = MkSoup(ContentHTML).p.get_text().split('\n')
|
||||||
|
Read = '...' + Locale['ReadFullPost'] + ':\n'
|
||||||
for p in Paragraphs:
|
for p in Paragraphs:
|
||||||
if p and len(Read+Desc+p)+25 < 500:
|
if p and len(Read+Desc+p)+25 < 500:
|
||||||
Desc += p + '\n\n'
|
Desc += p + '\n\n'
|
||||||
@ -74,15 +80,11 @@ def MastodonShare(Flags, Pages, Locale):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
Desc = p[:500-25-5-len(Read)] + '...'
|
Desc = p[:500-25-5-len(Read)] + '...'
|
||||||
DoPost = True
|
|
||||||
for p in Posts:
|
|
||||||
if p['Link'] == URL:
|
|
||||||
DoPost = False
|
|
||||||
break
|
|
||||||
if DoPost and Meta['Feed'] == 'True' and (not HoursLimit or (Meta['CreatedOn'] and time.time() - time.mktime(date_parse(Meta['CreatedOn']).timetuple()) < 60*60*HoursLimit)):
|
|
||||||
if not SaidPosting:
|
if not SaidPosting:
|
||||||
print("[I] Posting to Mastodon")
|
print("[I] Posting to Mastodon")
|
||||||
SaidPosting = True
|
SaidPosting = True
|
||||||
|
|
||||||
time.sleep(5) # Prevent flooding
|
time.sleep(5) # Prevent flooding
|
||||||
Post = MastodonGetLinkFromPost(
|
Post = MastodonGetLinkFromPost(
|
||||||
Post=MastodonDoPost(
|
Post=MastodonDoPost(
|
||||||
@ -92,4 +94,5 @@ def MastodonShare(Flags, Pages, Locale):
|
|||||||
Domain=SiteDomain)
|
Domain=SiteDomain)
|
||||||
if Post:
|
if Post:
|
||||||
Posts += [Post]
|
Posts += [Post]
|
||||||
|
|
||||||
return Posts
|
return Posts
|
||||||
|
@ -53,6 +53,9 @@ def LoadFromDir(Dir, Matchs):
|
|||||||
Contents.update({File: ReadFile(f"{Dir}/{File}")})
|
Contents.update({File: ReadFile(f"{Dir}/{File}")})
|
||||||
return Contents
|
return Contents
|
||||||
|
|
||||||
|
def mkdirps(Dir):
|
||||||
|
return Path(Dir).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
def StripExt(Path):
|
def StripExt(Path):
|
||||||
return ".".join(Path.split('.')[:-1])
|
return ".".join(Path.split('.')[:-1])
|
||||||
|
|
||||||
@ -162,4 +165,6 @@ def PrintProcPercentDots(Proc, DivMult=1):
|
|||||||
Div = 5 * DivMult # 100/5 = 20 chars
|
Div = 5 * DivMult # 100/5 = 20 chars
|
||||||
Num, Count = Proc['Num'], Proc['Count']
|
Num, Count = Proc['Num'], Proc['Count']
|
||||||
if int(((Num/Count)*100)/Div) != int((((Num+1)/Count)*100)/Div):
|
if int(((Num/Count)*100)/Div) != int((((Num+1)/Count)*100)/Div):
|
||||||
os.system('printf "="') # For some reason print() without newline breaks here (doesn't print everytime)
|
os.system('printf "="') # Using sys shell since for some reason print() without newline breaks here (doesn't print everytime)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
1
TODO
1
TODO
@ -5,7 +5,6 @@
|
|||||||
- Support for YAML header in Markdown
|
- Support for YAML header in Markdown
|
||||||
- Support for HTML comment lines (<!-- -->) in any format
|
- Support for HTML comment lines (<!-- -->) in any format
|
||||||
- Support for rST and AsciiDoc (?)
|
- Support for rST and AsciiDoc (?)
|
||||||
- Showing build percentage as dots
|
|
||||||
- Posts in draft state (will not be compiled) / show unlisted status for posts with Index = False
|
- Posts in draft state (will not be compiled) / show unlisted status for posts with Index = False
|
||||||
- Check if external tools (pug-cli, html2gmi) are installed
|
- Check if external tools (pug-cli, html2gmi) are installed
|
||||||
- Static code syntax highlighing
|
- Static code syntax highlighing
|
||||||
|
Reference in New Issue
Block a user