Handle lowercase extensions; Misc fixes

This commit is contained in:
octospacc 2023-03-14 15:21:27 +01:00
parent 784d8e4732
commit 9a98577fda
7 changed files with 45 additions and 23 deletions

View File

@ -35,10 +35,10 @@ def ResetOutDir(OutDir:str):
def DelTmp(OutDir:str): def DelTmp(OutDir:str):
for Ext in FileExtensions['Tmp']: for Ext in FileExtensions['Tmp']:
for File in Path(OutDir).rglob(f'*.{Ext}'): for File in Path(OutDir).rglob(AnyCaseGlob(f'*.{Ext}')):
os.remove(File) os.remove(File)
for Dir in (OutDir, f'{OutDir}.gmi'): for Dir in (OutDir, f'{OutDir}.gmi'):
for File in Path(Dir).rglob('*.tmp'): for File in Path(Dir).rglob(AnyCaseGlob('*.tmp')):
os.remove(File) os.remove(File)
def SetSorting(Sorting:dict): def SetSorting(Sorting:dict):

View File

@ -58,10 +58,11 @@ def GetHTMLPagesList(Flags:dict, Pages:list, PathPrefix:str, CallbackFile=None,
if LastParent != CurParent and ShowPaths: if LastParent != CurParent and ShowPaths:
LastParent = CurParent LastParent = CurParent
Levels = '.' * ((Depth-2+i) if not Flatten else 0) + ':' Levels = '.' * ((Depth-2+i) if not Flatten else 0) + ':'
# If search node endswith index, it's a page; else, it's a folder # It's a page
if StripExt(File).endswith('index'): if StripExt(File).endswith('index'):
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', f.BlogName, PathPrefix) Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', f.BlogName, PathPrefix)
DoneCount += 1 DoneCount += 1
# It's a folder
else: else:
Title = CurParent[Depth-2+i] Title = CurParent[Depth-2+i]
if SingleLine: if SingleLine:

View File

@ -49,23 +49,23 @@ def HandleDynamicParts(Flags:dict, Html:str, Snippets:dict):
# TODO: This would need to be handled either fully before or fully after after all pages' content has been transformed to HTML, else other markups end up in HTML and the page is broken # TODO: This would need to be handled either fully before or fully after after all pages' content has been transformed to HTML, else other markups end up in HTML and the page is broken
def HandleTransclusions(Base:str, Caller:str, Pages:list): def HandleTransclusions(Base:str, Caller:str, Pages:list):
Targets = [] for Target in StrFindWrapped(Base, '{{', '}}'):
Finding = Base # Recursive transclusion
Start = Finding.find('{{') if Target.lower() in (Caller.lower(), StripExt(Caller.lower())):
while Start != -1: Base = ReplWithEsc(Base, '{{' + Target + '}}', f'(staticoso - Error - Recursive transclusion of "{Target}")')
Start = Start + 2 # Allowed transclusion
Finding = Finding[Start:] else:
Stop = Finding.find('}}') Transed = False
if Stop != -1:
Targets += [Finding[:Stop]]
Start = Finding.find('{{')
for Target in Targets:
# We should show an error message on inexistant transclusion and possible recursive transclusion, as currently this doesn't handle escaped tokens
if Target != Caller:
for File, Content, _, _ in Pages: for File, Content, _, _ in Pages:
if File.lower() == Target.lower(): # Target exists, transclude its content
if Target.lower() in (File.lower(), StripExt(File.lower())):
print(Target)
Base = ReplWithEsc(Base, '{{' + Target + '}}', Content) Base = ReplWithEsc(Base, '{{' + Target + '}}', Content)
Transed = True
break break
# No target with that name, replace with blank string
if not Transed:
Base = ReplWithEsc(Base, '{{' + Target + '}}', '')
return Base return Base
def PatchHtml(Flags:dict, Pages:list, Page:dict, Context:dict, Snippets:dict, Locale:dict, LightRun): def PatchHtml(Flags:dict, Pages:list, Page:dict, Context:dict, Snippets:dict, Locale:dict, LightRun):
@ -338,7 +338,7 @@ def FindPagesPaths():
Paths = {"Pages":[], "Posts":[]} Paths = {"Pages":[], "Posts":[]}
for Ext in FileExtensions['Pages']: for Ext in FileExtensions['Pages']:
for Type in ('Pages', 'Posts'): for Type in ('Pages', 'Posts'):
for File in Path(Type).rglob(f'*.{Ext}'): for File in Path(Type).rglob(AnyCaseGlob(f'*.{Ext}')):
Paths[Type] += [FileToStr(File, f'{Type}/')] Paths[Type] += [FileToStr(File, f'{Type}/')]
return Paths return Paths
@ -369,7 +369,7 @@ def MakeAutoCategories(Flags:dict, Categories):
Dir = f'{OutDir}/Categories' Dir = f'{OutDir}/Categories'
for Cat in Categories: for Cat in Categories:
Exists = False Exists = False
for File in Path(Dir).rglob(str(Cat)+'.*'): for File in Path(Dir).rglob(AnyCaseGlob(str(Cat)+'.*')):
Exists = True Exists = True
break break
if not Exists: if not Exists:

View File

@ -44,7 +44,10 @@ def ApplySocialIntegrations(Flags, Pages, LimitFiles, Locale):
break break
#Content = ReplWithEsc(Content, '[staticoso:Comments]', Post) #Content = ReplWithEsc(Content, '[staticoso:Comments]', Post)
Content = ReplWithEsc(Content, '<staticoso:Comments>', Post) Content = ReplWithEsc(Content, '<staticoso:Comments>', Post)
# BeautifulSoup issue
Content = ReplWithEsc(Content, '<staticoso:comments>', Post) Content = ReplWithEsc(Content, '<staticoso:comments>', Post)
Content = ReplWithEsc(Content, '<staticoso:comments/>', Post)
#Content = ReplWithEsc(Content, '</staticoso:comments>', Post)
WriteFile(File, Content) WriteFile(File, Content)
FinalPaths += [File] FinalPaths += [File]

View File

@ -38,6 +38,12 @@ def WriteFile(p, c, m='w'):
logging.error(f"[E] Error writing file {p}") logging.error(f"[E] Error writing file {p}")
return False return False
def AnyCaseGlob(Glob:str):
New = ''
for c in Glob:
New += '[%s%s]' % (c.lower(), c.upper()) if c.isalpha() else c
return New
def FileToStr(File:str, Truncate:str=''): def FileToStr(File:str, Truncate:str=''):
return str(File)[len(Truncate):] return str(File)[len(Truncate):]
@ -49,7 +55,7 @@ def LoadFromDir(Dir:str, Matchs:list):
Contents = {} Contents = {}
Matchs = SureList(Matchs) Matchs = SureList(Matchs)
for Match in Matchs: for Match in Matchs:
for File in Path(Dir).rglob(Match): for File in Path(Dir).rglob(AnyCaseGlob(Match)):
if os.path.isfile(File): if os.path.isfile(File):
Name = str(File)[len(Dir)+1:] Name = str(File)[len(Dir)+1:]
Contents.update({Name: ReadFile(File)}) Contents.update({Name: ReadFile(File)})
@ -89,6 +95,19 @@ def FindAllIndex(Str:str, Sub:str):
yield i yield i
i = Str.find(Sub, i+1) i = Str.find(Sub, i+1)
# Find all occurrences of substrings wrapped inside some characters
def StrFindWrapped(Str:str, Left:str, Right:str):
Res = []
Start = Str.find(Left)
while Start != -1:
Start = Start + len(Left)
Str = Str[Start:]
Stop = Str.find(Right)
if Stop != -1:
Res += [Str[:Stop]]
Start = Str.find(Left)
return Res
# Replace substrings in a string, except when an escape char is prepended # Replace substrings in a string, except when an escape char is prepended
def ReplWithEsc(Str:str, Find:str, Repl:str, Html:bool=True, Esc:str='\\'): def ReplWithEsc(Str:str, Find:str, Repl:str, Html:bool=True, Esc:str='\\'):
New = '' New = ''

View File

@ -30,11 +30,10 @@
- Override internal HTML snippets (meta lines, page lists, redirects, ...) with config file in Templates/NAME.ini - Override internal HTML snippets (meta lines, page lists, redirects, ...) with config file in Templates/NAME.ini
- Specify input folder(s) - Specify input folder(s)
- Show page size/words/time in meta line - Show page size/words/time in meta line
- Add feed support for HTML Journal pages - Add feed support for HTML Journal pages directly, without the external tool
- Fix excess whitespace in some section/menu titles - Fix excess whitespace in some section/menu titles
- Parity presence for [] and <> internal macro enclosure, + streamline the code for that - Parity presence for [] and <> internal macro enclosure, + streamline the code for that
- Investigate a strange bug with Macros - Investigate a strange bug with Macros
- Handle file extensions with any case sensitivity, not just lowercase; currently the bulk of the issue is finding the files on disk
- Test sorting by date for files not starting with date, and dated folders - Test sorting by date for files not starting with date, and dated folders
- Fix arguments - some are only callable from CLI and not Site.ini - make them coherent with INI categories - Fix arguments - some are only callable from CLI and not Site.ini - make them coherent with INI categories
- Change FolderRoots arg name to CustomPaths - Change FolderRoots arg name to CustomPaths
@ -53,4 +52,3 @@
- Exporting sites to different formats (?) (single-page HTML, PDF, EPUB, ...) - Exporting sites to different formats (?) (single-page HTML, PDF, EPUB, ...)
- Disable ActivityPub feed for a specific page - Disable ActivityPub feed for a specific page
- Symlinks and direct copies as option instead of redirect pages - Symlinks and direct copies as option instead of redirect pages
- Automatic redirects/symlinks for making pages work without .html suffix

View File

@ -52,6 +52,7 @@ All of this is because some crucial things might be changed from one commit to a
### Features ### Features
- [ ] Page transclusions
- [x] Generation of simplified pages compliant with the [HTML Journal standard](https://journal.miso.town) - [x] Generation of simplified pages compliant with the [HTML Journal standard](https://journal.miso.town)
- [x] HTML feeds (pages with list of N most recent posts) - [x] HTML feeds (pages with list of N most recent posts)
- [x] Lists of all pages in a site directory - [x] Lists of all pages in a site directory