mirror of https://gitlab.com/octtspacc/staticoso
Add md extensions, Fix page list generation
This commit is contained in:
parent
337f3330d7
commit
9249fa359a
|
@ -122,7 +122,7 @@ def LoadFromDir(Dir, Rglob):
|
|||
Contents.update({File: ReadFile('{}/{}'.format(Dir, File))})
|
||||
return Contents
|
||||
|
||||
def PreProcessor(Path, SiteRoot):
|
||||
def Preprocessor(Path, SiteRoot):
|
||||
File = ReadFile(Path)
|
||||
Content, Titles, DashyTitles, Meta = '', [], [], {
|
||||
'Template': 'Standard.html',
|
||||
|
@ -309,12 +309,12 @@ def GetHTMLPagesList(Pages, SiteRoot, PathPrefix, Type='Page', Category=None, Fo
|
|||
if LastParent != CurParent:
|
||||
LastParent = CurParent
|
||||
Levels = '- ' * (n-1+i)
|
||||
if File[:-3].endswith('index.'):
|
||||
if StripExt(File).endswith('index'):
|
||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, PathPrefix)
|
||||
else:
|
||||
Title = CurParent[n-2+i]
|
||||
List += Levels + Title + '\n'
|
||||
if not (n > 1 and File[:-3].endswith('index.')):
|
||||
if not (n > 1 and StripExt(File).endswith('index')):
|
||||
Levels = '- ' * n
|
||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, PathPrefix)
|
||||
List += Levels + Title + '\n'
|
||||
|
@ -362,13 +362,14 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||
elif Sorting['Posts'] == 'Inverse':
|
||||
PostsPaths = RevSort(PostsPaths)
|
||||
|
||||
print("[I] Preprocessing Source Pages")
|
||||
for Type in ['Page', 'Post']:
|
||||
if Type == 'Page':
|
||||
Files = PagesPaths
|
||||
elif Type == 'Post':
|
||||
Files = PostsPaths
|
||||
for File in Files:
|
||||
Content, Titles, Meta = PreProcessor('{}s/{}'.format(Type, File), SiteRoot)
|
||||
Content, Titles, Meta = Preprocessor('{}s/{}'.format(Type, File), SiteRoot)
|
||||
if Type != 'Page':
|
||||
File = Type + 's/' + File
|
||||
if not Meta['Type']:
|
||||
|
@ -378,22 +379,25 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||
Categories.update({Category:''})
|
||||
PugCompileList(Pages)
|
||||
|
||||
for Category in Categories:
|
||||
Categories[Category] = GetHTMLPagesList(
|
||||
Pages=Pages,
|
||||
SiteRoot=SiteRoot,
|
||||
PathPrefix=GetLevels(Reserved['Categories']), # This hardcodes paths, TODO make it somehow guess the path for every page containing the [HTML:Category] macro
|
||||
Type='Page',
|
||||
Category=Category,
|
||||
For='Categories')
|
||||
Categories[Category] += GetHTMLPagesList(
|
||||
Pages=Pages,
|
||||
SiteRoot=SiteRoot,
|
||||
PathPrefix=GetLevels(Reserved['Categories']), # This hardcodes paths, TODO make it somehow guess the path for every page containing the [HTML:Category] macro
|
||||
Type='Post',
|
||||
Category=Category,
|
||||
For='Categories')
|
||||
if Categories:
|
||||
print("[I] Generating Category Lists")
|
||||
for Category in Categories:
|
||||
Categories[Category] = GetHTMLPagesList(
|
||||
Pages=Pages,
|
||||
SiteRoot=SiteRoot,
|
||||
PathPrefix=GetLevels(Reserved['Categories']), # This hardcodes paths, TODO make it somehow guess the path for every page containing the [HTML:Category] macro
|
||||
Type='Page',
|
||||
Category=Category,
|
||||
For='Categories')
|
||||
Categories[Category] += GetHTMLPagesList(
|
||||
Pages=Pages,
|
||||
SiteRoot=SiteRoot,
|
||||
PathPrefix=GetLevels(Reserved['Categories']), # This hardcodes paths, TODO make it somehow guess the path for every page containing the [HTML:Category] macro
|
||||
Type='Post',
|
||||
Category=Category,
|
||||
For='Categories')
|
||||
|
||||
print("[I] Writing Pages")
|
||||
for File, Content, Titles, Meta in Pages:
|
||||
HTMLPagesList = GetHTMLPagesList(
|
||||
Pages=Pages,
|
||||
|
@ -480,7 +484,7 @@ def Main(Args, FeedEntries):
|
|||
Locale=Locale,
|
||||
Minify=Args.Minify if Args.Minify else 'None',
|
||||
Sorting=SetSorting(literal_eval(Args.ContextParts) if Args.ContextParts else {}),
|
||||
MarkdownExts=literal_eval(Args.MarkdownExts) if Args.MarkdownExts else ['attr_list'])
|
||||
MarkdownExts=literal_eval(Args.MarkdownExts) if Args.MarkdownExts else ['attr_list', 'def_list', 'markdown_del_ins', 'mdx_subscript', 'mdx_superscript'])
|
||||
|
||||
if FeedEntries != 0:
|
||||
print("[I] Generating Feeds")
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
"""
|
||||
Copyright 2011, 2012 The Active Archives contributors
|
||||
Copyright 2011, 2012 Alexandre Leray
|
||||
Copyright 2020 Honza Javorek <https://honzajavorek.cz>
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the <organization> nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
|
||||
from . import Extension
|
||||
from ..inlinepatterns import SimpleTagInlineProcessor
|
||||
|
||||
class DelInsExtension(Extension):
|
||||
def extendMarkdown(self, md):
|
||||
del_proc = SimpleTagInlineProcessor(r'(\~\~)(.+?)(\~\~)', 'del')
|
||||
md.inlinePatterns.register(del_proc, 'del', 200)
|
||||
|
||||
ins_proc = SimpleTagInlineProcessor(r'(\+\+)(.+?)(\+\+)', 'ins')
|
||||
md.inlinePatterns.register(ins_proc, 'ins', 200)
|
||||
|
||||
def makeExtension(**kwargs):
|
||||
return DelInsExtension(**kwargs)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testfile('README.md')
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Markdown Subscript Extension
|
||||
|
||||
Extends the Python-Markdown library to support subscript text.
|
||||
|
||||
Given the text:
|
||||
The molecular composition of water is H~2~O.
|
||||
Will output:
|
||||
<p>The molecular composition of water is H<sub>2</sub>O.</p>
|
||||
|
||||
:website: https://github.com/jambonrose/markdown_subscript_extension
|
||||
:copyright: Copyright 2014-2018 Andrew Pinkham
|
||||
:license: Simplified BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from . import Extension
|
||||
from ..inlinepatterns import SimpleTagPattern
|
||||
|
||||
# match ~, at least one character that is not ~, and ~ again
|
||||
SUBSCRIPT_RE = r"(\~)([^\~]+)\2"
|
||||
|
||||
|
||||
def makeExtension(*args, **kwargs): # noqa: N802
|
||||
"""Inform Markdown of the existence of the extension."""
|
||||
return SubscriptExtension(*args, **kwargs)
|
||||
|
||||
|
||||
class SubscriptExtension(Extension):
|
||||
"""Extension: text between ~ characters will be subscripted."""
|
||||
|
||||
def extendMarkdown(self, md, md_globals): # noqa: N802
|
||||
"""Insert 'subscript' pattern before 'not_strong' pattern."""
|
||||
md.inlinePatterns.add(
|
||||
"subscript", SimpleTagPattern(SUBSCRIPT_RE, "sub"), "<not_strong"
|
||||
)
|
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Markdown Superscript Extension
|
||||
|
||||
Extends the Python-Markdown library to support superscript text.
|
||||
|
||||
Given the text:
|
||||
2^10^ is 1024.
|
||||
Will output:
|
||||
2<sup>10</sup> is 1024.
|
||||
|
||||
:website: https://github.com/jambonrose/markdown_superscript_extension
|
||||
:copyright: Copyright 2014-2018 Andrew Pinkham
|
||||
:license: Simplified BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from . import Extension
|
||||
from ..inlinepatterns import SimpleTagPattern
|
||||
|
||||
# match ^, at least one character that is not ^, and ^ again
|
||||
SUPERSCRIPT_RE = r"(\^)([^\^]+)\2"
|
||||
|
||||
|
||||
def makeExtension(*args, **kwargs): # noqa: N802
|
||||
"""Inform Markdown of the existence of the extension."""
|
||||
return SuperscriptExtension(*args, **kwargs)
|
||||
|
||||
|
||||
class SuperscriptExtension(Extension):
|
||||
"""Extension: text between ^ characters will be superscripted."""
|
||||
|
||||
def extendMarkdown(self, md, md_globals): # noqa: N802
|
||||
"""Insert 'superscript' pattern before 'not_strong' pattern."""
|
||||
md.inlinePatterns.add(
|
||||
"superscript",
|
||||
SimpleTagPattern(SUPERSCRIPT_RE, "sup"),
|
||||
"<not_strong",
|
||||
)
|
Loading…
Reference in New Issue