mirror of https://gitlab.com/octtspacc/staticoso
Custom menu
This commit is contained in:
parent
68a639b8c0
commit
aa08327f28
|
@ -53,8 +53,7 @@ def SetSorting(Sorting):
|
|||
Sorting.update({i:Default[i]})
|
||||
return Sorting
|
||||
|
||||
def GetConfMenu(Conf, MarkdownExts):
|
||||
Entries = ReadConf(Conf, 'Menu')
|
||||
def GetConfMenu(Entries, MarkdownExts):
|
||||
if Entries:
|
||||
Menu, Max = [], 0
|
||||
for i in Entries:
|
||||
|
@ -64,13 +63,18 @@ def GetConfMenu(Conf, MarkdownExts):
|
|||
Menu += [[]]
|
||||
for i in Entries:
|
||||
e = Entries[i]
|
||||
if (e.startswith('<') and e.endswith('>')) or (e.startswith('[') and e.endswith(')')):
|
||||
Menu[int(i)] = markdown(e, extensions=MarkdownExts)
|
||||
else:
|
||||
#if not (e.startswith('<') or e.endswith('>') or e.startswith('[') or e.endswith(')')):
|
||||
if not ((e.startswith('<') or e.startswith('[') or e.startswith('- ')) and (e.endswith('>') or e.endswith(')') or e.endswith(' }'))):
|
||||
if not e.lower().endswith('.html'):
|
||||
e += '.html'
|
||||
Menu[int(i)] = e
|
||||
print(Menu)
|
||||
#if (e.startswith('<') and e.endswith('>')) or (e.startswith('[') and (e.endswith(')') or e.endswith('}'))):
|
||||
# Menu[int(i)] = markdown(e, extensions=MarkdownExts)
|
||||
#else:
|
||||
# if not e.lower().endswith('.html'):
|
||||
# e += '.html'
|
||||
# Menu[int(i)] = e
|
||||
#print(Menu)
|
||||
return Menu
|
||||
|
||||
def Main(Args, FeedEntries):
|
||||
|
@ -85,7 +89,7 @@ def Main(Args, FeedEntries):
|
|||
Locale = LoadLocale(SiteLang)
|
||||
MastodonURL = Args.MastodonURL if Args.MastodonURL else ''
|
||||
MastodonToken = Args.MastodonToken if Args.MastodonToken else ''
|
||||
MarkdownExts = literal_eval(Args.MarkdownExts) if Args.MarkdownExts else EvalOpt(ReadConf(SiteConf, 'Site', 'MarkdownExts')) if ReadConf(SiteConf, 'Site', 'MarkdownExts') else ['attr_list', 'def_list', 'markdown_del_ins', 'mdx_subscript', 'mdx_superscript']
|
||||
MarkdownExts = literal_eval(Args.MarkdownExts) if Args.MarkdownExts else EvalOpt(ReadConf(SiteConf, 'Site', 'MarkdownExts')) if ReadConf(SiteConf, 'Site', 'MarkdownExts') else ('attr_list', 'def_list', 'markdown_del_ins', 'mdx_subscript', 'mdx_superscript')
|
||||
|
||||
Minify = False
|
||||
if Args.Minify != None:
|
||||
|
@ -105,6 +109,12 @@ def Main(Args, FeedEntries):
|
|||
if EvalOpt(ReadConf(SiteConf, 'Site', 'AutoCategories')) == True:
|
||||
AutoCategories = True
|
||||
|
||||
Entries = ReadConf(SiteConf, 'Menu')
|
||||
if Entries:
|
||||
ConfMenu = GetConfMenu(Entries, MarkdownExts)
|
||||
else:
|
||||
ConfMenu = []
|
||||
|
||||
ResetPublic()
|
||||
|
||||
if os.path.isdir('Pages'):
|
||||
|
@ -128,7 +138,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),
|
||||
ConfMenu=ConfMenu,
|
||||
SiteName=SiteName,
|
||||
BlogName=BlogName,
|
||||
SiteTagline=SiteTagline,
|
||||
|
|
|
@ -12,3 +12,11 @@ try:
|
|||
from markdown import markdown
|
||||
except ModuleNotFoundError:
|
||||
from Libs.markdown import markdown
|
||||
|
||||
def MarkdownHTMLEscape(Str, Extensions=()): # WIP
|
||||
Text = ''
|
||||
for i,e in enumerate(Str):
|
||||
if ('mdx_subscript' or 'markdown_del_ins') in Extensions and e == '~':
|
||||
e = '~'
|
||||
Text += e
|
||||
return Text
|
||||
|
|
|
@ -69,7 +69,7 @@ def MakeCategoryLine(File, Meta):
|
|||
Categories += '[{}]({}{}.html) '.format(i, GetPathLevels(File) + 'Categories/', i)
|
||||
return Categories
|
||||
|
||||
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page', Category=None, For='Menu'):
|
||||
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page', Category=None, For='Menu', MarkdownExts=()):
|
||||
List, ToPop, LastParent = '', [], []
|
||||
IndexPages = Pages.copy()
|
||||
for e in IndexPages:
|
||||
|
@ -88,26 +88,26 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page
|
|||
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 (not Category or Category in Meta['Categories']):
|
||||
n = File.count('/') + 1
|
||||
if n > 1:
|
||||
Depth = (File.count('/') + 1) if Meta['Order'] != 'Unite' else 1
|
||||
if Depth > 1 and Meta['Order'] != 'Unite':
|
||||
CurParent = File.split('/')[:-1]
|
||||
for i,s in enumerate(CurParent):
|
||||
if LastParent != CurParent:
|
||||
LastParent = CurParent
|
||||
Levels = '- ' * (n-1+i)
|
||||
Levels = '- ' * (Depth-1+i)
|
||||
if StripExt(File).endswith('index'):
|
||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
||||
else:
|
||||
Title = CurParent[n-2+i]
|
||||
Title = CurParent[Depth-2+i]
|
||||
List += Levels + Title + '\n'
|
||||
if not (n > 1 and StripExt(File).endswith('index')):
|
||||
Levels = '- ' * n
|
||||
if not (Depth > 1 and StripExt(File).endswith('index')):
|
||||
Levels = '- ' * Depth
|
||||
if Meta['Order'] == 'Unite':
|
||||
Title = File
|
||||
else:
|
||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
||||
List += Levels + Title + '\n'
|
||||
return markdown(List)
|
||||
return markdown(MarkdownHTMLEscape(List, MarkdownExts), extensions=MarkdownExts)
|
||||
|
||||
def Preprocessor(Path, SiteRoot):
|
||||
File = ReadFile(Path)
|
||||
|
@ -338,7 +338,8 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu,
|
|||
PathPrefix=GetPathLevels('Categories/'),
|
||||
Type=Type,
|
||||
Category=Cat,
|
||||
For='Categories')
|
||||
For='Categories',
|
||||
MarkdownExts=MarkdownExts)
|
||||
|
||||
if AutoCategories:
|
||||
Dir = 'public/Categories'
|
||||
|
@ -362,13 +363,13 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu,
|
|||
Pages += [[File, Content, Titles, Meta]]
|
||||
|
||||
for i,e in enumerate(ConfMenu):
|
||||
print(e,i)
|
||||
#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(File)
|
||||
#print(ConfMenu)
|
||||
|
||||
print("[I] Writing Pages")
|
||||
for File, Content, Titles, Meta in Pages:
|
||||
|
@ -379,7 +380,8 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu,
|
|||
PathPrefix=GetPathLevels(File),
|
||||
Unite=ConfMenu,
|
||||
Type='Page',
|
||||
For='Menu')
|
||||
For='Menu',
|
||||
MarkdownExts=MarkdownExts)
|
||||
PagePath = 'public/{}.html'.format(StripExt(File))
|
||||
if File.endswith('.md'):
|
||||
Content = markdown(Content, extensions=MarkdownExts)
|
||||
|
|
Loading…
Reference in New Issue