mirror of https://gitlab.com/octtspacc/staticoso
Partial handling of relative paths for lists
This commit is contained in:
parent
657b3f8504
commit
4496d1400b
|
@ -40,6 +40,24 @@ def ResetPublic():
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def GetLevels(Path, Sub=0, AsNum=False):
|
||||||
|
n = Path.count('/')
|
||||||
|
return n if AsNum else '../' * n
|
||||||
|
|
||||||
|
def GetDeepest(Paths):
|
||||||
|
Deepest = 0
|
||||||
|
for p in Paths:
|
||||||
|
l = GetLevels(p, True)
|
||||||
|
if l > Deepest:
|
||||||
|
Deepest = l
|
||||||
|
print(Deepest)
|
||||||
|
return Deepest
|
||||||
|
|
||||||
|
def GetRelative(Path, Levels):
|
||||||
|
print(Path, Levels)
|
||||||
|
#return GetLevels(Path, Levels)
|
||||||
|
return '../' * Levels
|
||||||
|
|
||||||
def DashifyStr(s, Limit=32):
|
def DashifyStr(s, Limit=32):
|
||||||
Str, lc = '', Limit
|
Str, lc = '', Limit
|
||||||
for c in s[:Limit].replace(' ','-').replace(' ','-'):
|
for c in s[:Limit].replace(' ','-').replace(' ','-'):
|
||||||
|
@ -79,13 +97,14 @@ def GetTitleIdLine(Line, Title, Type):
|
||||||
NewLine += Line[Index+2:]
|
NewLine += Line[Index+2:]
|
||||||
return NewLine
|
return NewLine
|
||||||
|
|
||||||
def MakeListTitle(File, Meta, Titles, Prefer, SiteRoot):
|
def MakeListTitle(File, Meta, Titles, Prefer, SiteRoot, CurLevels, PathPrefix=''):
|
||||||
|
print(PathPrefix)
|
||||||
Title = GetTitle(Meta, Titles, Prefer)
|
Title = GetTitle(Meta, Titles, Prefer)
|
||||||
Link = False if Meta['Index'] == 'Unlinked' else True
|
Link = False if Meta['Index'] == 'Unlinked' else True
|
||||||
if Link:
|
if Link:
|
||||||
Title = '[{}]({})'.format(
|
Title = '[{}]({})'.format(
|
||||||
Title,
|
Title,
|
||||||
'{}{}.html'.format(SiteRoot, StripExt(File)))
|
'{}{}.html'.format(PathPrefix, StripExt(File))) #(GetRelative(File, CurLevels), StripExt(File)))
|
||||||
if Meta['Type'] == 'Post' and Meta['CreatedOn']:
|
if Meta['Type'] == 'Post' and Meta['CreatedOn']:
|
||||||
Title = '[{}] {}'.format(
|
Title = '[{}] {}'.format(
|
||||||
Meta['CreatedOn'],
|
Meta['CreatedOn'],
|
||||||
|
@ -239,7 +258,7 @@ def OrderPages(Old):
|
||||||
New.remove([])
|
New.remove([])
|
||||||
return New
|
return New
|
||||||
|
|
||||||
def GetHTMLPagesList(Pages, SiteRoot, Type='Page', Category=None):
|
def GetHTMLPagesList(Pages, SiteRoot, CurLevels, PathPrefix, Type='Page', Category=None):
|
||||||
List = ''
|
List = ''
|
||||||
ToPop = []
|
ToPop = []
|
||||||
LastParent = []
|
LastParent = []
|
||||||
|
@ -266,13 +285,13 @@ def GetHTMLPagesList(Pages, SiteRoot, Type='Page', Category=None):
|
||||||
LastParent = CurParent
|
LastParent = CurParent
|
||||||
Levels = '- ' * (n-1+i)
|
Levels = '- ' * (n-1+i)
|
||||||
if File[:-3].endswith('index.'):
|
if File[:-3].endswith('index.'):
|
||||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot)
|
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, CurLevels, PathPrefix)
|
||||||
else:
|
else:
|
||||||
Title = CurParent[n-2+i]
|
Title = CurParent[n-2+i]
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
if not (n > 1 and File[:-3].endswith('index.')):
|
if not (n > 1 and File[:-3].endswith('index.')):
|
||||||
Levels = '- ' * n
|
Levels = '- ' * n
|
||||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot)
|
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, CurLevels, PathPrefix)
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
return Markdown().convert(List)
|
return Markdown().convert(List)
|
||||||
|
|
||||||
|
@ -298,10 +317,15 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteRoot,
|
||||||
for Category in Meta['Categories']:
|
for Category in Meta['Categories']:
|
||||||
Categories.update({Category:''})
|
Categories.update({Category:''})
|
||||||
PugCompileList(Pages)
|
PugCompileList(Pages)
|
||||||
HTMLPagesList = GetHTMLPagesList(Pages, SiteRoot, 'Page')
|
print(Files)
|
||||||
for Category in Categories:
|
for Category in Categories:
|
||||||
Categories[Category] = GetHTMLPagesList(Pages, SiteRoot, 'Post', Category)
|
Categories[Category] = GetHTMLPagesList(Pages, SiteRoot, 0, '../../', 'Post', Category)
|
||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
|
CurLevels = GetLevels(File, 0, True)
|
||||||
|
PathPrefix = GetLevels(File)
|
||||||
|
print(PathPrefix)
|
||||||
|
print(File, CurLevels)
|
||||||
|
HTMLPagesList = GetHTMLPagesList(Pages, SiteRoot, CurLevels, PathPrefix, 'Page')
|
||||||
PagePath = 'public/{}.html'.format(StripExt(File))
|
PagePath = 'public/{}.html'.format(StripExt(File))
|
||||||
if File.endswith('.md'):
|
if File.endswith('.md'):
|
||||||
Content = Markdown().convert(Content)
|
Content = Markdown().convert(Content)
|
||||||
|
@ -313,7 +337,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteRoot,
|
||||||
SiteRoot)
|
SiteRoot)
|
||||||
Template = Template.replace(
|
Template = Template.replace(
|
||||||
'[HTML:Site:RelativeRoot]',
|
'[HTML:Site:RelativeRoot]',
|
||||||
'../'*File.count('/'))
|
GetLevels(File))
|
||||||
WriteFile(
|
WriteFile(
|
||||||
PagePath,
|
PagePath,
|
||||||
PatchHTML(
|
PatchHTML(
|
||||||
|
|
Loading…
Reference in New Issue