Global macros

This commit is contained in:
octospacc 2022-07-28 23:13:47 +02:00
parent 0919e108a1
commit c0e394646b
4 changed files with 18 additions and 5 deletions

View File

@ -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

View File

@ -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,

View File

@ -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']:

9
TODO
View File

@ -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