mirror of https://gitlab.com/octtspacc/staticoso
Base code for custom site menus
This commit is contained in:
parent
de9f0e832b
commit
68a639b8c0
|
@ -53,7 +53,7 @@ def SetSorting(Sorting):
|
||||||
Sorting.update({i:Default[i]})
|
Sorting.update({i:Default[i]})
|
||||||
return Sorting
|
return Sorting
|
||||||
|
|
||||||
def GetConfMenu(Conf):
|
def GetConfMenu(Conf, MarkdownExts):
|
||||||
Entries = ReadConf(Conf, 'Menu')
|
Entries = ReadConf(Conf, 'Menu')
|
||||||
if Entries:
|
if Entries:
|
||||||
Menu, Max = [], 0
|
Menu, Max = [], 0
|
||||||
|
@ -67,15 +67,15 @@ def GetConfMenu(Conf):
|
||||||
if (e.startswith('<') and e.endswith('>')) or (e.startswith('[') and e.endswith(')')):
|
if (e.startswith('<') and e.endswith('>')) or (e.startswith('[') and e.endswith(')')):
|
||||||
Menu[int(i)] = markdown(e, extensions=MarkdownExts)
|
Menu[int(i)] = markdown(e, extensions=MarkdownExts)
|
||||||
else:
|
else:
|
||||||
if not (e.lower().endswith('.html') or e.lower().endswith('.htm')):
|
if not e.lower().endswith('.html'):
|
||||||
Menu[int(i)] = e + '.html'
|
e += '.html'
|
||||||
|
Menu[int(i)] = e
|
||||||
print(Menu)
|
print(Menu)
|
||||||
return Menu
|
return Menu
|
||||||
|
|
||||||
def Main(Args, FeedEntries):
|
def Main(Args, FeedEntries):
|
||||||
HavePages, HavePosts = False, False
|
HavePages, HavePosts = False, False
|
||||||
SiteConf = LoadConf('Site.ini')
|
SiteConf = LoadConf('Site.ini')
|
||||||
#SiteMenu = GetConfMenu(SiteConf)
|
|
||||||
|
|
||||||
SiteName = Args.SiteName if Args.SiteName else ReadConf(SiteConf, 'Site', 'Name') if ReadConf(SiteConf, 'Site', 'Name') else ''
|
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 ''
|
BlogName = Args.BlogName if Args.BlogName else ReadConf(SiteConf, 'Site', 'BlogName') if ReadConf(SiteConf, 'Site', 'BlogName') else ''
|
||||||
|
@ -128,6 +128,7 @@ def Main(Args, FeedEntries):
|
||||||
PartsText=LoadFromDir('Parts', '*.html'),
|
PartsText=LoadFromDir('Parts', '*.html'),
|
||||||
ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {},
|
ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {},
|
||||||
ContextPartsText=LoadFromDir('ContextParts', '*.html'),
|
ContextPartsText=LoadFromDir('ContextParts', '*.html'),
|
||||||
|
ConfMenu=[],#GetConfMenu(SiteConf, MarkdownExts),
|
||||||
SiteName=SiteName,
|
SiteName=SiteName,
|
||||||
BlogName=BlogName,
|
BlogName=BlogName,
|
||||||
SiteTagline=SiteTagline,
|
SiteTagline=SiteTagline,
|
||||||
|
|
|
@ -69,7 +69,7 @@ def MakeCategoryLine(File, Meta):
|
||||||
Categories += '[{}]({}{}.html) '.format(i, GetPathLevels(File) + 'Categories/', i)
|
Categories += '[{}]({}{}.html) '.format(i, GetPathLevels(File) + 'Categories/', i)
|
||||||
return Categories
|
return Categories
|
||||||
|
|
||||||
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Type='Page', Category=None, For='Menu'):
|
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page', Category=None, For='Menu'):
|
||||||
List, ToPop, LastParent = '', [], []
|
List, ToPop, LastParent = '', [], []
|
||||||
IndexPages = Pages.copy()
|
IndexPages = Pages.copy()
|
||||||
for e in IndexPages:
|
for e in IndexPages:
|
||||||
|
@ -83,8 +83,11 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Type='Page', Categor
|
||||||
IndexPages.pop(i)
|
IndexPages.pop(i)
|
||||||
if Type == 'Page':
|
if Type == 'Page':
|
||||||
IndexPages = OrderPages(IndexPages)
|
IndexPages = OrderPages(IndexPages)
|
||||||
|
for i,e in enumerate(Unite):
|
||||||
|
if e:
|
||||||
|
IndexPages.insert(i,[e,None,None,{'Type':Type,'Index':'True','Order':'Unite'}])
|
||||||
for File, Content, Titles, Meta in IndexPages:
|
for File, Content, Titles, Meta in IndexPages:
|
||||||
if Meta['Type'] == Type and CanIndex(Meta['Index'], For) and GetTitle(Meta, Titles, 'HTMLTitle', BlogName) != 'Untitled' and (not Category or Category in Meta['Categories']):
|
if Meta['Type'] == Type and CanIndex(Meta['Index'], For) and (not Category or Category in Meta['Categories']):
|
||||||
n = File.count('/') + 1
|
n = File.count('/') + 1
|
||||||
if n > 1:
|
if n > 1:
|
||||||
CurParent = File.split('/')[:-1]
|
CurParent = File.split('/')[:-1]
|
||||||
|
@ -99,7 +102,10 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Type='Page', Categor
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
if not (n > 1 and StripExt(File).endswith('index')):
|
if not (n > 1 and StripExt(File).endswith('index')):
|
||||||
Levels = '- ' * n
|
Levels = '- ' * n
|
||||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
if Meta['Order'] == 'Unite':
|
||||||
|
Title = File
|
||||||
|
else:
|
||||||
|
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
return markdown(List)
|
return markdown(List)
|
||||||
|
|
||||||
|
@ -275,7 +281,7 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
||||||
|
|
||||||
return HTML, ContentHTML, SlimHTML, Description, Image
|
return HTML, ContentHTML, SlimHTML, Description, Image
|
||||||
|
|
||||||
def DoMinify(HTML):
|
def DoMinifyHTML(HTML):
|
||||||
return htmlmin.minify(
|
return htmlmin.minify(
|
||||||
input=HTML,
|
input=HTML,
|
||||||
remove_comments=True,
|
remove_comments=True,
|
||||||
|
@ -287,7 +293,7 @@ def DoMinify(HTML):
|
||||||
convert_charrefs=True,
|
convert_charrefs=True,
|
||||||
keep_pre=True)
|
keep_pre=True)
|
||||||
|
|
||||||
def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName, BlogName, SiteTagline, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, Sorting, MarkdownExts, AutoCategories):
|
def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu, SiteName, BlogName, SiteTagline, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, Sorting, MarkdownExts, AutoCategories):
|
||||||
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
||||||
for Ext in FileExtensions['Pages']:
|
for Ext in FileExtensions['Pages']:
|
||||||
for File in Path('Pages').rglob('*.{}'.format(Ext)):
|
for File in Path('Pages').rglob('*.{}'.format(Ext)):
|
||||||
|
@ -355,6 +361,15 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
Content, Titles, Meta = Preprocessor(FilePath, SiteRoot)
|
Content, Titles, Meta = Preprocessor(FilePath, SiteRoot)
|
||||||
Pages += [[File, Content, Titles, Meta]]
|
Pages += [[File, Content, Titles, Meta]]
|
||||||
|
|
||||||
|
for i,e in enumerate(ConfMenu):
|
||||||
|
print(e,i)
|
||||||
|
for File, Content, Titles, Meta in Pages:
|
||||||
|
File = StripExt(File)+'.html'
|
||||||
|
if e == File:
|
||||||
|
ConfMenu[i] = None
|
||||||
|
print(File)
|
||||||
|
print(ConfMenu)
|
||||||
|
|
||||||
print("[I] Writing Pages")
|
print("[I] Writing Pages")
|
||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
HTMLPagesList = GetHTMLPagesList(
|
HTMLPagesList = GetHTMLPagesList(
|
||||||
|
@ -362,6 +377,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
BlogName=BlogName,
|
BlogName=BlogName,
|
||||||
SiteRoot=SiteRoot,
|
SiteRoot=SiteRoot,
|
||||||
PathPrefix=GetPathLevels(File),
|
PathPrefix=GetPathLevels(File),
|
||||||
|
Unite=ConfMenu,
|
||||||
Type='Page',
|
Type='Page',
|
||||||
For='Menu')
|
For='Menu')
|
||||||
PagePath = 'public/{}.html'.format(StripExt(File))
|
PagePath = 'public/{}.html'.format(StripExt(File))
|
||||||
|
@ -388,7 +404,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
||||||
SiteLang=SiteLang,
|
SiteLang=SiteLang,
|
||||||
Locale=Locale)
|
Locale=Locale)
|
||||||
if Minify:
|
if Minify:
|
||||||
HTML = DoMinify(HTML)
|
HTML = DoMinifyHTML(HTML)
|
||||||
WriteFile(PagePath, HTML)
|
WriteFile(PagePath, HTML)
|
||||||
MadePages += [[File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]]
|
MadePages += [[File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue