mirror of https://gitlab.com/octtspacc/staticoso
Templating for HTML Journal pages, setting redirect or not
This commit is contained in:
parent
120d0bff11
commit
97ae55cc6f
|
@ -146,7 +146,7 @@ def Main(Args, FeedEntries):
|
||||||
SiteTemplate = Flags['SiteTemplate'] = DefConfOptChoose('SiteTemplate', Args.SiteTemplate, ReadConf(SiteConf, 'Site', 'Template'))
|
SiteTemplate = Flags['SiteTemplate'] = DefConfOptChoose('SiteTemplate', Args.SiteTemplate, ReadConf(SiteConf, 'Site', 'Template'))
|
||||||
SiteDomain = Flags['SiteDomain'] = OptChoose('', Args.SiteDomain, ReadConf(SiteConf, 'Site', 'Domain'))
|
SiteDomain = Flags['SiteDomain'] = OptChoose('', Args.SiteDomain, ReadConf(SiteConf, 'Site', 'Domain'))
|
||||||
SiteRoot = Flags['SiteRoot'] = OptChoose('/', Args.SiteRoot, ReadConf(SiteConf, 'Site', 'Root'))
|
SiteRoot = Flags['SiteRoot'] = OptChoose('/', Args.SiteRoot, ReadConf(SiteConf, 'Site', 'Root'))
|
||||||
SiteLang = Flags['SiteLang'] = DefConfOptChoose('SiteLang', Args.SiteLang, ReadConf(SiteConf, 'Site', 'Lang'))
|
SiteLang = Flags['SiteLang'] = DefConfOptChoose('SiteLang', Args.SiteLanguage, ReadConf(SiteConf, 'Site', 'Language'))
|
||||||
|
|
||||||
Sorting = Flags['Sorting'] = literal_eval(OptChoose('{}', Args.Sorting, ReadConf(SiteConf, 'Site', 'Sorting')))
|
Sorting = Flags['Sorting'] = literal_eval(OptChoose('{}', Args.Sorting, ReadConf(SiteConf, 'Site', 'Sorting')))
|
||||||
Sorting = Flags['Sorting'] = SetSorting(Sorting)
|
Sorting = Flags['Sorting'] = SetSorting(Sorting)
|
||||||
|
@ -180,6 +180,8 @@ def Main(Args, FeedEntries):
|
||||||
FeedCategoryFilter = Flags['FeedCategoryFilter'] = DefConfOptChoose('FeedCategoryFilter', Args.FeedCategoryFilter, ReadConf(SiteConf, 'Feed', 'CategoryFilter'))
|
FeedCategoryFilter = Flags['FeedCategoryFilter'] = DefConfOptChoose('FeedCategoryFilter', Args.FeedCategoryFilter, ReadConf(SiteConf, 'Feed', 'CategoryFilter'))
|
||||||
FeedEntries = Flags['FeedEntries'] = int(FeedEntries) if (FeedEntries or FeedEntries == 0) and FeedEntries != 'Default' else int(ReadConf(SiteConf, 'Feed', 'Entries')) if ReadConf(SiteConf, 'Feed', 'Entries') else DefConf['FeedEntries']
|
FeedEntries = Flags['FeedEntries'] = int(FeedEntries) if (FeedEntries or FeedEntries == 0) and FeedEntries != 'Default' else int(ReadConf(SiteConf, 'Feed', 'Entries')) if ReadConf(SiteConf, 'Feed', 'Entries') else DefConf['FeedEntries']
|
||||||
|
|
||||||
|
JournalRedirect = Flags["JournalRedirect"] = StrBoolChoose(DefConf["JournalRedirect"], Args.JournalRedirect, ReadConf(SiteConf, 'Journal', 'Redirect'))
|
||||||
|
|
||||||
DynamicParts = Flags['DynamicParts'] = literal_eval(OptionChoose('{}', Args.DynamicParts, ReadConf(SiteConf, 'Site', 'DynamicParts')))
|
DynamicParts = Flags['DynamicParts'] = literal_eval(OptionChoose('{}', Args.DynamicParts, ReadConf(SiteConf, 'Site', 'DynamicParts')))
|
||||||
DynamicPartsText = Snippets['DynamicParts'] = LoadFromDir('DynamicParts', ['*.htm', '*.html'])
|
DynamicPartsText = Snippets['DynamicParts'] = LoadFromDir('DynamicParts', ['*.htm', '*.html'])
|
||||||
StaticPartsText = Snippets['StaticParts'] = LoadFromDir('StaticParts', ['*.htm', '*.html'])
|
StaticPartsText = Snippets['StaticParts'] = LoadFromDir('StaticParts', ['*.htm', '*.html'])
|
||||||
|
@ -296,7 +298,8 @@ if __name__ == '__main__':
|
||||||
Parser.add_argument('--OutputDir', type=str)
|
Parser.add_argument('--OutputDir', type=str)
|
||||||
#Parser.add_argument('--InputDir', type=str)
|
#Parser.add_argument('--InputDir', type=str)
|
||||||
Parser.add_argument('--Sorting', type=str)
|
Parser.add_argument('--Sorting', type=str)
|
||||||
Parser.add_argument('--SiteLang', type=str)
|
Parser.add_argument('--SiteLang', type=str) # DEPRECATED
|
||||||
|
Parser.add_argument('--SiteLanguage', type=str)
|
||||||
Parser.add_argument('--SiteRoot', type=str)
|
Parser.add_argument('--SiteRoot', type=str)
|
||||||
Parser.add_argument('--SiteName', type=str)
|
Parser.add_argument('--SiteName', type=str)
|
||||||
Parser.add_argument('--BlogName', type=str)
|
Parser.add_argument('--BlogName', type=str)
|
||||||
|
@ -313,6 +316,7 @@ if __name__ == '__main__':
|
||||||
Parser.add_argument('--GemtextHeader', type=str)
|
Parser.add_argument('--GemtextHeader', type=str)
|
||||||
Parser.add_argument('--SiteTagline', type=str)
|
Parser.add_argument('--SiteTagline', type=str)
|
||||||
Parser.add_argument('--SitemapOutput', type=str)
|
Parser.add_argument('--SitemapOutput', type=str)
|
||||||
|
Parser.add_argument('--JournalRedirect', type=str)
|
||||||
Parser.add_argument('--FeedEntries', type=str)
|
Parser.add_argument('--FeedEntries', type=str)
|
||||||
Parser.add_argument('--FolderRoots', type=str)
|
Parser.add_argument('--FolderRoots', type=str)
|
||||||
Parser.add_argument('--DynamicParts', type=str)
|
Parser.add_argument('--DynamicParts', type=str)
|
||||||
|
|
|
@ -11,17 +11,18 @@ import configparser
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
|
|
||||||
DefConf = {
|
DefConf = {
|
||||||
'Logging': 20,
|
"Logging": 20,
|
||||||
'Threads': 0,
|
"Threads": 0,
|
||||||
'DiffBuild': False,
|
"DiffBuild": False,
|
||||||
'OutDir': 'public',
|
"OutDir": "public",
|
||||||
'SiteLang': 'en',
|
"SiteLang": "en",
|
||||||
'SiteTemplate': 'Default.html',
|
"SiteTemplate": "Default.html",
|
||||||
'ActivityPubTypeFilter': 'Post',
|
"ActivityPubTypeFilter": "Post",
|
||||||
'ActivityPubHoursLimit': 168,
|
"ActivityPubHoursLimit": 168,
|
||||||
'CategoriesUncategorized': 'Uncategorized',
|
"CategoriesUncategorized": "Uncategorized",
|
||||||
'FeedCategoryFilter': 'Blog',
|
"FeedCategoryFilter": "Blog",
|
||||||
'FeedEntries': 10
|
"FeedEntries": 10,
|
||||||
|
"JournalRedirect": False
|
||||||
}
|
}
|
||||||
|
|
||||||
def LoadConfFile(File):
|
def LoadConfFile(File):
|
||||||
|
|
|
@ -41,7 +41,7 @@ RedirectPageTemplate = """\
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
HTMLCommentsBlock = '<br><h3>{StrComments}</h3><a href="{URL}" rel="noopener" target="_blank">{StrOpen} ↗️</a>'
|
HTMLCommentsBlock = '<br><h3>{StrComments}</h3><a href="{URL}" rel="noopener" target="_blank">{StrOpen} <span class="twa twa-↗️"><span>↗️</span></span></a>'
|
||||||
|
|
||||||
def DashifyTitle(Title, Done=[]):
|
def DashifyTitle(Title, Done=[]):
|
||||||
return UndupeStr(DashifyStr(Title.lstrip(' ').rstrip(' ')), Done, '-')
|
return UndupeStr(DashifyStr(Title.lstrip(' ').rstrip(' ')), Done, '-')
|
||||||
|
@ -149,6 +149,8 @@ def MakeHTMLJournal(Flags, Locale, FilePath, HTML):
|
||||||
Journal += str(ct)
|
Journal += str(ct)
|
||||||
FileName = FilePath.split('/')[-1]
|
FileName = FilePath.split('/')[-1]
|
||||||
URL = f'{Flags["SiteDomain"]}/{StripExt(FilePath)}.Journal.html'
|
URL = f'{Flags["SiteDomain"]}/{StripExt(FilePath)}.Journal.html'
|
||||||
|
Redirect = f"""<meta http-equiv="refresh" content="0; url='./{FileName}'">""" if Flags["JournalRedirect"] else ''
|
||||||
|
|
||||||
# Instead of copying stuff from the full page, for now we use dedicated title, header, footer, and pagination
|
# Instead of copying stuff from the full page, for now we use dedicated title, header, footer, and pagination
|
||||||
Title = t.attrs["journaltitle"] if 'journaltitle' in t.attrs else f'"{StripExt(FileName)}" Journal - {Flags["SiteName"]}' if Flags["SiteName"] else f'"{StripExt(FileName)}" Journal'
|
Title = t.attrs["journaltitle"] if 'journaltitle' in t.attrs else f'"{StripExt(FileName)}" Journal - {Flags["SiteName"]}' if Flags["SiteName"] else f'"{StripExt(FileName)}" Journal'
|
||||||
FeedLink = f"""<a title="Journal Atom Feed" href="https://journal.miso.town/atom?url={URL}" target="_blank" rel="noopener"><img width="88" height="31" alt="Journal Atom Feed" title="Journal Atom Feed" src="data:image/png;base64,{b64encode(ReadFile(staticosoBaseDir()+'Assets/Feed-88x31.png', 'rb')).decode()}"></a>""" if Flags["SiteDomain"] else ''
|
FeedLink = f"""<a title="Journal Atom Feed" href="https://journal.miso.town/atom?url={URL}" target="_blank" rel="noopener"><img width="88" height="31" alt="Journal Atom Feed" title="Journal Atom Feed" src="data:image/png;base64,{b64encode(ReadFile(staticosoBaseDir()+'Assets/Feed-88x31.png', 'rb')).decode()}"></a>""" if Flags["SiteDomain"] else ''
|
||||||
|
@ -160,20 +162,30 @@ def MakeHTMLJournal(Flags, Locale, FilePath, HTML):
|
||||||
</p>
|
</p>
|
||||||
"""
|
"""
|
||||||
Journal = f"""\
|
Journal = f"""\
|
||||||
|
<!--
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>{Title}</title>
|
<title>{Title}</title>
|
||||||
<link rel="canonical" href="{URL}">
|
<link rel="canonical" href="{URL}">
|
||||||
<meta http-equiv="refresh" content="0; url='./{FileName}'">
|
{Redirect}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
--->
|
||||||
<h1>{Title}</h1>
|
<h1>{Title}</h1>
|
||||||
{Header}<br>
|
<header id="Header">
|
||||||
|
{Header}
|
||||||
|
<div id="staticoso-LinkToFooter"><b>[<big><a href="#Footer"><span class="twa twa-⬇️"><span>⬇️</span></span> Footer</a></big>]</b></div>
|
||||||
|
</header><br>
|
||||||
{Journal}
|
{Journal}
|
||||||
</article><br>
|
</article><br>
|
||||||
{t.attrs["journalfooter"] if "journalfooter" in t.attrs else ""}
|
<footer id="Footer">
|
||||||
|
<div id="staticoso-LinkToHeader"><b>[<big><a href="#Header"><span class="twa twa-⬆️"><span>⬆️</span></span> Header</a></big>]</b></div>
|
||||||
|
{t.attrs["journalfooter"] if "journalfooter" in t.attrs else ""}
|
||||||
|
</footer>
|
||||||
|
<!--
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
--->
|
||||||
"""
|
"""
|
||||||
return Journal
|
return Journal
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
| Copyright (C) 2022, OctoSpacc |
|
| Copyright (C) 2022, OctoSpacc |
|
||||||
| ================================= """
|
| ================================= """
|
||||||
|
|
||||||
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from multiprocessing import Pool, cpu_count
|
from multiprocessing import Pool, cpu_count
|
||||||
from Libs.bs4 import BeautifulSoup
|
from Libs.bs4 import BeautifulSoup
|
||||||
|
@ -152,7 +153,8 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
|
||||||
'CreatedOn': '',
|
'CreatedOn': '',
|
||||||
'UpdatedOn': '',
|
'UpdatedOn': '',
|
||||||
'EditedOn': '',
|
'EditedOn': '',
|
||||||
'Order': None}
|
'Order': None,
|
||||||
|
'Language': None}
|
||||||
# Find all positions of '<!--', '-->', add them in a list=[[pos0,pos1,line0,line1],...]
|
# Find all positions of '<!--', '-->', add them in a list=[[pos0,pos1,line0,line1],...]
|
||||||
for l in File.splitlines():
|
for l in File.splitlines():
|
||||||
ll = l.lstrip().rstrip()
|
ll = l.lstrip().rstrip()
|
||||||
|
@ -345,8 +347,9 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
||||||
HTML = DictReplWithEsc(HTML, {
|
HTML = DictReplWithEsc(HTML, {
|
||||||
'[staticoso:Site:Menu]': HTMLPagesList,
|
'[staticoso:Site:Menu]': HTMLPagesList,
|
||||||
'<staticoso:SiteMenu>': HTMLPagesList,
|
'<staticoso:SiteMenu>': HTMLPagesList,
|
||||||
'[staticoso:Page:Lang]': SiteLang,
|
'[staticoso:Page:Lang]': Meta['Language'] if Meta['Language'] else SiteLang,
|
||||||
'<staticoso:PageLang>': SiteLang,
|
'<staticoso:PageLang>': Meta['Language'] if Meta['Language'] else SiteLang,
|
||||||
|
'<staticoso:PageLanguage>': Meta['Language'] if Meta['Language'] else SiteLang,
|
||||||
'[staticoso:Page:Chapters]': HTMLTitles,
|
'[staticoso:Page:Chapters]': HTMLTitles,
|
||||||
'<staticoso:PageSections>': HTMLTitles,
|
'<staticoso:PageSections>': HTMLTitles,
|
||||||
'[staticoso:Page:Title]': Title,
|
'[staticoso:Page:Title]': Title,
|
||||||
|
@ -527,8 +530,6 @@ def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, L
|
||||||
if not LightRun:
|
if not LightRun:
|
||||||
HTML = DoHTMLFixPre(HTML)
|
HTML = DoHTMLFixPre(HTML)
|
||||||
ContentHTML = DoHTMLFixPre(ContentHTML)
|
ContentHTML = DoHTMLFixPre(ContentHTML)
|
||||||
if not LightRun and 'htmljournal' in ContentHTML.lower(): # Avoid extra cycles
|
|
||||||
WriteFile(StripExt(PagePath)+'.Journal.html', MakeHTMLJournal(Flags, Locale, f'{StripExt(File)}.html', ContentHTML))
|
|
||||||
|
|
||||||
if LightRun:
|
if LightRun:
|
||||||
SlimHTML = None
|
SlimHTML = None
|
||||||
|
@ -537,6 +538,31 @@ def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, L
|
||||||
if not LightRun:
|
if not LightRun:
|
||||||
WriteFile(PagePath, HTML)
|
WriteFile(PagePath, HTML)
|
||||||
|
|
||||||
|
if not LightRun and 'htmljournal' in ContentHTML.lower(): # Avoid extra cycles
|
||||||
|
HTML, _, _, _ = PatchHTML(
|
||||||
|
File=File,
|
||||||
|
HTML=TemplatesText[Meta['Template']],
|
||||||
|
StaticPartsText=StaticPartsText,
|
||||||
|
DynamicParts=DynamicParts,
|
||||||
|
DynamicPartsText=DynamicPartsText,
|
||||||
|
HTMLPagesList=HTMLPagesList,
|
||||||
|
PagePath=f'{StripExt(File)}.Journal.html',
|
||||||
|
Content=MakeHTMLJournal(Flags, Locale, f'{StripExt(File)}.html', ContentHTML),
|
||||||
|
Titles='',
|
||||||
|
Meta=Meta,
|
||||||
|
SiteDomain=SiteDomain,
|
||||||
|
SiteRoot=SiteRoot,
|
||||||
|
SiteName=SiteName,
|
||||||
|
BlogName=BlogName,
|
||||||
|
FolderRoots=FolderRoots,
|
||||||
|
Categories=Categories,
|
||||||
|
SiteLang=SiteLang,
|
||||||
|
Locale=Locale,
|
||||||
|
LightRun=LightRun)
|
||||||
|
if Flags["JournalRedirect"]:
|
||||||
|
HTML = HTML.replace('</head>', f"""<meta http-equiv="refresh" content="0; url='./{PagePath.split('''/''')[-1]}'"></head>""")
|
||||||
|
WriteFile(StripExt(PagePath)+'.Journal.html', HTML)
|
||||||
|
|
||||||
return [File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]
|
return [File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]
|
||||||
|
|
||||||
def MultiprocPagePreprocessor(d):
|
def MultiprocPagePreprocessor(d):
|
||||||
|
|
2
TODO
2
TODO
|
@ -1,7 +1,7 @@
|
||||||
|
- Choosing to use HTML or CSS styling for default internal snippets
|
||||||
- Pages transclusion + probably drop StaticParts (would be redundant)
|
- Pages transclusion + probably drop StaticParts (would be redundant)
|
||||||
- User macros with arguments
|
- User macros with arguments
|
||||||
- Specifying language for single pages, with the option applying to the locale used for templating
|
- Specifying language for single pages, with the option applying to the locale used for templating
|
||||||
- Apply HTML templating to Journal pages (requires a template that won't conflict, aka testing is needed)
|
|
||||||
- Internal macro substitutions have to be made until there's nothing to replace
|
- Internal macro substitutions have to be made until there's nothing to replace
|
||||||
- Release on pip
|
- Release on pip
|
||||||
- Alert for deprecated features
|
- Alert for deprecated features
|
||||||
|
|
Loading…
Reference in New Issue