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]})
|
||||
return Sorting
|
||||
|
||||
def GetConfMenu(Conf):
|
||||
def GetConfMenu(Conf, MarkdownExts):
|
||||
Entries = ReadConf(Conf, 'Menu')
|
||||
if Entries:
|
||||
Menu, Max = [], 0
|
||||
|
@ -67,15 +67,15 @@ def GetConfMenu(Conf):
|
|||
if (e.startswith('<') and e.endswith('>')) or (e.startswith('[') and e.endswith(')')):
|
||||
Menu[int(i)] = markdown(e, extensions=MarkdownExts)
|
||||
else:
|
||||
if not (e.lower().endswith('.html') or e.lower().endswith('.htm')):
|
||||
Menu[int(i)] = e + '.html'
|
||||
if not e.lower().endswith('.html'):
|
||||
e += '.html'
|
||||
Menu[int(i)] = e
|
||||
print(Menu)
|
||||
return Menu
|
||||
|
||||
def Main(Args, FeedEntries):
|
||||
HavePages, HavePosts = False, False
|
||||
SiteConf = LoadConf('Site.ini')
|
||||
#SiteMenu = GetConfMenu(SiteConf)
|
||||
|
||||
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 ''
|
||||
|
@ -128,6 +128,7 @@ def Main(Args, FeedEntries):
|
|||
PartsText=LoadFromDir('Parts', '*.html'),
|
||||
ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {},
|
||||
ContextPartsText=LoadFromDir('ContextParts', '*.html'),
|
||||
ConfMenu=[],#GetConfMenu(SiteConf, MarkdownExts),
|
||||
SiteName=SiteName,
|
||||
BlogName=BlogName,
|
||||
SiteTagline=SiteTagline,
|
||||
|
|
|
@ -69,7 +69,7 @@ def MakeCategoryLine(File, Meta):
|
|||
Categories += '[{}]({}{}.html) '.format(i, GetPathLevels(File) + 'Categories/', i)
|
||||
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 = '', [], []
|
||||
IndexPages = Pages.copy()
|
||||
for e in IndexPages:
|
||||
|
@ -83,8 +83,11 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Type='Page', Categor
|
|||
IndexPages.pop(i)
|
||||
if Type == 'Page':
|
||||
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:
|
||||
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
|
||||
if n > 1:
|
||||
CurParent = File.split('/')[:-1]
|
||||
|
@ -99,7 +102,10 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Type='Page', Categor
|
|||
List += Levels + Title + '\n'
|
||||
if not (n > 1 and StripExt(File).endswith('index')):
|
||||
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'
|
||||
return markdown(List)
|
||||
|
||||
|
@ -275,7 +281,7 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
|||
|
||||
return HTML, ContentHTML, SlimHTML, Description, Image
|
||||
|
||||
def DoMinify(HTML):
|
||||
def DoMinifyHTML(HTML):
|
||||
return htmlmin.minify(
|
||||
input=HTML,
|
||||
remove_comments=True,
|
||||
|
@ -287,7 +293,7 @@ def DoMinify(HTML):
|
|||
convert_charrefs=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 = [], [], [], [], {}
|
||||
for Ext in FileExtensions['Pages']:
|
||||
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)
|
||||
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")
|
||||
for File, Content, Titles, Meta in Pages:
|
||||
HTMLPagesList = GetHTMLPagesList(
|
||||
|
@ -362,6 +377,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||
BlogName=BlogName,
|
||||
SiteRoot=SiteRoot,
|
||||
PathPrefix=GetPathLevels(File),
|
||||
Unite=ConfMenu,
|
||||
Type='Page',
|
||||
For='Menu')
|
||||
PagePath = 'public/{}.html'.format(StripExt(File))
|
||||
|
@ -388,7 +404,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||
SiteLang=SiteLang,
|
||||
Locale=Locale)
|
||||
if Minify:
|
||||
HTML = DoMinify(HTML)
|
||||
HTML = DoMinifyHTML(HTML)
|
||||
WriteFile(PagePath, HTML)
|
||||
MadePages += [[File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]]
|
||||
|
||||
|
|
Loading…
Reference in New Issue