mirror of https://gitlab.com/octtspacc/staticoso
Change md exts; Start adding support for HTML pages input
This commit is contained in:
parent
719ddefb48
commit
ad8379b419
|
@ -37,7 +37,7 @@ def ResetPublic():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def DelTmp():
|
def DelTmp():
|
||||||
for Ext in FileExtensions['Pages']:
|
for Ext in FileExtensions['Tmp']:
|
||||||
for File in Path('public').rglob('*.{}'.format(Ext)):
|
for File in Path('public').rglob('*.{}'.format(Ext)):
|
||||||
os.remove(File)
|
os.remove(File)
|
||||||
for Dir in ('public', 'public.gmi'):
|
for Dir in ('public', 'public.gmi'):
|
||||||
|
@ -81,7 +81,7 @@ def Main(Args, FeedEntries):
|
||||||
Locale = LoadLocale(SiteLang)
|
Locale = LoadLocale(SiteLang)
|
||||||
MastodonURL = Args.MastodonURL if Args.MastodonURL else ''
|
MastodonURL = Args.MastodonURL if Args.MastodonURL else ''
|
||||||
MastodonToken = Args.MastodonToken if Args.MastodonToken else ''
|
MastodonToken = Args.MastodonToken if Args.MastodonToken else ''
|
||||||
MarkdownExts = literal_eval(Args.MarkdownExts) if Args.MarkdownExts else EvalOpt(ReadConf(SiteConf, 'Site', 'MarkdownExts')) if ReadConf(SiteConf, 'Site', 'MarkdownExts') else ('attr_list', 'def_list', 'markdown_del_ins', 'md_in_html', 'mdx_subscript', 'mdx_superscript')
|
MarkdownExts = literal_eval(Args.MarkdownExts) if Args.MarkdownExts else EvalOpt(ReadConf(SiteConf, 'Site', 'MarkdownExts')) if ReadConf(SiteConf, 'Site', 'MarkdownExts') else ('attr_list', 'def_list', 'markdown_del_ins', 'md_in_html', 'mdx_subscript', 'mdx_superscript', 'tables')
|
||||||
ActivityPubTypeFilter = Args.ActivityPubTypeFilter if Args.ActivityPubTypeFilter else 'Post'
|
ActivityPubTypeFilter = Args.ActivityPubTypeFilter if Args.ActivityPubTypeFilter else 'Post'
|
||||||
FeedCategoryFilter = Args.FeedCategoryFilter if Args.FeedCategoryFilter else 'Blog'
|
FeedCategoryFilter = Args.FeedCategoryFilter if Args.FeedCategoryFilter else 'Blog'
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page
|
||||||
|
|
||||||
def Preprocessor(Path, SiteRoot):
|
def Preprocessor(Path, SiteRoot):
|
||||||
File = ReadFile(Path)
|
File = ReadFile(Path)
|
||||||
Content, Titles, DashyTitles, Meta = '', [], [], {
|
Content, Titles, DashyTitles, HTMLTitlesFound, Meta = '', [], [], False, {
|
||||||
'Template': 'Standard.html',
|
'Template': 'Standard.html',
|
||||||
'Style': '',
|
'Style': '',
|
||||||
'Type': '',
|
'Type': '',
|
||||||
|
@ -143,16 +143,32 @@ def Preprocessor(Path, SiteRoot):
|
||||||
elif lss.startswith('Order: '):
|
elif lss.startswith('Order: '):
|
||||||
Meta['Order'] = int(lss[len('Order: '):])
|
Meta['Order'] = int(lss[len('Order: '):])
|
||||||
else:
|
else:
|
||||||
if Path.endswith('.md'):
|
Headings = ('h1', 'h2', 'h3', 'h4', 'h5', 'h6')
|
||||||
|
if Path.endswith('.html') and not HTMLTitlesFound:
|
||||||
|
Soup = BeautifulSoup(File, 'html.parser')
|
||||||
|
Tags = Soup.find_all()
|
||||||
|
#for t in Soup.find_all(Headings):
|
||||||
|
for t in Tags:
|
||||||
|
if t.name in Headings:
|
||||||
|
Title = '#'*int(t.name[1]) + ' ' + str(t.text)
|
||||||
|
DashTitle = DashifyTitle(Title.lstrip('#'), DashyTitles)
|
||||||
|
DashyTitles += [DashTitle]
|
||||||
|
Titles += [Title]
|
||||||
|
t.replace_with(MakeLinkableTitle(None, Title, DashTitle, 'md'))
|
||||||
|
print(Titles)
|
||||||
|
Content = str(Soup)
|
||||||
|
print(Content)
|
||||||
|
HTMLTitlesFound = True
|
||||||
|
elif Path.endswith('.md'):
|
||||||
if ls.startswith('#'):
|
if ls.startswith('#'):
|
||||||
DashTitle = DashifyTitle(l.lstrip('#'), DashyTitles)
|
DashTitle = DashifyTitle(l.lstrip('#'), DashyTitles)
|
||||||
DashyTitles += [DashTitle]
|
DashyTitles += [DashTitle]
|
||||||
Titles += [l]
|
Titles += [l]
|
||||||
Content += MakeLinkableTitle(l, ls, DashTitle, 'md') + '\n'
|
Content += MakeLinkableTitle(None, ls, DashTitle, 'md') + '\n'
|
||||||
else:
|
else:
|
||||||
Content += l + '\n'
|
Content += l + '\n'
|
||||||
elif Path.endswith('.pug'):
|
elif Path.endswith('.pug'):
|
||||||
if ls.startswith(('h1', 'h2', 'h3', 'h4', 'h5', 'h6')):
|
if ls.startswith(Headings):
|
||||||
if ls[2:].startswith(("(class='NoTitle", '(class="NoTitle')):
|
if ls[2:].startswith(("(class='NoTitle", '(class="NoTitle')):
|
||||||
Content += l + '\n'
|
Content += l + '\n'
|
||||||
else:
|
else:
|
||||||
|
@ -383,7 +399,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu,
|
||||||
PagePath = 'public/{}.html'.format(StripExt(File))
|
PagePath = 'public/{}.html'.format(StripExt(File))
|
||||||
if File.endswith('.md'):
|
if File.endswith('.md'):
|
||||||
Content = markdown(Content, extensions=MarkdownExts)
|
Content = markdown(Content, extensions=MarkdownExts)
|
||||||
elif File.endswith('.pug'):
|
elif File.endswith(('.html','.pug')):
|
||||||
Content = ReadFile(PagePath)
|
Content = ReadFile(PagePath)
|
||||||
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML(
|
||||||
File=File,
|
File=File,
|
||||||
|
|
|
@ -13,7 +13,8 @@ from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
FileExtensions = {
|
FileExtensions = {
|
||||||
'Pages': ('md', 'pug')}
|
'Pages': ('html', 'md', 'pug'),
|
||||||
|
'Tmp': ('md', 'pug')}
|
||||||
|
|
||||||
def ReadFile(p):
|
def ReadFile(p):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue