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