From c35aa94345ce16c9109fd5a9f35c5aa9498fb664 Mon Sep 17 00:00:00 2001 From: octospacc Date: Thu, 23 Feb 2023 00:11:49 +0100 Subject: [PATCH] Some code restructuring, Update copyright year, Fix bug in PagesSearch.html --- .gitignore | 2 + App/Assets/PagesSearch.html | 4 +- App/Source/Build.py | 16 +- App/Source/Modules/ActivityPub.py | 16 +- App/Source/Modules/Config.py | 16 +- App/Source/Modules/Elements.py | 16 +- App/Source/Modules/Feed.py | 16 +- App/Source/Modules/Gemini.py | 16 +- App/Source/Modules/Globals.py | 16 +- App/Source/Modules/HTML.py | 16 +- App/Source/Modules/Logging.py | 16 +- App/Source/Modules/Markdown.py | 16 +- App/Source/Modules/Meta.py | 289 +++++++++++++++++++++++++++++ App/Source/Modules/Pug.py | 16 +- App/Source/Modules/Site.py | 293 +----------------------------- App/Source/Modules/Sitemap.py | 16 +- App/Source/Modules/Utils.py | 17 +- 17 files changed, 406 insertions(+), 391 deletions(-) create mode 100644 App/Source/Modules/Meta.py diff --git a/.gitignore b/.gitignore index 65ed20c..c7011d8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ tmp.* public/* Sites/*/public/* +Sites/*/public.Content/* +Sites/*/public.gmi/* Themes/Build/* diff --git a/App/Assets/PagesSearch.html b/App/Assets/PagesSearch.html index ce1cb07..6a2b5fc 100644 --- a/App/Assets/PagesSearch.html +++ b/App/Assets/PagesSearch.html @@ -90,7 +90,7 @@ return false; }; - function CreateSearchAnchors() { + function CreateSearchAnchors(Query) { /* // Create anchors redirecting to the pages that are displayed document.querySelectorAll(SelectBase).forEach(function(Page) { @@ -184,7 +184,7 @@ ${WordLooseStyle} ${SelectBase} *[data-staticoso-htmlsearch-block*="${Query}"] { display: revert; } `; - CreateSearchAnchors(); + CreateSearchAnchors(Query); }; ['onchange', 'oninput', 'onpaste'].forEach(function(Ev) { diff --git a/App/Source/Build.py b/App/Source/Build.py index 77dfd80..b8ce501 100644 --- a/App/Source/Build.py +++ b/App/Source/Build.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ import argparse import os diff --git a/App/Source/Modules/ActivityPub.py b/App/Source/Modules/ActivityPub.py index 6c1252b..d2d94de 100644 --- a/App/Source/Modules/ActivityPub.py +++ b/App/Source/Modules/ActivityPub.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ import time from Libs.dateutil.parser import parse as date_parse diff --git a/App/Source/Modules/Config.py b/App/Source/Modules/Config.py index 19e8601..52549fc 100644 --- a/App/Source/Modules/Config.py +++ b/App/Source/Modules/Config.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ import configparser from ast import literal_eval diff --git a/App/Source/Modules/Elements.py b/App/Source/Modules/Elements.py index 6391e80..cf3532f 100644 --- a/App/Source/Modules/Elements.py +++ b/App/Source/Modules/Elements.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ from base64 import b64encode from Modules.Globals import * diff --git a/App/Source/Modules/Feed.py b/App/Source/Modules/Feed.py index 6652ffb..5001dbb 100644 --- a/App/Source/Modules/Feed.py +++ b/App/Source/Modules/Feed.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ # TODO: Either switch feed generation lib, or rewrite the 'lxml' module, so that no modules have to be compiled and the program is 100% portable diff --git a/App/Source/Modules/Gemini.py b/App/Source/Modules/Gemini.py index 05dfab5..30ab5c5 100644 --- a/App/Source/Modules/Gemini.py +++ b/App/Source/Modules/Gemini.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ # TODO: Write the Python HTML2Gemtext converter diff --git a/App/Source/Modules/Globals.py b/App/Source/Modules/Globals.py index 50b18ae..3b5dc1a 100644 --- a/App/Source/Modules/Globals.py +++ b/App/Source/Modules/Globals.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ ReservedPaths = ('Site.ini', 'Assets', 'Pages', 'Posts', 'Templates', 'StaticParts', 'DynamicParts') FileExtensions = { diff --git a/App/Source/Modules/HTML.py b/App/Source/Modules/HTML.py index 270e700..f85a4f0 100644 --- a/App/Source/Modules/HTML.py +++ b/App/Source/Modules/HTML.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ import html import warnings diff --git a/App/Source/Modules/Logging.py b/App/Source/Modules/Logging.py index bdb1e77..3a2548f 100644 --- a/App/Source/Modules/Logging.py +++ b/App/Source/Modules/Logging.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ import logging import sys diff --git a/App/Source/Modules/Markdown.py b/App/Source/Modules/Markdown.py index 7e5a7cd..c29b014 100644 --- a/App/Source/Modules/Markdown.py +++ b/App/Source/Modules/Markdown.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ from Libs.markdown import markdown diff --git a/App/Source/Modules/Meta.py b/App/Source/Modules/Meta.py new file mode 100644 index 0000000..18680a8 --- /dev/null +++ b/App/Source/Modules/Meta.py @@ -0,0 +1,289 @@ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ + +from Modules.Config import * +from Modules.Elements import * +from Modules.HTML import * +from Modules.Markdown import * +from Modules.Utils import * + +# Menu styles: +# - Simple: Default, Flat, Line +# - Others: Excerpt, Image, Preview (Excerpt + Image), Full +def GetHTMLPagesList(Pages:list, BlogName:str, SiteRoot:str, PathPrefix:str, CallbackFile=None, Unite=[], Type=None, Limit=None, PathFilter='', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default', ShowPaths=True): + Flatten, SingleLine, DoneCount, PrevDepth = False, False, 0, 0 + if MenuStyle == 'Flat': + Flatten = True + elif MenuStyle == 'Line': + ShowPaths, SingleLine = False, True + List, ToPop, LastParent = '', [], [] + IndexPages = Pages.copy() + for e in IndexPages: + if e[3]['Index'].lower() in PageIndexStrNeg: + IndexPages.remove(e) + for i,e in enumerate(IndexPages): + if Type and e[3]['Type'] != Type: + ToPop += [i] + ToPop = RevSort(ToPop) + for i in ToPop: + IndexPages.pop(i) + if Type == 'Page': + IndexPages = OrderPages(IndexPages) + for i,e in enumerate(Unite): + if e: + 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 + if TmpPathFilter.startswith('Pages/'): + TmpPathFilter = TmpPathFilter[len('Pages/'):] + if File.startswith('Posts/'): + continue + + if (not Type or (Meta['Type'] == Type and CanIndex(Meta['Index'], For))) and (not Category or Category in Meta['Categories']) and File.startswith(TmpPathFilter) and File != CallbackFile and (not Limit or Limit > DoneCount): + Depth = (File.count('/') + 1) if Meta['Order'] != 'Unite' else 1 + # Folder names are handled here + if Depth > 1 and Meta['Order'] != 'Unite': + CurParent = File.split('/')[:-1] + for i,s in enumerate(CurParent): + if LastParent != CurParent and ShowPaths: + LastParent = CurParent + Levels = '.' * ((Depth-2+i) if not Flatten else 0) + ':' + # If search node endswith index, it's a page; else, it's a folder + if StripExt(File).endswith('index'): + Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', BlogName, PathPrefix) + DoneCount += 1 + else: + Title = CurParent[Depth-2+i] + if SingleLine: + List += f' {Title} ' + else: + List += f'{Levels}{Title}\n' + + # Pages with any other path + if not (Depth > 1 and StripExt(File).split('/')[-1] == 'index'): + Levels = '.' * ((Depth-1) if not Flatten else 0) + ':' + DoneCount += 1 + if Meta['Order'] == 'Unite': + Title = markdown(MarkdownHTMLEscape(File, MarkdownExts), extensions=MarkdownExts).removeprefix('

').removesuffix('

') + else: + Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', BlogName, PathPrefix) + if SingleLine: + List += ' ' + Title + ' ' + else: + List += Levels + Title + '\n' + + if MenuStyle in ('Default', 'Flat'): + return GenHTMLTreeList(List, Class="staticoso-PagesList") + elif MenuStyle in ('Line', 'Excerpt', 'Image', 'Preview', 'Full'): + return List + +def CheckHTMLCommentLine(Line:str): + if Line.startswith(''): + return Line + return None + +def TemplatePreprocessor(Text:str): + Meta, MetaDefault = '', { + 'MenuStyle': 'Default'} + for l in Text.splitlines(): + ll = l.lstrip().rstrip() + lll = CheckHTMLCommentLine(ll) + if lll: + if lll.startswith('%'): + Meta += lll[1:-3].lstrip().rstrip() + '\n' + Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta')) + for i in MetaDefault: + if not i in Meta: + Meta.update({i:MetaDefault[i]}) + return Meta + +def FindPreprocLine(Line:str, Meta, Macros): + Changed = False + Line = Line.lstrip().rstrip() + lll = CheckHTMLCommentLine(Line) + if Line.startswith('//') or lll: # Find preprocessor lines + lll = Line[2:].lstrip() + if lll.startswith('%'): + Meta += lll[1:].lstrip() + '\n' + Changed = True + elif lll.startswith('$'): + Macros += lll[1:].lstrip() + '\n' + Changed = True + #if ll.startswith(''): # Find comment and code blocks + # IgnoreBlocksStart += [l] + return (Meta, Macros, Changed) + +def PagePreprocessor(Path:str, TempPath:str, Type:str, SiteTemplate, SiteRoot, GlobalMacros, CategoryUncategorized, LightRun:bool=False, Content=None): + File = ReadFile(Path) if not Content else Content + Path = Path.lower() + Content, Titles, DashyTitles, HTMLTitlesFound, Macros, Meta, MetaDefault = '', [], [], False, '', '', { + 'Template': SiteTemplate, + 'Head': '', + 'Style': '', + 'Type': Type, + 'Index': 'Unspecified', + 'Feed': 'True', + 'Title': '', + 'HTMLTitle': '', + 'Description': '', + 'Image': '', + 'Macros': {}, + 'Categories': [], + 'URLs': [], + 'CreatedOn': '', + 'UpdatedOn': '', + 'EditedOn': '', + 'Order': None, + 'Language': None, + 'Downsync': None} + # Find all positions of '', add them in a list=[[pos0,pos1,line0,line1],...] + for l in File.splitlines(): + ll = l.lstrip().rstrip() + Meta, Macros, Changed = FindPreprocLine(ll, Meta, Macros) + if not Changed: # Find headings + #if line in ignore block: + # continue + Headings = ('h1', 'h2', 'h3', 'h4', 'h5', 'h6') + #if Path.endswith(FileExtensions['HTML']): + # if ll[1:].startswith(Headings): + # if ll[3:].startswith((" class='NoTitle", ' class="NoTitle')): + # Content += l + '\n' + # elif ll.replace(' ', ' ').startswith('// %'): + # pass + # else: + # Title = '#'*int(ll[2]) + ' ' + ll[4:] + # DashTitle = DashifyTitle(Title.lstrip('#'), DashyTitles) + # DashyTitles += [DashTitle] + # Titles += [Title] + # Content += MakeLinkableTitle(l, Title, DashTitle, 'pug') + '\n' + # else: + # Content += l + '\n' + if Path.endswith(FileExtensions['HTML']) and not HTMLTitlesFound: + Soup = MkSoup(File) + Tags = Soup.find_all() + for t in Tags: + if t.name in Headings: + Title = '#'*int(t.name[1]) + ' ' + str(t.text) + DashTitle = DashifyTitle(Title.lstrip('#'), DashyTitles) + DashyTitles += [DashTitle] + Titles += [Title] + t.replace_with(MakeLinkableTitle(None, Title, DashTitle, 'md')) + HTMLTitlesFound = True + Content = '' + TmpContent = str(Soup.prettify(formatter=None)) + for cl in TmpContent.splitlines(): + _, _, IsMetaLine = FindPreprocLine(cl, Meta, Macros) + if not IsMetaLine: + #print(cl) + Content += cl + '\n' + break + elif Path.endswith(FileExtensions['Markdown']): + lsuffix = '' + if ll.startswith(('-', '+', '*')): + lsuffix += ll[0] + ll = ll[1:].lstrip() + if ll.startswith('#') or (ll.startswith('<') and ll[1:].startswith(Headings)): + if ll.startswith('#'): + Title = ll + elif ll.startswith('<'): + if ll[3:].startswith((" class='NoTitle", ' class="NoTitle')): + Content += l + '\n' + continue + else: + Title = '#'*int(ll[2]) + ' ' + ll[4:] + DashTitle = DashifyTitle(MkSoup(Title.lstrip('#')).get_text(), DashyTitles) + DashyTitles += [DashTitle] + Titles += [Title] + Title = MakeLinkableTitle(None, Title, DashTitle, 'md') + # I can't remember why I put this but it was needed + Title = Title.replace('> Max: + Max = int(Curr) + else: + NoOrder += [e] + New = [None] * (Max+1) + for i,e in enumerate(Old): + Curr = e[3]['Order'] + if Curr: + New[int(Curr)] = e + while None in New: + New.remove(None) + return New + NoOrder + +def CanIndex(Index:str, For:str): + if Index.lower() in PageIndexStrNeg: + return False + elif Index.lower() in PageIndexStrPos: + return True + else: + return True if Index == For else False diff --git a/App/Source/Modules/Pug.py b/App/Source/Modules/Pug.py index 56b48b2..62fbf3a 100644 --- a/App/Source/Modules/Pug.py +++ b/App/Source/Modules/Pug.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ # TODO: Write a native Pug parser; There is one already available for Python but seems broken / out-of-date diff --git a/App/Source/Modules/Site.py b/App/Source/Modules/Site.py index ab0a70c..8dbe30b 100644 --- a/App/Source/Modules/Site.py +++ b/App/Source/Modules/Site.py @@ -1,300 +1,25 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ import shutil from datetime import datetime 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 * +from Modules.Meta import * from Modules.Pug import * from Modules.Utils import * -# Menu styles: -# - Simple: Default, Flat, Line -# - Others: Excerpt, Image, Preview (Excerpt + Image), Full -def GetHTMLPagesList(Pages:list, BlogName:str, SiteRoot:str, PathPrefix:str, CallbackFile=None, Unite=[], Type=None, Limit=None, PathFilter='', Category=None, For='Menu', MarkdownExts=(), MenuStyle='Default', ShowPaths=True): - Flatten, SingleLine, DoneCount, PrevDepth = False, False, 0, 0 - if MenuStyle == 'Flat': - Flatten = True - elif MenuStyle == 'Line': - ShowPaths, SingleLine = False, True - List, ToPop, LastParent = '', [], [] - IndexPages = Pages.copy() - for e in IndexPages: - if e[3]['Index'].lower() in PageIndexStrNeg: - IndexPages.remove(e) - for i,e in enumerate(IndexPages): - if Type and e[3]['Type'] != Type: - ToPop += [i] - ToPop = RevSort(ToPop) - for i in ToPop: - IndexPages.pop(i) - if Type == 'Page': - IndexPages = OrderPages(IndexPages) - for i,e in enumerate(Unite): - if e: - 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 - if TmpPathFilter.startswith('Pages/'): - TmpPathFilter = TmpPathFilter[len('Pages/'):] - if File.startswith('Posts/'): - continue - - if (not Type or (Meta['Type'] == Type and CanIndex(Meta['Index'], For))) and (not Category or Category in Meta['Categories']) and File.startswith(TmpPathFilter) and File != CallbackFile and (not Limit or Limit > DoneCount): - Depth = (File.count('/') + 1) if Meta['Order'] != 'Unite' else 1 - # Folder names are handled here - if Depth > 1 and Meta['Order'] != 'Unite': - CurParent = File.split('/')[:-1] - for i,s in enumerate(CurParent): - if LastParent != CurParent and ShowPaths: - LastParent = CurParent - Levels = '.' * ((Depth-2+i) if not Flatten else 0) + ':' - # If search node endswith index, it's a page; else, it's a folder - if StripExt(File).endswith('index'): - Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', BlogName, PathPrefix) - DoneCount += 1 - else: - Title = CurParent[Depth-2+i] - if SingleLine: - List += f' {Title} ' - else: - List += f'{Levels}{Title}\n' - - # Pages with any other path - if not (Depth > 1 and StripExt(File).split('/')[-1] == 'index'): - Levels = '.' * ((Depth-1) if not Flatten else 0) + ':' - DoneCount += 1 - if Meta['Order'] == 'Unite': - Title = markdown(MarkdownHTMLEscape(File, MarkdownExts), extensions=MarkdownExts).removeprefix('

').removesuffix('

') - else: - Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', BlogName, PathPrefix) - if SingleLine: - List += ' ' + Title + ' ' - else: - List += Levels + Title + '\n' - - if MenuStyle in ('Default', 'Flat'): - return GenHTMLTreeList(List, Class="staticoso-PagesList") - elif MenuStyle in ('Line', 'Excerpt', 'Image', 'Preview', 'Full'): - return List - -def CheckHTMLCommentLine(Line:str): - if Line.startswith(''): - return Line - return None - -def TemplatePreprocessor(Text:str): - Meta, MetaDefault = '', { - 'MenuStyle': 'Default'} - for l in Text.splitlines(): - ll = l.lstrip().rstrip() - lll = CheckHTMLCommentLine(ll) - if lll: - if lll.startswith('%'): - Meta += lll[1:-3].lstrip().rstrip() + '\n' - Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta')) - for i in MetaDefault: - if not i in Meta: - Meta.update({i:MetaDefault[i]}) - return Meta - -def FindPreprocLine(Line:str, Meta, Macros): - Changed = False - Line = Line.lstrip().rstrip() - lll = CheckHTMLCommentLine(Line) - if Line.startswith('//') or lll: # Find preprocessor lines - lll = Line[2:].lstrip() - if lll.startswith('%'): - Meta += lll[1:].lstrip() + '\n' - Changed = True - elif lll.startswith('$'): - Macros += lll[1:].lstrip() + '\n' - Changed = True - #if ll.startswith(''): # Find comment and code blocks - # IgnoreBlocksStart += [l] - return (Meta, Macros, Changed) - -def PagePreprocessor(Path:str, TempPath:str, Type:str, SiteTemplate, SiteRoot, GlobalMacros, CategoryUncategorized, LightRun:bool=False, Content=None): - File = ReadFile(Path) if not Content else Content - Path = Path.lower() - Content, Titles, DashyTitles, HTMLTitlesFound, Macros, Meta, MetaDefault = '', [], [], False, '', '', { - 'Template': SiteTemplate, - 'Head': '', - 'Style': '', - 'Type': Type, - 'Index': 'Unspecified', - 'Feed': 'True', - 'Title': '', - 'HTMLTitle': '', - 'Description': '', - 'Image': '', - 'Macros': {}, - 'Categories': [], - 'URLs': [], - 'CreatedOn': '', - 'UpdatedOn': '', - 'EditedOn': '', - 'Order': None, - 'Language': None, - 'Downsync': None} - # Find all positions of '', add them in a list=[[pos0,pos1,line0,line1],...] - for l in File.splitlines(): - ll = l.lstrip().rstrip() - Meta, Macros, Changed = FindPreprocLine(ll, Meta, Macros) - if not Changed: # Find headings - #if line in ignore block: - # continue - Headings = ('h1', 'h2', 'h3', 'h4', 'h5', 'h6') - #if Path.endswith(FileExtensions['HTML']): - # if ll[1:].startswith(Headings): - # if ll[3:].startswith((" class='NoTitle", ' class="NoTitle')): - # Content += l + '\n' - # elif ll.replace(' ', ' ').startswith('// %'): - # pass - # else: - # Title = '#'*int(ll[2]) + ' ' + ll[4:] - # DashTitle = DashifyTitle(Title.lstrip('#'), DashyTitles) - # DashyTitles += [DashTitle] - # Titles += [Title] - # Content += MakeLinkableTitle(l, Title, DashTitle, 'pug') + '\n' - # else: - # Content += l + '\n' - if Path.endswith(FileExtensions['HTML']) and not HTMLTitlesFound: - Soup = BeautifulSoup(File, 'html.parser') - Tags = Soup.find_all() - for t in Tags: - if t.name in Headings: - Title = '#'*int(t.name[1]) + ' ' + str(t.text) - DashTitle = DashifyTitle(Title.lstrip('#'), DashyTitles) - DashyTitles += [DashTitle] - Titles += [Title] - t.replace_with(MakeLinkableTitle(None, Title, DashTitle, 'md')) - HTMLTitlesFound = True - Content = '' - TmpContent = str(Soup.prettify(formatter=None)) - for cl in TmpContent.splitlines(): - _, _, IsMetaLine = FindPreprocLine(cl, Meta, Macros) - if not IsMetaLine: - #print(cl) - Content += cl + '\n' - break - elif Path.endswith(FileExtensions['Markdown']): - lsuffix = '' - if ll.startswith(('-', '+', '*')): - lsuffix += ll[0] - ll = ll[1:].lstrip() - if ll.startswith('#') or (ll.startswith('<') and ll[1:].startswith(Headings)): - if ll.startswith('#'): - Title = ll - elif ll.startswith('<'): - if ll[3:].startswith((" class='NoTitle", ' class="NoTitle')): - Content += l + '\n' - continue - else: - Title = '#'*int(ll[2]) + ' ' + ll[4:] - DashTitle = DashifyTitle(MkSoup(Title.lstrip('#')).get_text(), DashyTitles) - DashyTitles += [DashTitle] - Titles += [Title] - Title = MakeLinkableTitle(None, Title, DashTitle, 'md') - # I can't remember why I put this but it was needed - Title = Title.replace('> Max: - Max = int(Curr) - else: - NoOrder += [e] - New = [None] * (Max+1) - for i,e in enumerate(Old): - Curr = e[3]['Order'] - if Curr: - New[int(Curr)] = e - while None in New: - New.remove(None) - return New + NoOrder - -def CanIndex(Index:str, For:str): - if Index.lower() in PageIndexStrNeg: - return False - elif Index.lower() in PageIndexStrPos: - return True - else: - return True if Index == For else False - def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteDomain, SiteRoot, SiteName, BlogName, FolderRoots, Categories, SiteLang, Locale, LightRun): HTMLTitles = FormatTitles(Titles) BodyDescription, BodyImage = '', '' diff --git a/App/Source/Modules/Sitemap.py b/App/Source/Modules/Sitemap.py index 03f28ff..da43152 100644 --- a/App/Source/Modules/Sitemap.py +++ b/App/Source/Modules/Sitemap.py @@ -1,11 +1,11 @@ -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ from urllib.parse import quote as URLEncode from Modules.HTML import * diff --git a/App/Source/Modules/Utils.py b/App/Source/Modules/Utils.py index 542d204..4a13810 100644 --- a/App/Source/Modules/Utils.py +++ b/App/Source/Modules/Utils.py @@ -1,12 +1,11 @@ - -""" ================================= | -| This file is part of | -| staticoso | -| Just a simple Static Site Generator | -| | -| Licensed under the AGPLv3 license | -| Copyright (C) 2022, OctoSpacc | -| ================================= """ +""" ================================== | +| This file is part of | +| staticoso | +| Just a simple Static Site Generator | +| | +| Licensed under the AGPLv3 license | +| Copyright (C) 2022-2023, OctoSpacc | +| ================================== """ import json import os