diff --git a/Locale/en.json b/Locale/en.json index af775d7..894e660 100644 --- a/Locale/en.json +++ b/Locale/en.json @@ -1,6 +1,7 @@ { "CreatedOn": "Created on", "EditedOn": "Edited on", + "Unlisted": "Unlisted", "Categories": "Categories", "ReadFullPost": "Read the full post", "Comments": "Comments", diff --git a/Locale/it.json b/Locale/it.json index dc859ec..ee02612 100644 --- a/Locale/it.json +++ b/Locale/it.json @@ -1,6 +1,7 @@ { "CreatedOn": "Creato in data", "EditedOn": "Modificato in data", + "Unlisted": "Non in elenco", "Categories": "Categorie", "ReadFullPost": "Leggi il post intero", "Comments": "Commenti", diff --git a/Source/Build.py b/Source/Build.py index ac9c8f7..3aa9d39 100755 --- a/Source/Build.py +++ b/Source/Build.py @@ -17,6 +17,7 @@ from datetime import datetime from pathlib import Path from Modules.Config import * from Modules.Gemini import * +from Modules.Globals import * from Modules.Logging import * from Modules.Markdown import * from Modules.Site import * diff --git a/Source/Libs/mastodon/streaming.py b/Source/Libs/mastodon/streaming.py index 83472a8..8364274 100644 --- a/Source/Libs/mastodon/streaming.py +++ b/Source/Libs/mastodon/streaming.py @@ -4,7 +4,7 @@ https://github.com/tootsuite/mastodon/blob/master/docs/Using-the-API/Streaming-A """ import json -import six +from .. import six from . import Mastodon from .Mastodon import MastodonMalformedEventError, MastodonNetworkError, MastodonReadTimeout from requests.exceptions import ChunkedEncodingError, ReadTimeout diff --git a/Source/Modules/Elements.py b/Source/Modules/Elements.py index 9d65181..7c1607b 100644 --- a/Source/Modules/Elements.py +++ b/Source/Modules/Elements.py @@ -8,6 +8,7 @@ | ================================= """ from base64 import b64encode +from Modules.Globals import * from Modules.HTML import * from Modules.Utils import * @@ -32,6 +33,8 @@ RedirectPageTemplate = """\
+ +{Header}
' def MakeCategoryLine(File, Meta): diff --git a/Source/Modules/Globals.py b/Source/Modules/Globals.py new file mode 100644 index 0000000..50b18ae --- /dev/null +++ b/Source/Modules/Globals.py @@ -0,0 +1,23 @@ +""" ================================= | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022, OctoSpacc | +| ================================= """ + +ReservedPaths = ('Site.ini', 'Assets', 'Pages', 'Posts', 'Templates', 'StaticParts', 'DynamicParts') +FileExtensions = { + 'Pages': ('htm', 'html', 'markdown', 'md', 'pug', 'txt'), + 'HTML': ('.htm', '.html'), + 'Markdown': ('.markdown', '.md'), + 'Tmp': ('htm', 'markdown', 'md', 'pug', 'txt')} + +PosStrBools = ('true', 'yes', 'on', '1', 'enabled') +NegStrBools = ('false', 'no', 'off', '0', 'disabled') + +PageIndexStrPos = tuple(list(PosStrBools) + ['all', 'listed', 'indexed', 'unlinked']) +PageIndexStrNeg = tuple(list(NegStrBools) + ['none', 'unlisted', 'unindexed', 'hidden']) + +InternalMacrosWraps = [['[', ']'], ['<', '>']] diff --git a/Source/Modules/HTML.py b/Source/Modules/HTML.py index 34812d6..270e700 100644 --- a/Source/Modules/HTML.py +++ b/Source/Modules/HTML.py @@ -58,21 +58,24 @@ def WriteImgAltAndTitle(HTML, AltToTitle, TitleToAlt): # Adds alt or title attr. return str(Soup) def AddToTagStartEnd(HTML, MatchStart, MatchEnd, AddStart, AddEnd): # This doesn't handle nested tags - StartPos = None + StartPos, DidStart, DidEnd = None, 0, 0 for i,e in enumerate(HTML): FilterStart = HTML[i:i+len(MatchStart)] FilterEnd = HTML[i:i+len(MatchEnd)] - if not AddStart and not AddEnd: - break - if FilterStart == MatchStart: + if DidStart == 0 and FilterStart == MatchStart: StartPos = i if AddStart: HTML = HTML[:i] + AddStart + HTML[i:] - AddStart = None - if FilterEnd == MatchEnd and StartPos and i > StartPos: + DidStart = 2 + if DidEnd == 0 and FilterEnd == MatchEnd and StartPos and i > StartPos: + StartPos = None if AddEnd: HTML = HTML[:i+len(MatchEnd)] + AddEnd + HTML[i+len(MatchEnd):] - AddEnd = None + DidEnd = 2 + if DidStart > 0: + DidStart -= 1 + if DidEnd > 0: + DidEnd -= 1 return HTML def SquareFnrefs(HTML): # Different combinations of formatting for Soup .prettify, .encode, .decode break different page elements, don't use this for now diff --git a/Source/Modules/Site.py b/Source/Modules/Site.py index aef0bf0..2ccbb20 100644 --- a/Source/Modules/Site.py +++ b/Source/Modules/Site.py @@ -13,6 +13,7 @@ from multiprocessing import Pool, cpu_count from Libs.bs4 import BeautifulSoup from Modules.Config import * from Modules.Elements import * +from Modules.Globals import * from Modules.HTML import * from Modules.Logging import * from Modules.Markdown import * @@ -31,7 +32,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, U List, ToPop, LastParent = '', [], [] IndexPages = Pages.copy() for e in IndexPages: - if e[3]['Index'] == 'False' or e[3]['Index'] == 'None': + if e[3]['Index'].lower() in PageIndexStrNeg: IndexPages.remove(e) for i,e in enumerate(IndexPages): if Type and e[3]['Type'] != Type: @@ -43,7 +44,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, CallbackFile=None, U IndexPages = OrderPages(IndexPages) for i,e in enumerate(Unite): if e: - IndexPages.insert(i,[e,None,None,{'Type':Type,'Index':'True','Order':'Unite'}]) + IndexPages.insert(i, [e, None, None, {'Type':Type, 'Index':'True', 'Order':'Unite'}]) for File, Content, Titles, Meta in IndexPages: # Allow for the virtual "Pages/" prefix to be used in path filtering TmpPathFilter = PathFilter @@ -128,11 +129,12 @@ def FindPreprocLine(Line, Meta, Macros): # IgnoreBlocksStart += [l] return (Meta, Macros, Changed) -def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros, CategoryUncategorized, LightRun=False): +def PagePreprocessor(Path:str, TempPath:str, Type, SiteTemplate, SiteRoot, GlobalMacros, CategoryUncategorized, LightRun=False): File = ReadFile(Path) Path = Path.lower() Content, Titles, DashyTitles, HTMLTitlesFound, Macros, Meta, MetaDefault = '', [], [], False, '', '', { 'Template': SiteTemplate, + 'Head': '', 'Style': '', 'Type': Type, 'Index': 'Unspecified', @@ -250,24 +252,24 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros, Meta.update({i:MetaDefault[i]}) if Meta['UpdatedOn']: Meta['EditedOn'] = Meta['UpdatedOn'] - if Meta['Index'] in ('Default', 'Unspecified', 'Categories'): + if Meta['Index'].lower() in ('default', 'unspecified', 'categories'): if not Meta['Categories']: Meta['Categories'] = [CategoryUncategorized] - if Meta['Type'] == 'Page': + if Meta['Type'].lower() == 'page': Meta['Index'] = 'Categories' - elif Meta['Type'] == 'Post': + elif Meta['Type'].lower() == 'post': Meta['Index'] = 'True' if GlobalMacros: Meta['Macros'].update(GlobalMacros) Meta['Macros'].update(ReadConf(LoadConfStr('[Macros]\n' + Macros), 'Macros')) return [TempPath, Content, Titles, Meta] -def PagePostprocessor(FileType, Text, Meta): +def PagePostprocessor(FileType, Text:str, Meta:dict): for e in Meta['Macros']: Text = ReplWithEsc(Text, f"[: {e} :]", f"[:{e}:]") return Text -def OrderPages(Old): +def OrderPages(Old:list): New, NoOrder, Max = [], [], 0 for i,e in enumerate(Old): Curr = e[3]['Order'] @@ -285,10 +287,10 @@ def OrderPages(Old): New.remove(None) return New + NoOrder -def CanIndex(Index, For): - if Index in ('False', 'None'): +def CanIndex(Index:str, For:str): + if Index.lower() in PageIndexStrNeg: return False - elif Index in ('True', 'All', 'Unlinked'): + elif Index.lower() in PageIndexStrPos: return True else: return True if Index == For else False @@ -297,20 +299,26 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP HTMLTitles = FormatTitles(Titles) BodyDescription, BodyImage = '', '' if not File.lower().endswith('.txt'): - Soup = BeautifulSoup(Content, 'html.parser') - - if not BodyDescription and Soup.p: - BodyDescription = Soup.p.get_text()[:150].replace('\n', ' ').replace('"', "'") + '...' + Soup = MkSoup(Content) + if not BodyDescription:# and Soup.p: + #BodyDescription = Soup.p.get_text()[:150].replace('\n', ' ').replace('"', "'") + '...' + for t in Soup.find_all('p'): + if t.get_text(): + BodyDescription = t.get_text()[:150].replace('\n', ' ').replace('"', "'") + '...' + break if not BodyImage and Soup.img and Soup.img['src']: BodyImage = Soup.img['src'] #Content = SquareFnrefs(Content) - if '', '[', ']') + if '', '[', ']') if any(_ in Content for _ in ('', ' noprocess --->', '', '')): Content = DictReplWithEsc( Content, { + '': '', + '