mirror of https://gitlab.com/octtspacc/staticoso
Remove custom reserved paths, List categories for pages, fix bugs
This commit is contained in:
parent
9249fa359a
commit
b9d43c2a3a
|
@ -183,22 +183,21 @@ def Preprocessor(Path, SiteRoot):
|
||||||
|
|
||||||
def MakeContentHeader(Meta, Locale, Categories=''):
|
def MakeContentHeader(Meta, Locale, Categories=''):
|
||||||
Header = ''
|
Header = ''
|
||||||
if Meta['Type'] == 'Post':
|
for i in ['CreatedOn', 'EditedOn']:
|
||||||
for i in ['CreatedOn', 'EditedOn']:
|
if Meta[i]:
|
||||||
if Meta[i]:
|
Header += '{} {} \n'.format(Locale[i], Meta[i])
|
||||||
Header += '{} {} \n'.format(Locale[i], Meta[i])
|
if Categories:
|
||||||
if Categories:
|
Header += '{}: {} \n'.format(Locale['Categories'], Categories)
|
||||||
Header += '{}: {} \n'.format(Locale['Categories'], Categories)
|
|
||||||
return markdown(Header)
|
return markdown(Header)
|
||||||
|
|
||||||
def MakeCategoryLine(Meta, Reserved):
|
def MakeCategoryLine(File, Meta):
|
||||||
Categories = ''
|
Categories = ''
|
||||||
if Meta['Categories']:
|
if Meta['Categories']:
|
||||||
for i in Meta['Categories']:
|
for i in Meta['Categories']:
|
||||||
Categories += '[{}]({}{}.html) '.format(i, GetLevels(Reserved['Categories']) + Reserved['Categories'], i)
|
Categories += '[{}]({}{}.html) '.format(i, GetLevels(File) + 'Categories/', i)
|
||||||
return Categories
|
return Categories
|
||||||
|
|
||||||
def PatchHTML(HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteRoot, FolderRoots, Categories, Locale, Reserved):
|
def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteRoot, FolderRoots, Categories, Locale):
|
||||||
HTMLTitles = FormatTitles(Titles)
|
HTMLTitles = FormatTitles(Titles)
|
||||||
BodyDescription, BodyImage = '', ''
|
BodyDescription, BodyImage = '', ''
|
||||||
Parse = BeautifulSoup(Content, 'html.parser')
|
Parse = BeautifulSoup(Content, 'html.parser')
|
||||||
|
@ -237,7 +236,7 @@ def PatchHTML(HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesList, Pa
|
||||||
HTML = HTML.replace('[HTML:Page:Path]', PagePath)
|
HTML = HTML.replace('[HTML:Page:Path]', PagePath)
|
||||||
HTML = HTML.replace('[HTML:Page:Style]', Meta['Style'])
|
HTML = HTML.replace('[HTML:Page:Style]', Meta['Style'])
|
||||||
HTML = HTML.replace('[HTML:Page:Content]', Content)
|
HTML = HTML.replace('[HTML:Page:Content]', Content)
|
||||||
HTML = HTML.replace('[HTML:Page:ContentHeader]', MakeContentHeader(Meta, Locale, MakeCategoryLine(Meta, Reserved)))
|
HTML = HTML.replace('[HTML:Page:ContentHeader]', MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta)))
|
||||||
HTML = HTML.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
HTML = HTML.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||||
HTML = HTML.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
HTML = HTML.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
||||||
for i in FolderRoots:
|
for i in FolderRoots:
|
||||||
|
@ -345,7 +344,7 @@ def DoMinify(HTML):
|
||||||
convert_charrefs=True,
|
convert_charrefs=True,
|
||||||
keep_pre=True)
|
keep_pre=True)
|
||||||
|
|
||||||
def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName, SiteTagline, SiteDomain, SiteRoot, FolderRoots, Reserved, Locale, Minify, Sorting, MarkdownExts):
|
def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName, SiteTagline, SiteDomain, SiteRoot, FolderRoots, Locale, Minify, Sorting, MarkdownExts):
|
||||||
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
||||||
for Ext in Extensions['Pages']:
|
for Ext in Extensions['Pages']:
|
||||||
for File in Path('Pages').rglob('*.{}'.format(Ext)):
|
for File in Path('Pages').rglob('*.{}'.format(Ext)):
|
||||||
|
@ -385,14 +384,14 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
Categories[Category] = GetHTMLPagesList(
|
Categories[Category] = GetHTMLPagesList(
|
||||||
Pages=Pages,
|
Pages=Pages,
|
||||||
SiteRoot=SiteRoot,
|
SiteRoot=SiteRoot,
|
||||||
PathPrefix=GetLevels(Reserved['Categories']), # This hardcodes paths, TODO make it somehow guess the path for every page containing the [HTML:Category] macro
|
PathPrefix=GetLevels('Categories/'),
|
||||||
Type='Page',
|
Type='Page',
|
||||||
Category=Category,
|
Category=Category,
|
||||||
For='Categories')
|
For='Categories')
|
||||||
Categories[Category] += GetHTMLPagesList(
|
Categories[Category] += GetHTMLPagesList(
|
||||||
Pages=Pages,
|
Pages=Pages,
|
||||||
SiteRoot=SiteRoot,
|
SiteRoot=SiteRoot,
|
||||||
PathPrefix=GetLevels(Reserved['Categories']), # This hardcodes paths, TODO make it somehow guess the path for every page containing the [HTML:Category] macro
|
PathPrefix=GetLevels('Categories/'),
|
||||||
Type='Post',
|
Type='Post',
|
||||||
Category=Category,
|
Category=Category,
|
||||||
For='Categories')
|
For='Categories')
|
||||||
|
@ -411,6 +410,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
elif File.endswith('.pug'):
|
elif File.endswith('.pug'):
|
||||||
Content = ReadFile(PagePath)
|
Content = ReadFile(PagePath)
|
||||||
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
||||||
|
File=File,
|
||||||
HTML=TemplatesText[Meta['Template']],
|
HTML=TemplatesText[Meta['Template']],
|
||||||
PartsText=PartsText,
|
PartsText=PartsText,
|
||||||
ContextParts=ContextParts,
|
ContextParts=ContextParts,
|
||||||
|
@ -423,8 +423,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
SiteRoot=SiteRoot,
|
SiteRoot=SiteRoot,
|
||||||
FolderRoots=FolderRoots,
|
FolderRoots=FolderRoots,
|
||||||
Categories=Categories,
|
Categories=Categories,
|
||||||
Locale=Locale,
|
Locale=Locale)
|
||||||
Reserved=Reserved)
|
|
||||||
if Minify not in ('False', 'None'):
|
if Minify not in ('False', 'None'):
|
||||||
HTML = DoMinify(HTML)
|
HTML = DoMinify(HTML)
|
||||||
WriteFile(PagePath, HTML)
|
WriteFile(PagePath, HTML)
|
||||||
|
@ -432,15 +431,6 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
|
|
||||||
return MadePages
|
return MadePages
|
||||||
|
|
||||||
def SetReserved(Reserved):
|
|
||||||
for i in ['Categories']:
|
|
||||||
if i not in Reserved:
|
|
||||||
Reserved.update({i:i})
|
|
||||||
for i in Reserved:
|
|
||||||
if not Reserved[i].endswith('/'):
|
|
||||||
Reserved[i] = '{}/'.format(Reserved[i])
|
|
||||||
return Reserved
|
|
||||||
|
|
||||||
def SetSorting(Sorting):
|
def SetSorting(Sorting):
|
||||||
Default = {
|
Default = {
|
||||||
'Pages':'Standard',
|
'Pages':'Standard',
|
||||||
|
@ -480,7 +470,6 @@ def Main(Args, FeedEntries):
|
||||||
SiteDomain=SiteDomain,
|
SiteDomain=SiteDomain,
|
||||||
SiteRoot=Args.SiteRoot if Args.SiteRoot else '/',
|
SiteRoot=Args.SiteRoot if Args.SiteRoot else '/',
|
||||||
FolderRoots=literal_eval(Args.FolderRoots) if Args.FolderRoots else {},
|
FolderRoots=literal_eval(Args.FolderRoots) if Args.FolderRoots else {},
|
||||||
Reserved=SetReserved(literal_eval(Args.ReservedPaths) if Args.ReservedPaths else {}),
|
|
||||||
Locale=Locale,
|
Locale=Locale,
|
||||||
Minify=Args.Minify if Args.Minify else 'None',
|
Minify=Args.Minify if Args.Minify else 'None',
|
||||||
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
||||||
|
@ -545,7 +534,6 @@ if __name__ == '__main__':
|
||||||
Parser.add_argument('--FolderRoots', type=str)
|
Parser.add_argument('--FolderRoots', type=str)
|
||||||
Parser.add_argument('--ContextParts', type=str)
|
Parser.add_argument('--ContextParts', type=str)
|
||||||
Parser.add_argument('--MarkdownExts', type=str)
|
Parser.add_argument('--MarkdownExts', type=str)
|
||||||
Parser.add_argument('--ReservedPaths', type=str)
|
|
||||||
Parser.add_argument('--MastodonURL', type=str)
|
Parser.add_argument('--MastodonURL', type=str)
|
||||||
Parser.add_argument('--MastodonToken', type=str)
|
Parser.add_argument('--MastodonToken', type=str)
|
||||||
Args = Parser.parse_args()
|
Args = Parser.parse_args()
|
||||||
|
@ -553,7 +541,7 @@ if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
import lxml
|
import lxml
|
||||||
from Modules.Feed import *
|
from Modules.Feed import *
|
||||||
FeedEntries = Args.FeedEntries if Args.FeedEntries else 10
|
FeedEntries = Args.FeedEntries if Args.FeedEntries or Args.FeedEntries == 0 else 10
|
||||||
except:
|
except:
|
||||||
print("[E] Can't load the Atom/RSS feed libraries. Their generation is disabled.")
|
print("[E] Can't load the Atom/RSS feed libraries. Their generation is disabled.")
|
||||||
FeedEntries = 0
|
FeedEntries = 0
|
||||||
|
|
Loading…
Reference in New Issue