mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-04-25 23:28:49 +02:00
Implement basic transclusions; Redirects without .html; Minor fixes
This commit is contained in:
parent
0567297de6
commit
fe4cf294d5
@ -100,16 +100,27 @@ def WriteRedirects(Flags:dict, Pages:list, FinalPaths, Locale:dict):
|
|||||||
SiteName = Flags['SiteName']
|
SiteName = Flags['SiteName']
|
||||||
for Page in Pages:
|
for Page in Pages:
|
||||||
for URL in Page['Meta']['URLs']:
|
for URL in Page['Meta']['URLs']:
|
||||||
DestFile = f'{Flags["OutDir"]}/{URL}'
|
for DestOpts in ((f'{Flags["OutDir"]}/{URL}', ''), (f'{Flags["OutDir"]}/{StripExt(URL)}/index.html', '../')):
|
||||||
if DestFile not in FinalPaths:
|
DestFile, DestPrefix = DestOpts
|
||||||
DestURL = f'{GetPathLevels(URL)}{StripExt(Page["File"])}.html'
|
if DestFile not in FinalPaths:
|
||||||
mkdirps(os.path.dirname(DestFile))
|
DestURL = f'{DestPrefix}{GetPathLevels(URL)}{StripExt(Page["File"])}.html'
|
||||||
WriteFile(DestFile, RedirectPageTemplate.format(
|
mkdirps(os.path.dirname(DestFile))
|
||||||
SiteDomain=Flags['SiteDomain'],
|
WriteFile(DestFile, RedirectPageTemplate.format(
|
||||||
DestURL=DestURL,
|
SiteDomain=Flags['SiteDomain'],
|
||||||
TitlePrefix=f'{SiteName} - ' if SiteName else '',
|
DestURL=DestURL,
|
||||||
StrClick=Locale['ClickHere'],
|
TitlePrefix=f'{SiteName} - ' if SiteName else '',
|
||||||
StrRedirect=Locale['IfNotRedirected']))
|
StrClick=Locale['ClickHere'],
|
||||||
|
StrRedirect=Locale['IfNotRedirected']))
|
||||||
|
if StripExt(Page["File"]).split('/')[-1].lower() != 'index':
|
||||||
|
DestFile = f'{Flags["OutDir"]}/{StripExt(Page["File"])}/index.html'
|
||||||
|
DestURL = f'../{StripExt(Page["File"]).split("/")[-1]}.html'
|
||||||
|
mkdirps(os.path.dirname(DestFile))
|
||||||
|
WriteFile(DestFile, RedirectPageTemplate.format(
|
||||||
|
SiteDomain=Flags['SiteDomain'],
|
||||||
|
DestURL=DestURL,
|
||||||
|
TitlePrefix=f'{SiteName} - ' if SiteName else '',
|
||||||
|
StrClick=Locale['ClickHere'],
|
||||||
|
StrRedirect=Locale['IfNotRedirected']))
|
||||||
|
|
||||||
def CopyBaseFiles(Flags:dict):
|
def CopyBaseFiles(Flags:dict):
|
||||||
f = NameSpace(Flags)
|
f = NameSpace(Flags)
|
||||||
|
@ -37,8 +37,9 @@ PageMetaDefault = {
|
|||||||
'Categories': [],
|
'Categories': [],
|
||||||
'URLs': [],
|
'URLs': [],
|
||||||
'CreatedOn': '',
|
'CreatedOn': '',
|
||||||
'UpdatedOn': '',
|
'PublishedOn': '', # Alias of CreatedOn
|
||||||
'EditedOn': '',
|
'EditedOn': '',
|
||||||
|
'UpdatedOn': '', # Alias of EditedOn
|
||||||
'Order': None,
|
'Order': None,
|
||||||
'Language': None,
|
'Language': None,
|
||||||
'Downsync': None
|
'Downsync': None
|
||||||
|
@ -232,6 +232,8 @@ def PagePreprocessor(Flags:dict, Page:list, GlobalMacros:dict, LightRun:bool=Fal
|
|||||||
Meta['URLs'] += [j]
|
Meta['URLs'] += [j]
|
||||||
else:
|
else:
|
||||||
Meta.update({i:MetaDefault[i]})
|
Meta.update({i:MetaDefault[i]})
|
||||||
|
if Meta['PublishedOn']:
|
||||||
|
Meta['CreatedOn'] = Meta['PublishedOn']
|
||||||
if Meta['UpdatedOn']:
|
if Meta['UpdatedOn']:
|
||||||
Meta['EditedOn'] = Meta['UpdatedOn']
|
Meta['EditedOn'] = Meta['UpdatedOn']
|
||||||
if Meta['Index'].lower() in ('default', 'unspecified', 'categories'):
|
if Meta['Index'].lower() in ('default', 'unspecified', 'categories'):
|
||||||
|
@ -48,10 +48,10 @@ def HandleDynamicParts(Flags:dict, Html:str, Snippets:dict):
|
|||||||
return Html
|
return Html
|
||||||
|
|
||||||
# TODO: This would need to be handled either fully before or fully after after all pages' content has been transformed to HTML, else other markups end up in HTML and the page is broken
|
# TODO: This would need to be handled either fully before or fully after after all pages' content has been transformed to HTML, else other markups end up in HTML and the page is broken
|
||||||
def HandleTransclusions(Html:str, Caller:str, Pages:list):
|
def HandleTransclusions(Base:str, Caller:str, Pages:list):
|
||||||
#if Type == 'Evals': # [% cmd %] | {% cmd %}
|
#if Type == 'Evals': # [% cmd %] | {% cmd %}
|
||||||
Targets = []
|
Targets = []
|
||||||
Finding = Html
|
Finding = Base
|
||||||
Start = Finding.find('{{')
|
Start = Finding.find('{{')
|
||||||
while Start != -1:
|
while Start != -1:
|
||||||
Start = Start + 2
|
Start = Start + 2
|
||||||
@ -61,13 +61,13 @@ def HandleTransclusions(Html:str, Caller:str, Pages:list):
|
|||||||
Targets += [Finding[:Stop]]
|
Targets += [Finding[:Stop]]
|
||||||
Start = Finding.find('{{')
|
Start = Finding.find('{{')
|
||||||
for Target in Targets:
|
for Target in Targets:
|
||||||
# Maybe we should show an error message on possible recursive transclusion, as currently this doesn't handle escaped tokens
|
# We should show an error message on inexistant transclusion and possible recursive transclusion, as currently this doesn't handle escaped tokens
|
||||||
if Target != Caller:
|
if Target != Caller:
|
||||||
for File, Content, _, _ in Pages:
|
for File, Content, _, _ in Pages:
|
||||||
if File == Target:
|
if File == Target:
|
||||||
Html = ReplWithEsc(Html, '{{' + Target + '}}', Content)
|
Base = ReplWithEsc(Base, '{{' + Target + '}}', Content)
|
||||||
break
|
break
|
||||||
return Html
|
return Base
|
||||||
|
|
||||||
def PatchHtml(Flags:dict, Pages:list, Page:dict, Context:dict, Snippets:dict, Locale:dict, LightRun):
|
def PatchHtml(Flags:dict, Pages:list, Page:dict, Context:dict, Snippets:dict, Locale:dict, LightRun):
|
||||||
f = NameSpace(Flags)
|
f = NameSpace(Flags)
|
||||||
@ -140,6 +140,7 @@ def PatchHtml(Flags:dict, Pages:list, Page:dict, Context:dict, Snippets:dict, Lo
|
|||||||
'staticoso:PagePath': PagePath,
|
'staticoso:PagePath': PagePath,
|
||||||
'staticoso:PageHead': Meta['Head'],
|
'staticoso:PageHead': Meta['Head'],
|
||||||
'staticoso:PageStyle': Meta['Style'],
|
'staticoso:PageStyle': Meta['Style'],
|
||||||
|
'staticoso:PageCreatedOn': Meta['CreatedOn'],
|
||||||
# NOTE: Content is injected in page only at this point! Keep in mind for other substitutions
|
# NOTE: Content is injected in page only at this point! Keep in mind for other substitutions
|
||||||
# #DEPRECATION #
|
# #DEPRECATION #
|
||||||
'staticoso:Page:Content': Content,
|
'staticoso:Page:Content': Content,
|
||||||
@ -176,18 +177,18 @@ def PatchHtml(Flags:dict, Pages:list, Page:dict, Context:dict, Snippets:dict, Lo
|
|||||||
ContentHtml = Content
|
ContentHtml = Content
|
||||||
ContentHtml = WrapDictReplWithEsc(ContentHtml, {
|
ContentHtml = WrapDictReplWithEsc(ContentHtml, {
|
||||||
# #DEPRECATION #
|
# #DEPRECATION #
|
||||||
'[staticoso:Page:Title]': Title,
|
'staticoso:Page:Title': Title,
|
||||||
'[staticoso:Page:Description]': Description,
|
'staticoso:Page:Description': Description,
|
||||||
'[staticoso:Site:Name]': f.SiteName,
|
'staticoso:Site:Name': f.SiteName,
|
||||||
'[staticoso:Site:AbsoluteRoot]': f.SiteRoot,
|
'staticoso:Site:AbsoluteRoot': f.SiteRoot,
|
||||||
'[staticoso:Site:RelativeRoot]': RelativeRoot,
|
'staticoso:Site:RelativeRoot': RelativeRoot,
|
||||||
################
|
################
|
||||||
'<staticoso:PageTitle>': Title,
|
'staticoso:PageTitle': Title,
|
||||||
'<staticoso:PageDescription>': Description,
|
'staticoso:PageDescription': Description,
|
||||||
'<staticoso:SiteDomain>': f.SiteDomain,
|
'staticoso:SiteDomain': f.SiteDomain,
|
||||||
'<staticoso:SiteName>': f.SiteName,
|
'staticoso:SiteName': f.SiteName,
|
||||||
'<staticoso:SiteAbsoluteRoot>': f.SiteRoot,
|
'staticoso:SiteAbsoluteRoot': f.SiteRoot,
|
||||||
'<staticoso:SiteRelativeRoot>': RelativeRoot,
|
'staticoso:SiteRelativeRoot': RelativeRoot,
|
||||||
}, InternalMacrosWraps)
|
}, InternalMacrosWraps)
|
||||||
#Html = WhileFuncResultChanges(HandleTransclusions, {"Html": Html, "Caller": File, "Pages": Pages}, 'Html')
|
#Html = WhileFuncResultChanges(HandleTransclusions, {"Html": Html, "Caller": File, "Pages": Pages}, 'Html')
|
||||||
for e in Meta['Macros']:
|
for e in Meta['Macros']:
|
||||||
@ -239,6 +240,9 @@ def HandlePage(Flags:dict, Page:list, Pages:list, Categories, LimitFiles, Snippe
|
|||||||
ContentPagePath = f'{f.OutDir}.Content/{StripExt(File)}.html'
|
ContentPagePath = f'{f.OutDir}.Content/{StripExt(File)}.html'
|
||||||
LightRun = False if LimitFiles == False or File in LimitFiles else True
|
LightRun = False if LimitFiles == False or File in LimitFiles else True
|
||||||
|
|
||||||
|
# This should be done after all pages are converted to HTML, else issues with different formats will occur
|
||||||
|
Content = HandleTransclusions(Content, File, Pages)
|
||||||
|
|
||||||
if FileLower.endswith(FileExtensions['Markdown']):
|
if FileLower.endswith(FileExtensions['Markdown']):
|
||||||
Content = markdown(PagePostprocessor('md', Content, Meta), extensions=f.MarkdownExts)
|
Content = markdown(PagePostprocessor('md', Content, Meta), extensions=f.MarkdownExts)
|
||||||
elif FileLower.endswith(('.pug')):
|
elif FileLower.endswith(('.pug')):
|
||||||
@ -430,9 +434,6 @@ def MakeSite(Flags:dict, LimitFiles, Snippets, ConfMenu, GlobalMacros:dict, Loca
|
|||||||
Categories = PopulateCategoryLists(Flags, Pages, Categories)
|
Categories = PopulateCategoryLists(Flags, Pages, Categories)
|
||||||
Pages += MakeAutoCategories(Flags, Categories)
|
Pages += MakeAutoCategories(Flags, Categories)
|
||||||
|
|
||||||
#logging.info("Building the HTML Search Page")
|
|
||||||
#Pages += [PagePreprocessor(Flags, Path='Search.html', TempPath='Search.html', Type='Page', SiteTemplate=SiteTemplate, GlobalMacros=GlobalMacros, LightRun=LightRun, Content=BuildPagesSearch(Flags, Pages))]
|
|
||||||
|
|
||||||
for i,e in enumerate(ConfMenu):
|
for i,e in enumerate(ConfMenu):
|
||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
File = StripExt(File)+'.html'
|
File = StripExt(File)+'.html'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user