Add partial support for linked titles in right sidebar

This commit is contained in:
octospacc 2022-05-21 13:04:05 +02:00
parent 05a16d2203
commit b579c2e8ad
1 changed files with 10 additions and 12 deletions

View File

@ -6,7 +6,6 @@
| ================================= """ | ================================= """
import os import os
#import pypugjs
import shutil import shutil
from markdown import Markdown from markdown import Markdown
from pathlib import Path from pathlib import Path
@ -42,13 +41,14 @@ def DashifyStr(s, Limit=32):
return Str return Str
def FormatTitles(Titles): def FormatTitles(Titles):
HTMLTitles = '' MD = ''
for t in Titles: for t in Titles:
n = t.split(' ')[0].count('#') n = t.split(' ')[0].count('#')
Heading = '\-'*n + ' ' Heading = '\-'*n + ' '
t = t.lstrip('#') Title = t.lstrip('#')
HTMLTitles += Heading + t + ' \n' Title = '[{}](#{})'.format(Title, DashifyStr(Title))
return Markdown().convert(HTMLTitles) MDTitles += Heading + Title + ' \n'
return Markdown().convert(MDTitles)
def LoadFromDir(Dir): def LoadFromDir(Dir):
Contents = {} Contents = {}
@ -61,7 +61,8 @@ def PreProcessor(p):
File = ReadFile(p) File = ReadFile(p)
Content, Titles, Meta = '', [], { Content, Titles, Meta = '', [], {
'Template': 'Standard.html', 'Template': 'Standard.html',
'Style': ''} 'Style': '',
'Index': 'True'}}
for l in File.splitlines(): for l in File.splitlines():
ls = l.lstrip() ls = l.lstrip()
if p.endswith('.pug'): if p.endswith('.pug'):
@ -72,6 +73,8 @@ def PreProcessor(p):
Meta['Style'] += "#MainBox{Background:" + ls[len('// Background: '):] + ";} " Meta['Style'] += "#MainBox{Background:" + ls[len('// Background: '):] + ";} "
elif ls.startswith('// Style: '): elif ls.startswith('// Style: '):
Meta['Style'] += ls[len('// Style: '):] + ' ' Meta['Style'] += ls[len('// Style: '):] + ' '
elif ls.startswith('// Index: '):
Meta['Index'] += ls[len('// Index: '):] + ' '
else: else:
Content += l + '\n' Content += l + '\n'
if ls.startswith(('h1', 'h2', 'h3', 'h4', 'h5', 'h6')): if ls.startswith(('h1', 'h2', 'h3', 'h4', 'h5', 'h6')):
@ -100,17 +103,13 @@ def PugCompileList(Pages):
for File, Content, Titles, Meta in Pages: for File, Content, Titles, Meta in Pages:
Paths += '"public/' + File + '" ' Paths += '"public/' + File + '" '
os.system('pug {} > /dev/null'.format(Paths)) os.system('pug {} > /dev/null'.format(Paths))
"""
WriteFile('tmp.pug', c)
os.system('pug tmp.pug > /dev/null')
return ReadFile('tmp.html')
"""
def PatchHTML(Template, Parts, Content, Titles, Meta): def PatchHTML(Template, Parts, Content, Titles, Meta):
HTMLTitles = FormatTitles(Titles) HTMLTitles = FormatTitles(Titles)
Template = Template.replace('[HTML:Page:Title]', 'Untitled' if not Titles else Titles[0].lstrip('#')) Template = Template.replace('[HTML:Page:Title]', 'Untitled' if not Titles else Titles[0].lstrip('#'))
Template = Template.replace('[HTML:Page:Style]', Meta['Style']) Template = Template.replace('[HTML:Page:Style]', Meta['Style'])
#Template = Template.replace('[HTML:Page:LeftBox]', HTMLSiteTree)
Template = Template.replace('[HTML:Page:RightBox]', HTMLTitles) Template = Template.replace('[HTML:Page:RightBox]', HTMLTitles)
Template = Template.replace('[HTML:Page:MainBox]', Content) Template = Template.replace('[HTML:Page:MainBox]', Content)
@ -141,7 +140,6 @@ def MakeSite(Templates, Parts):
PatchHTML( PatchHTML(
Template, Parts, Template, Parts,
ReadFile('public/{}.html'.format(File.rstrip('.pug'))), ReadFile('public/{}.html'.format(File.rstrip('.pug'))),
#pypugjs.Compiler(pypugjs.Parser(Content).parse()).compile(),
Titles, Meta)) Titles, Meta))
for File in Path('Pages').rglob('*.md'): for File in Path('Pages').rglob('*.md'):
File = str(File)[len('Pages/'):] File = str(File)[len('Pages/'):]