From ad8379b41967346da09123aeb684212a30929a8c Mon Sep 17 00:00:00 2001 From: octospacc Date: Thu, 21 Jul 2022 19:15:30 +0200 Subject: [PATCH] Change md exts; Start adding support for HTML pages input --- Source/Build.py | 4 ++-- Source/Modules/Site.py | 26 +++++++++++++++++++++----- Source/Modules/Utils.py | 3 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Source/Build.py b/Source/Build.py index f0a3277..eeeff52 100755 --- a/Source/Build.py +++ b/Source/Build.py @@ -37,7 +37,7 @@ def ResetPublic(): pass def DelTmp(): - for Ext in FileExtensions['Pages']: + for Ext in FileExtensions['Tmp']: for File in Path('public').rglob('*.{}'.format(Ext)): os.remove(File) for Dir in ('public', 'public.gmi'): @@ -81,7 +81,7 @@ def Main(Args, FeedEntries): Locale = LoadLocale(SiteLang) MastodonURL = Args.MastodonURL if Args.MastodonURL 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' FeedCategoryFilter = Args.FeedCategoryFilter if Args.FeedCategoryFilter else 'Blog' diff --git a/Source/Modules/Site.py b/Source/Modules/Site.py index abdb96f..b43464a 100644 --- a/Source/Modules/Site.py +++ b/Source/Modules/Site.py @@ -112,7 +112,7 @@ def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Unite=[], Type='Page def Preprocessor(Path, SiteRoot): File = ReadFile(Path) - Content, Titles, DashyTitles, Meta = '', [], [], { + Content, Titles, DashyTitles, HTMLTitlesFound, Meta = '', [], [], False, { 'Template': 'Standard.html', 'Style': '', 'Type': '', @@ -143,16 +143,32 @@ def Preprocessor(Path, SiteRoot): elif lss.startswith('Order: '): Meta['Order'] = int(lss[len('Order: '):]) 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('#'): DashTitle = DashifyTitle(l.lstrip('#'), DashyTitles) DashyTitles += [DashTitle] Titles += [l] - Content += MakeLinkableTitle(l, ls, DashTitle, 'md') + '\n' + Content += MakeLinkableTitle(None, ls, DashTitle, 'md') + '\n' else: Content += l + '\n' 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')): Content += l + '\n' else: @@ -383,7 +399,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu, PagePath = 'public/{}.html'.format(StripExt(File)) if File.endswith('.md'): Content = markdown(Content, extensions=MarkdownExts) - elif File.endswith('.pug'): + elif File.endswith(('.html','.pug')): Content = ReadFile(PagePath) HTML, ContentHTML, SlimHTML, Description, Image = PatchHTML( File=File, diff --git a/Source/Modules/Utils.py b/Source/Modules/Utils.py index 93072b0..1ac29bb 100644 --- a/Source/Modules/Utils.py +++ b/Source/Modules/Utils.py @@ -13,7 +13,8 @@ from datetime import datetime from pathlib import Path FileExtensions = { - 'Pages': ('md', 'pug')} + 'Pages': ('html', 'md', 'pug'), + 'Tmp': ('md', 'pug')} def ReadFile(p): try: