mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-06-05 22:09:23 +02:00
Custom title choosing type
This commit is contained in:
@ -15,6 +15,9 @@ Feel free to experiment with all of this stuff!
|
|||||||
- [pug-cli >= 1.0.0-alpha6](https://npmjs.com/package/pug-cli)
|
- [pug-cli >= 1.0.0-alpha6](https://npmjs.com/package/pug-cli)
|
||||||
|
|
||||||
## Features roadmap
|
## Features roadmap
|
||||||
|
- [ ] Handle showing creation and modified date for any page
|
||||||
|
- [ ] Generation of category pages (ex. page with list of blog posts)
|
||||||
|
- [x] Custom title choosing type (HTML/Plaintext)
|
||||||
- [x] Custom page ordering
|
- [x] Custom page ordering
|
||||||
- [ ] SCSS compilation support for CSS templates
|
- [ ] SCSS compilation support for CSS templates
|
||||||
- [ ] Pug support for base templates and page side parts
|
- [ ] Pug support for base templates and page side parts
|
||||||
@ -28,3 +31,4 @@ Feel free to experiment with all of this stuff!
|
|||||||
- [x] Pug support for pages
|
- [x] Pug support for pages
|
||||||
- [x] Markdown support for pages
|
- [x] Markdown support for pages
|
||||||
- [x] First working version
|
- [x] First working version
|
||||||
|
|
||||||
|
@ -43,6 +43,14 @@ def DashifyStr(s, Limit=32):
|
|||||||
Str += c
|
Str += c
|
||||||
return '-' + Str
|
return '-' + Str
|
||||||
|
|
||||||
|
def GetTitle(Meta, Titles, Prefer='MetaTitle'):
|
||||||
|
if Prefer == 'Title':
|
||||||
|
return Titles[0].lstrip('#') if Titles else Meta['Title'] if Meta['Title'] else 'Untitled'
|
||||||
|
elif Prefer == 'MetaTitle':
|
||||||
|
return Meta['Title'] if Meta['Title'] else Titles[0].lstrip('#') if Titles else 'Untitled'
|
||||||
|
elif Prefer == 'HTMLTitle':
|
||||||
|
return Meta['HTMLTitle'] if Meta['HTMLTitle'] else Meta['Title'] if Meta['Title'] else Titles[0].lstrip('#') if Titles else 'Untitled'
|
||||||
|
|
||||||
def GetTitleIdLine(Line, Title):
|
def GetTitleIdLine(Line, Title):
|
||||||
Title = DashifyStr(Title.lstrip('#'))
|
Title = DashifyStr(Title.lstrip('#'))
|
||||||
Index = Line.find('h')
|
Index = Line.find('h')
|
||||||
@ -76,10 +84,11 @@ def PreProcessor(p, SiteRoot):
|
|||||||
'Style': '',
|
'Style': '',
|
||||||
'Index': 'True',
|
'Index': 'True',
|
||||||
'Title': '',
|
'Title': '',
|
||||||
|
'HTMLTitle': '',
|
||||||
'Order': None}
|
'Order': None}
|
||||||
for l in File.splitlines():
|
for l in File.splitlines():
|
||||||
ls = l.lstrip()
|
ls = l.lstrip()
|
||||||
if ls.startswith('//'):
|
if ls.startswith('// '):
|
||||||
if ls.startswith('// Template: '):
|
if ls.startswith('// Template: '):
|
||||||
Meta['Template'] = ls[len('// Template: '):]
|
Meta['Template'] = ls[len('// Template: '):]
|
||||||
elif ls.startswith('// Background: '):
|
elif ls.startswith('// Background: '):
|
||||||
@ -90,6 +99,8 @@ def PreProcessor(p, SiteRoot):
|
|||||||
Meta['Index'] = ls[len('// Index: '):]
|
Meta['Index'] = ls[len('// Index: '):]
|
||||||
elif ls.startswith('// Title: '):
|
elif ls.startswith('// Title: '):
|
||||||
Meta['Title'] = ls[len('// Title: '):]
|
Meta['Title'] = ls[len('// Title: '):]
|
||||||
|
elif ls.startswith('// HTMLTitle: '):
|
||||||
|
Meta['HTMLTitle'] = ls[len('// HTMLTitle: '):]
|
||||||
elif ls.startswith('// Order: '):
|
elif ls.startswith('// Order: '):
|
||||||
Meta['Order'] = int(ls[len('// Order: '):])
|
Meta['Order'] = int(ls[len('// Order: '):])
|
||||||
elif ls.startswith(('h1', 'h2', 'h3', 'h4', 'h5', 'h6')):
|
elif ls.startswith(('h1', 'h2', 'h3', 'h4', 'h5', 'h6')):
|
||||||
@ -123,7 +134,9 @@ def PatchHTML(Template, Parts, HTMLPagesList, Content, Titles, Meta, SiteRoot):
|
|||||||
Template = Template.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
Template = Template.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
||||||
Template = Template.replace('[HTML:Page:LeftBox]', HTMLPagesList)
|
Template = Template.replace('[HTML:Page:LeftBox]', HTMLPagesList)
|
||||||
Template = Template.replace('[HTML:Page:RightBox]', HTMLTitles)
|
Template = Template.replace('[HTML:Page:RightBox]', HTMLTitles)
|
||||||
Template = Template.replace('[HTML:Page:Title]', 'Untitled' if not Titles else Titles[0].lstrip('#'))
|
Template = Template.replace('[HTML:Page:Title]', GetTitle(Meta, Titles, 'MetaTitle'))
|
||||||
|
# Titles[0].lstrip('#') if Titles else 'Untitled')
|
||||||
|
# Meta['Title'] if Meta['Title'] else Titles[0].lstrip('#') if Titles else 'Untitled')
|
||||||
Template = Template.replace('[HTML:Page:Style]', Meta['Style'])
|
Template = Template.replace('[HTML:Page:Style]', Meta['Style'])
|
||||||
Template = Template.replace('[HTML:Page:MainBox]', Content)
|
Template = Template.replace('[HTML:Page:MainBox]', Content)
|
||||||
return Template
|
return Template
|
||||||
@ -134,16 +147,23 @@ def FileToStr(File, Truncate=''):
|
|||||||
def OrderPages(Old):
|
def OrderPages(Old):
|
||||||
New = []
|
New = []
|
||||||
Max = 0
|
Max = 0
|
||||||
|
#Off = 0
|
||||||
for i,e in enumerate(Old):
|
for i,e in enumerate(Old):
|
||||||
Curr = e[3]['Order']
|
Curr = e[3]['Order'] #if e[3]['Order'] else 0
|
||||||
if Curr > Max:
|
if Curr > Max:
|
||||||
Max = Curr
|
Max = Curr
|
||||||
for i in range(Max+1):
|
for i in range(Max+1):
|
||||||
New += [[]]
|
New += [[]]
|
||||||
for i,e in enumerate(Old):
|
for i,e in enumerate(Old):
|
||||||
|
#if e[3]['Order']:
|
||||||
New[e[3]['Order']] = e
|
New[e[3]['Order']] = e
|
||||||
|
#else:
|
||||||
|
#Off += 1
|
||||||
|
#New += [[e]]
|
||||||
while [] in New:
|
while [] in New:
|
||||||
New.remove([])
|
New.remove([])
|
||||||
|
#for i in New:
|
||||||
|
#print(i)
|
||||||
return New
|
return New
|
||||||
|
|
||||||
def GetHTMLPagesList(Pages, SiteRoot):
|
def GetHTMLPagesList(Pages, SiteRoot):
|
||||||
@ -151,7 +171,7 @@ def GetHTMLPagesList(Pages, SiteRoot):
|
|||||||
LastParent = []
|
LastParent = []
|
||||||
Pages = OrderPages(Pages)
|
Pages = OrderPages(Pages)
|
||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
if Meta['Index'] == 'True' and Titles:
|
if Meta['Index'] == 'True' and GetTitle(Meta, Titles, Prefer='HTMLTitle') != 'Untitled':
|
||||||
n = File.count('/') + 1
|
n = File.count('/') + 1
|
||||||
if n > 1:
|
if n > 1:
|
||||||
CurParent = File.split('/')[:-1]
|
CurParent = File.split('/')[:-1]
|
||||||
@ -159,14 +179,21 @@ def GetHTMLPagesList(Pages, SiteRoot):
|
|||||||
if LastParent != CurParent:
|
if LastParent != CurParent:
|
||||||
LastParent = CurParent
|
LastParent = CurParent
|
||||||
Levels = '- ' * (n-1+i)
|
Levels = '- ' * (n-1+i)
|
||||||
Title = CurParent[n-2+i]
|
if File[:-3].endswith('index.'):
|
||||||
|
Title = GetTitle(Meta, Titles, 'HTMLTitle')
|
||||||
|
Title = '[{}]({})'.format(
|
||||||
|
Title,
|
||||||
|
'{}{}html'.format(SiteRoot, File[:-3]))
|
||||||
|
else:
|
||||||
|
Title = CurParent[n-2+i]
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
Levels = '- ' * n
|
if not (n > 1 and File[:-3].endswith('index.')):
|
||||||
Title = Meta['Title'] if Meta['Title'] else 'Untitled' if not Titles else Titles[0].lstrip('#')
|
Levels = '- ' * n
|
||||||
Title = '[{}]({})'.format(
|
Title = GetTitle(Meta, Titles, 'HTMLTitle')
|
||||||
Title,
|
Title = '[{}]({})'.format(
|
||||||
'{}{}html'.format(SiteRoot, File[:-3]))
|
Title,
|
||||||
List += Levels + Title + '\n'
|
'{}{}html'.format(SiteRoot, File[:-3]))
|
||||||
|
List += Levels + Title + '\n'
|
||||||
return Markdown().convert(List)
|
return Markdown().convert(List)
|
||||||
|
|
||||||
def DelTmp():
|
def DelTmp():
|
||||||
@ -231,3 +258,4 @@ if __name__ == '__main__':
|
|||||||
Args = Parser.parse_args()
|
Args = Parser.parse_args()
|
||||||
|
|
||||||
Main(Args)
|
Main(Args)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user