Commit pending changes

This commit is contained in:
octospacc 2022-09-23 00:23:52 +02:00
parent 58d9b58fd8
commit c13be098ee
3 changed files with 32 additions and 12 deletions

View File

@ -48,7 +48,7 @@ Needed for Gemtext output support:
- [x] File name used as a title for pages without one - [x] File name used as a title for pages without one
- [ ] Custom category names in header links - [ ] Custom category names in header links
- [ ] Choosing custom name for Blog and Uncategorized categories - [ ] Choosing custom name for Blog and Uncategorized categories
- [ ] Choosing to use a template for all pages in a folder - [ ] Choosing to use a template for all pages in a folder/category
- [x] Configuration with both INI files and CLI arguments - [x] Configuration with both INI files and CLI arguments
- [ ] Category-based feeds - [ ] Category-based feeds
- [ ] Support for multi-language sites - [ ] Support for multi-language sites

View File

@ -70,14 +70,21 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page
List += Levels + Title + '\n' List += Levels + Title + '\n'
return markdown(MarkdownHTMLEscape(List, MarkdownExts), extensions=MarkdownExts) return markdown(MarkdownHTMLEscape(List, MarkdownExts), extensions=MarkdownExts)
def CheckHTMLCommentLine(Line):
if Line.startswith('<!--'):
Line = Line[4:].lstrip()
if Line.endswith('-->'):
return Line
return None
def TemplatePreprocessor(Text): def TemplatePreprocessor(Text):
Meta, MetaDefault = '', { Meta, MetaDefault = '', {
'MenuStyle': 'Default'} 'MenuStyle': 'Default'}
for l in Text.splitlines(): for l in Text.splitlines():
ll = l.lstrip() ll = l.lstrip().rstrip()
if ll.startswith('<!--'): lll = CheckHTMLCommentLine(ll)
lll = ll[4:].lstrip().rstrip() if lll:
if lll.startswith('%') and lll.endswith('-->'): if lll.startswith('%'):
Meta += lll[1:-3].lstrip().rstrip() + '\n' Meta += lll[1:-3].lstrip().rstrip() + '\n'
Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta')) Meta = dict(ReadConf(LoadConfStr('[Meta]\n' + Meta), 'Meta'))
for i in MetaDefault: for i in MetaDefault:
@ -103,15 +110,21 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
'CreatedOn': '', 'CreatedOn': '',
'EditedOn': '', 'EditedOn': '',
'Order': None} 'Order': None}
# Find all positions of '<!--', '-->', add them in a list=[[pos0,pos1,line0,line1],...]
for l in File.splitlines(): for l in File.splitlines():
ll = l.lstrip() ll = l.lstrip().rstrip()
if ll.startswith('//'): lll = CheckHTMLCommentLine(ll)
if ll.startswith('//') or lll: # Find preprocessor lines
lll = ll[2:].lstrip() lll = ll[2:].lstrip()
if lll.startswith('%'): if lll.startswith('%'):
Meta += lll[1:].lstrip() + '\n' Meta += lll[1:].lstrip() + '\n'
elif lll.startswith('$'): elif lll.startswith('$'):
Macros += lll[1:].lstrip() + '\n' Macros += lll[1:].lstrip() + '\n'
else: #if ll.startswith('<!--') and not ll.endswith('-->'): # Find comment and code blocks
# IgnoreBlocksStart += [l]
else: # Find headings
#if line in ignore block:
# continue
Headings = ('h1', 'h2', 'h3', 'h4', 'h5', 'h6') Headings = ('h1', 'h2', 'h3', 'h4', 'h5', 'h6')
if Path.endswith(FileExtensions['HTML']) and not HTMLTitlesFound: if Path.endswith(FileExtensions['HTML']) and not HTMLTitlesFound:
Soup = BeautifulSoup(File, 'html.parser') Soup = BeautifulSoup(File, 'html.parser')
@ -126,6 +139,10 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
Content = str(Soup.prettify(formatter=None)) Content = str(Soup.prettify(formatter=None))
HTMLTitlesFound = True HTMLTitlesFound = True
elif Path.endswith(FileExtensions['Markdown']): elif Path.endswith(FileExtensions['Markdown']):
lsuffix = ''
if ll.startswith(('-', '+', '*')):
lsuffix += ll[0]
ll = ll[1:].lstrip()
if ll.startswith('#') or (ll.startswith('<') and ll[1:].startswith(Headings)): if ll.startswith('#') or (ll.startswith('<') and ll[1:].startswith(Headings)):
if ll.startswith('#'): if ll.startswith('#'):
Title = ll Title = ll
@ -141,7 +158,7 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
Title = MakeLinkableTitle(None, Title, DashTitle, 'md') Title = MakeLinkableTitle(None, Title, DashTitle, 'md')
Title = Title.replace('> </', '> </') Title = Title.replace('> </', '> </')
Title = Title.replace(' </', '</') Title = Title.replace(' </', '</')
Content += Title + '\n' Content += lsuffix + Title + '\n'
else: else:
Content += l + '\n' Content += l + '\n'
elif Path.endswith('.pug'): elif Path.endswith('.pug'):
@ -172,11 +189,11 @@ def PagePreprocessor(Path, TempPath, Type, SiteTemplate, SiteRoot, GlobalMacros,
Meta['Categories'] += [j] Meta['Categories'] += [j]
else: else:
Meta.update({i:MetaDefault[i]}) Meta.update({i:MetaDefault[i]})
if Meta['Index'] in ('Default', 'Unspecified'): if Meta['Index'] in ('Default', 'Unspecified', 'Categories'):
if not Meta['Categories']: if not Meta['Categories']:
Meta['Categories'] = [CategoryUncategorized] Meta['Categories'] = [CategoryUncategorized]
if Meta['Type'] == 'Page': if Meta['Type'] == 'Page':
Meta['Index'] = 'False' Meta['Index'] = 'Categories'
elif Meta['Type'] == 'Post': elif Meta['Type'] == 'Post':
Meta['Index'] = 'True' Meta['Index'] = 'True'
if GlobalMacros: if GlobalMacros:

5
TODO
View File

@ -1,4 +1,7 @@
- Custom path for Posts - Fix title detection:
- Don't consider titles in code/comment blocks
- Consider titles in lists (title marker preceded by chars)
- Custom path for Posts and Categories
- Support for YAML header in Markdown - Support for YAML header in Markdown
- Support for HTML comment lines (<!-- -->) in any format - Support for HTML comment lines (<!-- -->) in any format
- Support for rST and AsciiDoc (?) - Support for rST and AsciiDoc (?)