mirror of
https://gitlab.com/octtspacc/staticoso
synced 2025-03-28 17:10:18 +01:00
clean stuff
This commit is contained in:
parent
d5d4ba3f2a
commit
2d6b537315
@ -53,16 +53,15 @@ def GetLevels(Path, AsNum=False, Add=0, Sub=0):
|
|||||||
def DashifyTitle(Title, Done=[]):
|
def DashifyTitle(Title, Done=[]):
|
||||||
return UndupeStr(DashifyStr(Title), Done, '-')
|
return UndupeStr(DashifyStr(Title), Done, '-')
|
||||||
|
|
||||||
def GetTitle(Meta, Titles, Prefer='MetaTitle'):
|
def GetTitle(Meta, Titles, Prefer='MetaTitle', BlogName=None):
|
||||||
if Prefer == 'BodyTitle':
|
if Prefer == 'BodyTitle':
|
||||||
Title = Titles[0].lstrip('#') if Titles else Meta['Title'] if Meta['Title'] else 'Untitled'
|
Title = Titles[0].lstrip('#') if Titles else Meta['Title'] if Meta['Title'] else 'Untitled'
|
||||||
elif Prefer == 'MetaTitle':
|
elif Prefer == 'MetaTitle':
|
||||||
Title = Meta['Title'] if Meta['Title'] else Titles[0].lstrip('#') if Titles else 'Untitled'
|
Title = Meta['Title'] if Meta['Title'] else Titles[0].lstrip('#') if Titles else 'Untitled'
|
||||||
elif Prefer == 'HTMLTitle':
|
elif Prefer == 'HTMLTitle':
|
||||||
Title = Meta['HTMLTitle'] if Meta['HTMLTitle'] else Meta['Title'] if Meta['Title'] else Titles[0].lstrip('#') if Titles else 'Untitled'
|
Title = Meta['HTMLTitle'] if Meta['HTMLTitle'] else Meta['Title'] if Meta['Title'] else Titles[0].lstrip('#') if Titles else 'Untitled'
|
||||||
if Meta['Type'] == 'Post':
|
if Meta['Type'] == 'Post' and BlogName:
|
||||||
# TODO: This hardcodes my blog name, bad, will fix asap
|
Title += ' - ' + BlogName
|
||||||
Title += ' - blogoctt'
|
|
||||||
return Title
|
return Title
|
||||||
|
|
||||||
def GetDescription(Meta, BodyDescription, Prefer='MetaDescription'):
|
def GetDescription(Meta, BodyDescription, Prefer='MetaDescription'):
|
||||||
@ -91,8 +90,8 @@ def MakeLinkableTitle(Line, Title, DashTitle, Type):
|
|||||||
NewLine += Line[Index+2:]
|
NewLine += Line[Index+2:]
|
||||||
return NewLine
|
return NewLine
|
||||||
|
|
||||||
def MakeListTitle(File, Meta, Titles, Prefer, SiteRoot, PathPrefix=''):
|
def MakeListTitle(File, Meta, Titles, Prefer, SiteRoot, BlogName, PathPrefix=''):
|
||||||
Title = GetTitle(Meta, Titles, Prefer)
|
Title = GetTitle(Meta, Titles, Prefer, BlogName)
|
||||||
Link = False if Meta['Index'] == 'Unlinked' else True
|
Link = False if Meta['Index'] == 'Unlinked' else True
|
||||||
if Link:
|
if Link:
|
||||||
Title = '[{}]({})'.format(
|
Title = '[{}]({})'.format(
|
||||||
@ -191,7 +190,7 @@ def MakeCategoryLine(File, Meta):
|
|||||||
Categories += '[{}]({}{}.html) '.format(i, GetLevels(File) + 'Categories/', i)
|
Categories += '[{}]({}{}.html) '.format(i, GetLevels(File) + 'Categories/', i)
|
||||||
return Categories
|
return Categories
|
||||||
|
|
||||||
def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteRoot, FolderRoots, Categories, Locale):
|
def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesList, PagePath, Content, Titles, Meta, SiteRoot, SiteName, BlogName, FolderRoots, Categories, Locale):
|
||||||
HTMLTitles = FormatTitles(Titles)
|
HTMLTitles = FormatTitles(Titles)
|
||||||
BodyDescription, BodyImage = '', ''
|
BodyDescription, BodyImage = '', ''
|
||||||
Parse = BeautifulSoup(Content, 'html.parser')
|
Parse = BeautifulSoup(Content, 'html.parser')
|
||||||
@ -200,7 +199,7 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
|||||||
if not BodyImage and Parse.img and Parse.img['src']:
|
if not BodyImage and Parse.img and Parse.img['src']:
|
||||||
BodyImage = Parse.img['src']
|
BodyImage = Parse.img['src']
|
||||||
|
|
||||||
Title = GetTitle(Meta, Titles, 'MetaTitle')
|
Title = GetTitle(Meta, Titles, 'MetaTitle', BlogName)
|
||||||
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
Description = GetDescription(Meta, BodyDescription, 'MetaDescription')
|
||||||
Image = GetImage(Meta, BodyImage, 'MetaImage')
|
Image = GetImage(Meta, BodyImage, 'MetaImage')
|
||||||
|
|
||||||
@ -222,17 +221,19 @@ def PatchHTML(File, HTML, PartsText, ContextParts, ContextPartsText, HTMLPagesLi
|
|||||||
HTML = HTML.replace('[HTML:ContextPart:{}]'.format(Path), Text)
|
HTML = HTML.replace('[HTML:ContextPart:{}]'.format(Path), Text)
|
||||||
for i in PartsText:
|
for i in PartsText:
|
||||||
HTML = HTML.replace('[HTML:Part:{}]'.format(i), PartsText[i])
|
HTML = HTML.replace('[HTML:Part:{}]'.format(i), PartsText[i])
|
||||||
HTML = HTML.replace('[HTML:Site:Menu]', HTMLPagesList)
|
HTML = (HTML
|
||||||
HTML = HTML.replace('[HTML:Page:Chapters]', HTMLTitles)
|
).replace('[HTML:Site:Menu]', HTMLPagesList
|
||||||
HTML = HTML.replace('[HTML:Page:Title]', Title)
|
).replace('[HTML:Page:Chapters]', HTMLTitles
|
||||||
HTML = HTML.replace('[HTML:Page:Description]', Description)
|
).replace('[HTML:Page:Title]', Title
|
||||||
HTML = HTML.replace('[HTML:Page:Image]', Image)
|
).replace('[HTML:Page:Description]', Description
|
||||||
HTML = HTML.replace('[HTML:Page:Path]', PagePath)
|
).replace('[HTML:Page:Image]', Image
|
||||||
HTML = HTML.replace('[HTML:Page:Style]', Meta['Style'])
|
).replace('[HTML:Page:Path]', PagePath
|
||||||
HTML = HTML.replace('[HTML:Page:Content]', Content)
|
).replace('[HTML:Page:Style]', Meta['Style']
|
||||||
HTML = HTML.replace('[HTML:Page:ContentHeader]', MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta)))
|
).replace('[HTML:Page:Content]', Content
|
||||||
HTML = HTML.replace('[HTML:Site:AbsoluteRoot]', SiteRoot)
|
).replace('[HTML:Page:ContentHeader]', MakeContentHeader(Meta, Locale, MakeCategoryLine(File, Meta))
|
||||||
HTML = HTML.replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
).replace('[HTML:Site:Name]', SiteName
|
||||||
|
).replace('[HTML:Site:AbsoluteRoot]', SiteRoot
|
||||||
|
).replace('[HTML:Site:RelativeRoot]', GetLevels(PagePath))
|
||||||
for i in FolderRoots:
|
for i in FolderRoots:
|
||||||
HTML = HTML.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(i), FolderRoots[i])
|
HTML = HTML.replace('[HTML:Folder:{}:AbsoluteRoot]'.format(i), FolderRoots[i])
|
||||||
for i in Categories:
|
for i in Categories:
|
||||||
@ -277,7 +278,7 @@ def CanIndex(Index, For):
|
|||||||
else:
|
else:
|
||||||
return True if Index == For else False
|
return True if Index == For else False
|
||||||
|
|
||||||
def GetHTMLPagesList(Pages, SiteRoot, PathPrefix, Type='Page', Category=None, For='Menu'):
|
def GetHTMLPagesList(Pages, BlogName, SiteRoot, PathPrefix, Type='Page', Category=None, For='Menu'):
|
||||||
List, ToPop, LastParent = '', [], []
|
List, ToPop, LastParent = '', [], []
|
||||||
IndexPages = Pages.copy()
|
IndexPages = Pages.copy()
|
||||||
for e in IndexPages:
|
for e in IndexPages:
|
||||||
@ -292,7 +293,7 @@ def GetHTMLPagesList(Pages, SiteRoot, PathPrefix, Type='Page', Category=None, Fo
|
|||||||
if Type == 'Page':
|
if Type == 'Page':
|
||||||
IndexPages = OrderPages(IndexPages)
|
IndexPages = OrderPages(IndexPages)
|
||||||
for File, Content, Titles, Meta in IndexPages:
|
for File, Content, Titles, Meta in IndexPages:
|
||||||
if Meta['Type'] == Type and CanIndex(Meta['Index'], For) and GetTitle(Meta, Titles, Prefer='HTMLTitle') != 'Untitled' and (not Category or Category in Meta['Categories']):
|
if Meta['Type'] == Type and CanIndex(Meta['Index'], For) and GetTitle(Meta, Titles, 'HTMLTitle', BlogName) != 'Untitled' and (not Category or Category in Meta['Categories']):
|
||||||
n = File.count('/') + 1
|
n = File.count('/') + 1
|
||||||
if n > 1:
|
if n > 1:
|
||||||
CurParent = File.split('/')[:-1]
|
CurParent = File.split('/')[:-1]
|
||||||
@ -301,13 +302,13 @@ def GetHTMLPagesList(Pages, SiteRoot, PathPrefix, Type='Page', Category=None, Fo
|
|||||||
LastParent = CurParent
|
LastParent = CurParent
|
||||||
Levels = '- ' * (n-1+i)
|
Levels = '- ' * (n-1+i)
|
||||||
if StripExt(File).endswith('index'):
|
if StripExt(File).endswith('index'):
|
||||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, PathPrefix)
|
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
||||||
else:
|
else:
|
||||||
Title = CurParent[n-2+i]
|
Title = CurParent[n-2+i]
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
if not (n > 1 and StripExt(File).endswith('index')):
|
if not (n > 1 and StripExt(File).endswith('index')):
|
||||||
Levels = '- ' * n
|
Levels = '- ' * n
|
||||||
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, PathPrefix)
|
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', SiteRoot, BlogName, PathPrefix)
|
||||||
List += Levels + Title + '\n'
|
List += Levels + Title + '\n'
|
||||||
return markdown(List)
|
return markdown(List)
|
||||||
|
|
||||||
@ -336,7 +337,7 @@ def DoMinify(HTML):
|
|||||||
convert_charrefs=True,
|
convert_charrefs=True,
|
||||||
keep_pre=True)
|
keep_pre=True)
|
||||||
|
|
||||||
def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName, SiteTagline, SiteDomain, SiteRoot, FolderRoots, Locale, Minify, Sorting, MarkdownExts, AutoCategories):
|
def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName, BlogName, SiteTagline, SiteDomain, SiteRoot, FolderRoots, Locale, Minify, Sorting, MarkdownExts, AutoCategories):
|
||||||
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
PagesPaths, PostsPaths, Pages, MadePages, Categories = [], [], [], [], {}
|
||||||
for Ext in Extensions['Pages']:
|
for Ext in Extensions['Pages']:
|
||||||
for File in Path('Pages').rglob('*.{}'.format(Ext)):
|
for File in Path('Pages').rglob('*.{}'.format(Ext)):
|
||||||
@ -376,6 +377,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||||||
for Type in ('Page', 'Post'):
|
for Type in ('Page', 'Post'):
|
||||||
Categories[Cat] += GetHTMLPagesList(
|
Categories[Cat] += GetHTMLPagesList(
|
||||||
Pages=Pages,
|
Pages=Pages,
|
||||||
|
BlogName=BlogName,
|
||||||
SiteRoot=SiteRoot,
|
SiteRoot=SiteRoot,
|
||||||
PathPrefix=GetLevels('Categories/'),
|
PathPrefix=GetLevels('Categories/'),
|
||||||
Type=Type,
|
Type=Type,
|
||||||
@ -407,6 +409,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||||||
for File, Content, Titles, Meta in Pages:
|
for File, Content, Titles, Meta in Pages:
|
||||||
HTMLPagesList = GetHTMLPagesList(
|
HTMLPagesList = GetHTMLPagesList(
|
||||||
Pages=Pages,
|
Pages=Pages,
|
||||||
|
BlogName=BlogName,
|
||||||
SiteRoot=SiteRoot,
|
SiteRoot=SiteRoot,
|
||||||
PathPrefix=GetLevels(File),
|
PathPrefix=GetLevels(File),
|
||||||
Type='Page',
|
Type='Page',
|
||||||
@ -428,6 +431,8 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, SiteName,
|
|||||||
Titles=Titles,
|
Titles=Titles,
|
||||||
Meta=Meta,
|
Meta=Meta,
|
||||||
SiteRoot=SiteRoot,
|
SiteRoot=SiteRoot,
|
||||||
|
SiteName=SiteName,
|
||||||
|
BlogName=BlogName,
|
||||||
FolderRoots=FolderRoots,
|
FolderRoots=FolderRoots,
|
||||||
Categories=Categories,
|
Categories=Categories,
|
||||||
Locale=Locale)
|
Locale=Locale)
|
||||||
@ -472,6 +477,7 @@ def Main(Args, FeedEntries):
|
|||||||
#SiteMenu = GetConfMenu(SiteConf)
|
#SiteMenu = GetConfMenu(SiteConf)
|
||||||
|
|
||||||
SiteName = Args.SiteName if Args.SiteName else ReadConf(SiteConf, 'Site', 'Name') if ReadConf(SiteConf, 'Site', 'Name') else ''
|
SiteName = Args.SiteName if Args.SiteName else ReadConf(SiteConf, 'Site', 'Name') if ReadConf(SiteConf, 'Site', 'Name') else ''
|
||||||
|
BlogName = Args.BlogName if Args.BlogName else ReadConf(SiteConf, 'Site', 'BlogName') if ReadConf(SiteConf, 'Site', 'BlogName') else ''
|
||||||
SiteTagline = Args.SiteTagline if Args.SiteTagline else ReadConf(SiteConf, 'Site', 'Tagline') if ReadConf(SiteConf, 'Site', 'Tagline') else ''
|
SiteTagline = Args.SiteTagline if Args.SiteTagline else ReadConf(SiteConf, 'Site', 'Tagline') if ReadConf(SiteConf, 'Site', 'Tagline') else ''
|
||||||
SiteDomain = Args.SiteDomain.rstrip('/') if Args.SiteDomain else ReadConf(SiteConf, 'Site', 'Domain') if ReadConf(SiteConf, 'Site', 'Domain') else ''
|
SiteDomain = Args.SiteDomain.rstrip('/') if Args.SiteDomain else ReadConf(SiteConf, 'Site', 'Domain') if ReadConf(SiteConf, 'Site', 'Domain') else ''
|
||||||
SiteLang = Args.SiteLang if Args.SiteLang else ReadConf(SiteConf, 'Site', 'Lang') if ReadConf(SiteConf, 'Site', 'Lang') else 'en'
|
SiteLang = Args.SiteLang if Args.SiteLang else ReadConf(SiteConf, 'Site', 'Lang') if ReadConf(SiteConf, 'Site', 'Lang') else 'en'
|
||||||
@ -513,6 +519,7 @@ def Main(Args, FeedEntries):
|
|||||||
ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {},
|
ContextParts=literal_eval(Args.ContextParts) if Args.ContextParts else {},
|
||||||
ContextPartsText=LoadFromDir('ContextParts', '*.html'),
|
ContextPartsText=LoadFromDir('ContextParts', '*.html'),
|
||||||
SiteName=SiteName,
|
SiteName=SiteName,
|
||||||
|
BlogName=BlogName,
|
||||||
SiteTagline=SiteTagline,
|
SiteTagline=SiteTagline,
|
||||||
SiteDomain=SiteDomain,
|
SiteDomain=SiteDomain,
|
||||||
SiteRoot=Args.SiteRoot if Args.SiteRoot else '/',
|
SiteRoot=Args.SiteRoot if Args.SiteRoot else '/',
|
||||||
@ -579,6 +586,7 @@ if __name__ == '__main__':
|
|||||||
Parser.add_argument('--SiteLang', type=str)
|
Parser.add_argument('--SiteLang', type=str)
|
||||||
Parser.add_argument('--SiteRoot', type=str)
|
Parser.add_argument('--SiteRoot', type=str)
|
||||||
Parser.add_argument('--SiteName', type=str)
|
Parser.add_argument('--SiteName', type=str)
|
||||||
|
Parser.add_argument('--BlogName', type=str)
|
||||||
Parser.add_argument('--SiteDomain', type=str)
|
Parser.add_argument('--SiteDomain', type=str)
|
||||||
Parser.add_argument('--GemtextOut', type=bool)
|
Parser.add_argument('--GemtextOut', type=bool)
|
||||||
Parser.add_argument('--GemtextHeader', type=str)
|
Parser.add_argument('--GemtextHeader', type=str)
|
||||||
|
@ -63,6 +63,13 @@ def DashifyStr(s, Limit=32):
|
|||||||
Str += c
|
Str += c
|
||||||
return '-' + Str
|
return '-' + Str
|
||||||
|
|
||||||
|
# https://stackoverflow.com/a/34445090
|
||||||
|
def FindAllIndex(Str, Sub):
|
||||||
|
i = Str.find(Sub)
|
||||||
|
while i != -1:
|
||||||
|
yield i
|
||||||
|
i = Str.find(Sub, i+1)
|
||||||
|
|
||||||
def GetFullDate(Date):
|
def GetFullDate(Date):
|
||||||
if not Date:
|
if not Date:
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user