diff --git a/Source/Build.py b/Source/Build.py index f512218..e3ea86f 100755 --- a/Source/Build.py +++ b/Source/Build.py @@ -105,7 +105,8 @@ def Main(Args, FeedEntries): FeedCategoryFilter = OptionChoose('Blog', Args.FeedCategoryFilter, ReadConf(SiteConf, 'Feed', 'CategoryFilter')) Minify = StringBoolChoose(False, Args.Minify, ReadConf(SiteConf, 'Site', 'Minify')) NoScripts = StringBoolChoose(False, Args.NoScripts, ReadConf(SiteConf, 'Site', 'NoScripts')) - ImgAltAndTitle = StringBoolChoose(True, Args.ImgAltAndTitle, ReadConf(SiteConf, 'Site', 'ImgAltAndTitle')) + ImgAltToTitle = StringBoolChoose(True, Args.ImgAltToTitle, ReadConf(SiteConf, 'Site', 'ImgAltToTitle')) + ImgTitleToAlt = StringBoolChoose(False, Args.ImgTitleToAlt, ReadConf(SiteConf, 'Site', 'ImgTitleToAlt')) AutoCategories = StringBoolChoose(False, Args.AutoCategories, ReadConf(SiteConf, 'Site', 'AutoCategories')) GemtextOut = StringBoolChoose(False, Args.GemtextOut, ReadConf(SiteConf, 'Site', 'GemtextOut')) GemtextHeader = Args.GemtextHeader if Args.GemtextHeader else ReadConf(SiteConf, 'Gemtext', 'Header') if ReadConf(SiteConf, 'Gemtext', 'Header') else f"# {SiteName}\n\n" if SiteName else '' @@ -156,7 +157,7 @@ def Main(Args, FeedEntries): Locale=Locale, Minify=Minify, NoScripts=NoScripts, - ImgAltAndTitle=ImgAltAndTitle, + ImgAltToTitle=ImgAltToTitle, ImgTitleToAlt=ImgTitleToAlt, Sorting=SetSorting(Sorting), MarkdownExts=MarkdownExts, AutoCategories=AutoCategories) @@ -233,7 +234,8 @@ if __name__ == '__main__': Parser.add_argument('--SiteDomain', type=str) Parser.add_argument('--Minify', type=str) Parser.add_argument('--NoScripts', type=str) - Parser.add_argument('--ImgAltAndTitle', type=str) + Parser.add_argument('--ImgAltToTitle', type=str) + Parser.add_argument('--ImgTitleToAlt', type=str) Parser.add_argument('--GemtextOut', type=str) Parser.add_argument('--GemtextHeader', type=str) Parser.add_argument('--SiteTagline', type=str) diff --git a/Source/Modules/HTML.py b/Source/Modules/HTML.py index 0818b87..e76d530 100644 --- a/Source/Modules/HTML.py +++ b/Source/Modules/HTML.py @@ -34,13 +34,13 @@ def StripTags(HTML, ToStrip): # Remove desired tags from the HTML t.replace_with('') return str(Soup) -def WriteImgAltAndTitle(HTML): # Adds alt or title attr. to which only have one of them +def WriteImgAltAndTitle(HTML, AltToTitle, TitleToAlt): # Adds alt or title attr. to which only have one of them Soup = MkSoup(HTML) Tags = Soup.find_all('img') for t in Tags: - if 'alt' in t.attrs and 'title' not in t.attrs: + if AltToTitle and 'alt' in t.attrs and 'title' not in t.attrs: t.attrs.update({'title': t.attrs['alt']}) - elif 'title' in t.attrs and 'alt' not in t.attrs: + elif TitleToAlt and 'title' in t.attrs and 'alt' not in t.attrs: t.attrs.update({'alt': t.attrs['title']}) return str(Soup) diff --git a/Source/Modules/Site.py b/Source/Modules/Site.py index 5574854..d9d7551 100644 --- a/Source/Modules/Site.py +++ b/Source/Modules/Site.py @@ -373,7 +373,7 @@ def DoMinifyHTML(HTML): convert_charrefs=True, keep_pre=True) -def MakeSite(OutputDir, TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, ConfMenu, GlobalMacros, SiteName, BlogName, SiteTagline, SiteTemplate, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, NoScripts, ImgAltAndTitle, Sorting, MarkdownExts, AutoCategories): +def MakeSite(OutputDir, TemplatesText, StaticPartsText, DynamicParts, DynamicPartsText, ConfMenu, GlobalMacros, SiteName, BlogName, SiteTagline, SiteTemplate, SiteDomain, SiteRoot, FolderRoots, SiteLang, Locale, Minify, NoScripts, ImgAltToTitle, ImgTitleToAlt, Sorting, MarkdownExts, AutoCategories): PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {} for Ext in FileExtensions['Pages']: for File in Path('Pages').rglob(f"*.{Ext}"): @@ -495,8 +495,8 @@ def MakeSite(OutputDir, TemplatesText, StaticPartsText, DynamicParts, DynamicPar HTML = DoMinifyHTML(HTML) if NoScripts: HTML = StripTags(HTML, ['script']) - if ImgAltAndTitle: - HTML = WriteImgAltAndTitle(HTML) + if ImgAltToTitle or ImgTitleToAlt: + HTML = WriteImgAltAndTitle(HTML, ImgAltToTitle, ImgTitleToAlt) WriteFile(PagePath, HTML) MadePages += [[File, Content, Titles, Meta, ContentHTML, SlimHTML, Description, Image]]