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'))
|
||||
SiteDomain = Flags['SiteDomain'] = OptChoose('', Args.SiteDomain, ReadConf(SiteConf, 'Site', 'Domain'))
|
||||
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'] = SetSorting(Sorting)
|
||||
|
@ -180,6 +180,8 @@ def Main(Args, FeedEntries):
|
|||
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']
|
||||
|
||||
JournalRedirect = Flags["JournalRedirect"] = StrBoolChoose(DefConf["JournalRedirect"], Args.JournalRedirect, ReadConf(SiteConf, 'Journal', 'Redirect'))
|
||||
|
||||
DynamicParts = Flags['DynamicParts'] = literal_eval(OptionChoose('{}', Args.DynamicParts, ReadConf(SiteConf, 'Site', 'DynamicParts')))
|
||||
DynamicPartsText = Snippets['DynamicParts'] = LoadFromDir('DynamicParts', ['*.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('--InputDir', 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('--SiteName', type=str)
|
||||
Parser.add_argument('--BlogName', type=str)
|
||||
|
@ -313,6 +316,7 @@ if __name__ == '__main__':
|
|||
Parser.add_argument('--GemtextHeader', type=str)
|
||||
Parser.add_argument('--SiteTagline', type=str)
|
||||
Parser.add_argument('--SitemapOutput', type=str)
|
||||
Parser.add_argument('--JournalRedirect', type=str)
|
||||
Parser.add_argument('--FeedEntries', type=str)
|
||||
Parser.add_argument('--FolderRoots', type=str)
|
||||
Parser.add_argument('--DynamicParts', type=str)
|
||||
|
|
|
@ -11,17 +11,18 @@ import configparser
|
|||
from ast import literal_eval
|
||||
|
||||
DefConf = {
|
||||
'Logging': 20,
|
||||
'Threads': 0,
|
||||
'DiffBuild': False,
|
||||
'OutDir': 'public',
|
||||
'SiteLang': 'en',
|
||||
'SiteTemplate': 'Default.html',
|
||||
'ActivityPubTypeFilter': 'Post',
|
||||
'ActivityPubHoursLimit': 168,
|
||||
'CategoriesUncategorized': 'Uncategorized',
|
||||
'FeedCategoryFilter': 'Blog',
|
||||
'FeedEntries': 10
|
||||
"Logging": 20,
|
||||
"Threads": 0,
|
||||
"DiffBuild": False,
|
||||
"OutDir": "public",
|
||||
"SiteLang": "en",
|
||||
"SiteTemplate": "Default.html",
|
||||
"ActivityPubTypeFilter": "Post",
|
||||
"ActivityPubHoursLimit": 168,
|
||||
"CategoriesUncategorized": "Uncategorized",
|
||||
"FeedCategoryFilter": "Blog",
|
||||
"FeedEntries": 10,
|
||||
"JournalRedirect": False
|
||||
}
|
||||
|
||||
def LoadConfFile(File):
|
||||
|
|
|
@ -41,7 +41,7 @@ RedirectPageTemplate = """\
|
|||
</body>
|
||||
</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=[]):
|
||||
return UndupeStr(DashifyStr(Title.lstrip(' ').rstrip(' ')), Done, '-')
|
||||
|
@ -149,6 +149,8 @@ def MakeHTMLJournal(Flags, Locale, FilePath, HTML):
|
|||
Journal += str(ct)
|
||||
FileName = FilePath.split('/')[-1]
|
||||
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
|
||||
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 ''
|
||||
|
@ -160,20 +162,30 @@ def MakeHTMLJournal(Flags, Locale, FilePath, HTML):
|
|||
</p>
|
||||
"""
|
||||
Journal = f"""\
|
||||
<!--
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{Title}</title>
|
||||
<link rel="canonical" href="{URL}">
|
||||
<meta http-equiv="refresh" content="0; url='./{FileName}'">
|
||||
{Redirect}
|
||||
</head>
|
||||
<body>
|
||||
--->
|
||||
<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}
|
||||
</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>
|
||||
</html>
|
||||
--->
|
||||
"""
|
||||
return Journal
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
| Copyright (C) 2022, OctoSpacc |
|
||||
| ================================= """
|
||||
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from multiprocessing import Pool, cpu_count
|
||||
from Libs.bs4 import BeautifulSoup
|
||||
|
@ -152,7 +153,8 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
|
|||
'CreatedOn': '',
|
||||
'UpdatedOn': '',
|
||||
'EditedOn': '',
|
||||
'Order': None}
|
||||
'Order': None,
|
||||
'Language': None}
|
||||
# Find all positions of '<!--', '-->', add them in a list=[[pos0,pos1,line0,line1],...]
|
||||
for l in File.splitlines():
|
||||
ll = l.lstrip().rstrip()
|
||||
|
@ -345,8 +347,9 @@ def PatchHTML(File, HTML, StaticPartsText, DynamicParts, DynamicPartsText, HTMLP
|
|||
HTML = DictReplWithEsc(HTML, {
|
||||
'[staticoso:Site:Menu]': HTMLPagesList,
|
||||
'<staticoso:SiteMenu>': HTMLPagesList,
|
||||
'[staticoso:Page:Lang]': SiteLang,
|
||||
'<staticoso:PageLang>': SiteLang,
|
||||
'[staticoso:Page:Lang]': Meta['Language'] if Meta['Language'] else SiteLang,
|
||||
'<staticoso:PageLang>': Meta['Language'] if Meta['Language'] else SiteLang,
|
||||
'<staticoso:PageLanguage>': Meta['Language'] if Meta['Language'] else SiteLang,
|
||||
'[staticoso:Page:Chapters]': HTMLTitles,
|
||||
'<staticoso:PageSections>': HTMLTitles,
|
||||
'[staticoso:Page:Title]': Title,
|
||||
|
@ -527,8 +530,6 @@ def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, L
|
|||
if not LightRun:
|
||||
HTML = DoHTMLFixPre(HTML)
|
||||
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:
|
||||
SlimHTML = None
|
||||
|
@ -537,6 +538,31 @@ def HandlePage(Flags, Page, Pages, Categories, LimitFiles, Snippets, ConfMenu, L
|
|||
if not LightRun:
|
||||
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]
|
||||
|
||||
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)
|
||||
- User macros with arguments
|
||||
- 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
|
||||
- Release on pip
|
||||
- Alert for deprecated features
|
||||
|
|
Loading…
Reference in New Issue