mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-03-12 17:20:22 +01:00
Add local macros
This commit is contained in:
parent
fe4d34e96e
commit
d96cb51fbd
@ -21,6 +21,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] ActivityPub (Mastodon) support (Feed + embedded comments)
|
||||
- [ ] Polished Gemtext generation
|
||||
- [x] Autodetection of pages and posts
|
||||
|
@ -71,7 +71,7 @@ def GetConfMenu(Entries, MarkdownExts):
|
||||
|
||||
def Main(Args, FeedEntries):
|
||||
HavePages, HavePosts = False, False
|
||||
SiteConf = LoadConf('Site.ini')
|
||||
SiteConf = LoadConfFile('Site.ini')
|
||||
|
||||
SiteName = Args.SiteName if Args.SiteName else ReadConf(SiteConf, 'Site', 'Name') if ReadConf(SiteConf, 'Site', 'Name') else ''
|
||||
BlogName = Args.BlogName if Args.BlogName else ReadConf(SiteConf, 'Site', 'BlogName') if ReadConf(SiteConf, 'Site', 'BlogName') else ''
|
||||
|
@ -7,14 +7,22 @@
|
||||
| Copyright (C) 2022, OctoSpacc |
|
||||
| ================================= """
|
||||
|
||||
import io
|
||||
import configparser
|
||||
from ast import literal_eval
|
||||
|
||||
def LoadConf(File):
|
||||
def LoadConfFile(File):
|
||||
Conf = configparser.ConfigParser()
|
||||
Conf.optionxform = lambda option: option
|
||||
Conf.read(File)
|
||||
return Conf
|
||||
|
||||
def LoadConfStr(Str):
|
||||
Conf = configparser.ConfigParser()
|
||||
Conf.optionxform = lambda option: option
|
||||
Conf.read_string(Str)
|
||||
return Conf
|
||||
|
||||
def ReadConf(Conf, Sect, Opt=None):
|
||||
if Opt:
|
||||
if Conf.has_option(Sect, Opt):
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
from Libs import htmlmin
|
||||
from Libs.bs4 import BeautifulSoup
|
||||
from Modules.Config import *
|
||||
from Modules.HTML import *
|
||||
from Modules.Markdown import *
|
||||
from Modules.Pug import *
|
||||
@ -112,7 +113,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page
|
||||
|
||||
def Preprocessor(Path, SiteRoot):
|
||||
File = ReadFile(Path)
|
||||
Content, Titles, DashyTitles, HTMLTitlesFound, Meta = '', [], [], False, {
|
||||
Content, Titles, DashyTitles, HTMLTitlesFound, Macros, Meta = '', [], [], False, '', {
|
||||
'Template': 'Standard.html',
|
||||
'Style': '',
|
||||
'Type': '',
|
||||
@ -122,6 +123,7 @@ def Preprocessor(Path, SiteRoot):
|
||||
'HTMLTitle': '',
|
||||
'Description': '',
|
||||
'Image': '',
|
||||
'Macros': {},
|
||||
'Categories': [],
|
||||
'CreatedOn': '',
|
||||
'EditedOn': '',
|
||||
@ -134,7 +136,9 @@ def Preprocessor(Path, SiteRoot):
|
||||
ItemText = '{}: '.format(Item)
|
||||
if lss.startswith(ItemText):
|
||||
Meta[Item] = lss[len(ItemText):]
|
||||
if lss.startswith('Categories: '):
|
||||
if lss.startswith('$'):
|
||||
Macros += lss[1:].lstrip() + '\n'
|
||||
elif lss.startswith('Categories: '):
|
||||
for i in lss[len('Categories: '):].split(' '):
|
||||
Meta['Categories'] += [i]
|
||||
elif lss.startswith('Background: '):
|
||||
@ -181,6 +185,12 @@ def Preprocessor(Path, SiteRoot):
|
||||
Content += MakeLinkableTitle(l, Title, DashTitle, 'pug') + '\n'
|
||||
else:
|
||||
Content += l + '\n'
|
||||
#if Macros:
|
||||
Meta['Macros'] = ReadConf(LoadConfStr('[Macros]\n' + Macros), 'Macros')
|
||||
# Macros = '[Macros]\n' + Macros
|
||||
# Macros = LoadConfStr(Macros)
|
||||
# Macros = ReadConf(Macros, 'Macros')
|
||||
# Meta['Macros'] = Macros
|
||||
return Content, Titles, Meta
|
||||
|
||||
def MakeListTitle(File, Meta, Titles, Prefer, SiteRoot, BlogName, PathPrefix=''):
|
||||
@ -279,19 +289,23 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
||||
HTML = ReplWithEsc(HTML, '[HTML:Site:Name]', SiteName)
|
||||
HTML = ReplWithEsc(HTML, '[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||
HTML = ReplWithEsc(HTML, '[HTML:Site:RelativeRoot]', GetPathLevels(PagePath))
|
||||
for i in FolderRoots:
|
||||
HTML = HTML.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(i), FolderRoots[i])
|
||||
for i in Categories:
|
||||
HTML = HTML.replace('<span>[HTML:Category:{}]</span>'.format(i), Categories[i])
|
||||
for e in Meta['Macros']:
|
||||
HTML = HTML.replace(f"{{{{{e}}}}}", Meta['Macros'][e]).replace(f"{{{{ {e} }}}}", Meta['Macros'][e])
|
||||
for e in FolderRoots:
|
||||
HTML = HTML.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(e), FolderRoots[e])
|
||||
for e in Categories:
|
||||
HTML = HTML.replace('<span>[HTML:Category:{}]</span>'.format(e), Categories[e])
|
||||
|
||||
# TODO: Clean this doubling?
|
||||
ContentHTML = Content
|
||||
ContentHTML = ContentHTML.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||
ContentHTML = ContentHTML.replace('[HTML:Site:RelativeRoot]', GetPathLevels(PagePath))
|
||||
for i in FolderRoots:
|
||||
ContentHTML = ContentHTML.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(i), FolderRoots[i])
|
||||
for i in Categories:
|
||||
ContentHTML = ContentHTML.replace('<span>[HTML:Category:{}]</span>'.format(i), Categories[i])
|
||||
for e in Meta['Macros']:
|
||||
ContentHTML = ContentHTML.replace(f"{{{{{e}}}}}", Meta['Macros'][e]).replace(f"{{{{ {e} }}}}", Meta['Macros'][e])
|
||||
for e in FolderRoots:
|
||||
ContentHTML = ContentHTML.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(e), FolderRoots[e])
|
||||
for e in Categories:
|
||||
ContentHTML = ContentHTML.replace('<span>[HTML:Category:{}]</span>'.format(e), Categories[e])
|
||||
SlimHTML = HTMLPagesList + ContentHTML
|
||||
|
||||
return HTML, ContentHTML, SlimHTML, Description, Image
|
||||
|
Loading…
x
Reference in New Issue
Block a user