From c0e394646b9efec383d0e5c1878b552adb30c4f6 Mon Sep 17 00:00:00 2001 From: octospacc Date: Thu, 28 Jul 2022 23:13:47 +0200 Subject: [PATCH] Global macros --- README.md | 3 ++- Source/Build.py | 1 + Source/Modules/Site.py | 10 ++++++---- TODO | 9 +++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0500399..3d8aba1 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Feel free to experiment with all of this stuff! ## Dependencies - [Python == 3.10.4](https://python.org) - (Included) [Python Markdown == 3.3.7](https://pypi.org/project/Markdown) + - (Included) Third-Party Extensions for Python Markdown: [markdown_del_ins](https://github.com/honzajavorek/markdown-del-ins), [mdx_subscript](https://github.com/jambonrose/markdown_subscript_extension), [mdx_superscript](https://github.com/jambonrose/markdown_superscript_extension) - (Included) [Beautiful Soup == 4.11.1](https://pypi.org/project/beautifulsoup4) - (Included) [feedgen == 0.9.0](https://pypi.org/project/feedgen) - (Included) [htmlmin == 0.1.12](https://pypi.org/project/htmlmin) @@ -21,7 +22,7 @@ Feel free to experiment with all of this stuff! - [html2gmi](https://github.com/LukeEmmet/html2gmi) ## Features roadmap -- [ ] Local (per-page) and global (per-site) macros +- [x] Local (per-page) and global (per-site) macros - [x] ActivityPub (Mastodon) support (Feed + embedded comments) - [ ] Polished Gemtext generation - [x] Autodetection of pages and posts diff --git a/Source/Build.py b/Source/Build.py index 9d691de..4496b7e 100755 --- a/Source/Build.py +++ b/Source/Build.py @@ -120,6 +120,7 @@ def Main(Args, FeedEntries): ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {}, ContextPartsText=LoadFromDir('ContextParts', '*.html'), ConfMenu=ConfMenu, + GlobalMacros=ReadConf(SiteConf, 'Macros'), SiteName=SiteName, BlogName=BlogName, SiteTagline=SiteTagline, diff --git a/Source/Modules/Site.py b/Source/Modules/Site.py index cde57d8..f9b8c34 100644 --- a/Source/Modules/Site.py +++ b/Source/Modules/Site.py @@ -111,7 +111,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page List += Levels + Title + '\n' return markdown(MarkdownHTMLEscape(List, MarkdownExts), extensions=MarkdownExts) -def Preprocessor(Path, SiteRoot): +def Preprocessor(Path, SiteRoot, GlobalMacros): File = ReadFile(Path) Content, Titles, DashyTitles, HTMLTitlesFound, Macros, Meta = '', [], [], False, '', { 'Template': 'Standard.html', @@ -185,7 +185,9 @@ def Preprocessor(Path, SiteRoot): Content += MakeLinkableTitle(l, Title, DashTitle, 'pug') + '\n' else: Content += l + '\n' - Meta['Macros'] = ReadConf(LoadConfStr('[Macros]\n' + Macros), 'Macros') + if GlobalMacros: + Meta['Macros'].update(GlobalMacros) + Meta['Macros'].update(ReadConf(LoadConfStr('[Macros]\n' + Macros), 'Macros')) return Content, Titles, Meta def Postprocessor(FileType, Text, Meta): @@ -323,7 +325,7 @@ def DoMinifyHTML(HTML): convert_charrefs=True, keep_pre=True) -def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu, SiteName, BlogName, SiteTagline, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, NoScripts, Sorting, MarkdownExts, AutoCategories): +def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu, GlobalMacros, SiteName, BlogName, SiteTagline, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, NoScripts, Sorting, MarkdownExts, AutoCategories): PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {} for Ext in FileExtensions['Pages']: for File in Path('Pages').rglob(f"*.{Ext}"): @@ -347,7 +349,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu, elif Type == 'Post': Files = PostsPaths for File in Files: - Content, Titles, Meta = Preprocessor(f"{Type}s/{File}", SiteRoot) + Content, Titles, Meta = Preprocessor(f"{Type}s/{File}", SiteRoot, GlobalMacros) if Type != 'Page': File = f"{Type}s/{File}" if not Meta['Type']: diff --git a/TODO b/TODO index 9f5f268..f03d655 100644 --- a/TODO +++ b/TODO @@ -1 +1,10 @@ - Fix arguments - some are only callable from CLI and not Site.ini +- Fix Python-Markdown is installed problem (to load our modules) +- Hot-recompile +- Differential recompile +- Feed generation without native libraries +- JSON feeds +- Full XML sitemap +- SCSS support +- Images in post listings +- "Uncategorized" category for posts without specified ones