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):
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)
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)
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:
LastParent = CurParent
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'):
Title = MakeListTitle(File, Meta, Titles, 'HTMLTitle', f.BlogName, PathPrefix)
DoneCount += 1
# It's a folder
else:
Title = CurParent[Depth-2+i]
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
def HandleTransclusions(Base:str, Caller:str, Pages:list):
Targets = []
Finding = Base
Start = Finding.find('{{')
while Start != -1:
Start = Start + 2
Finding = Finding[Start:]
Stop = Finding.find('}}')
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 Target in StrFindWrapped(Base, '{{', '}}'):
# Recursive transclusion
if Target.lower() in (Caller.lower(), StripExt(Caller.lower())):
Base = ReplWithEsc(Base, '{{' + Target + '}}', f'(staticoso - Error - Recursive transclusion of "{Target}")')
# Allowed transclusion
else:
Transed = False
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)
Transed = True
break
# No target with that name, replace with blank string
if not Transed:
Base = ReplWithEsc(Base, '{{' + Target + '}}', '')
return Base
def PatchHtml(Flags:dict, Pages:list, Page:dict, Context:dict, Snippets:dict, Locale:dict, LightRun):
@ -338,7 +338,7 @@ def FindPagesPaths():
Paths = {"Pages":[], "Posts":[]}
for Ext in FileExtensions['Pages']:
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}/')]
return Paths
@ -369,7 +369,7 @@ def MakeAutoCategories(Flags:dict, Categories):
Dir = f'{OutDir}/Categories'
for Cat in Categories:
Exists = False
for File in Path(Dir).rglob(str(Cat)+'.*'):
for File in Path(Dir).rglob(AnyCaseGlob(str(Cat)+'.*')):
Exists = True
break
if not Exists:

View File

@ -44,7 +44,10 @@ def ApplySocialIntegrations(Flags, Pages, LimitFiles, Locale):
break
#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)
WriteFile(File, Content)
FinalPaths += [File]

View File

@ -38,6 +38,12 @@ def WriteFile(p, c, m='w'):
logging.error(f"[E] Error writing file {p}")
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=''):
return str(File)[len(Truncate):]
@ -49,7 +55,7 @@ def LoadFromDir(Dir:str, Matchs:list):
Contents = {}
Matchs = SureList(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):
Name = str(File)[len(Dir)+1:]
Contents.update({Name: ReadFile(File)})
@ -89,6 +95,19 @@ def FindAllIndex(Str:str, Sub:str):
yield i
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
def ReplWithEsc(Str:str, Find:str, Repl:str, Html:bool=True, Esc:str='\\'):
New = ''

View File

@ -30,11 +30,10 @@
- Override internal HTML snippets (meta lines, page lists, redirects, ...) with config file in Templates/NAME.ini
- Specify input folder(s)
- 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
- Parity presence for [] and <> internal macro enclosure, + streamline the code for that
- 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
- Fix arguments - some are only callable from CLI and not Site.ini - make them coherent with INI categories
- Change FolderRoots arg name to CustomPaths
@ -53,4 +52,3 @@
- Exporting sites to different formats (?) (single-page HTML, PDF, EPUB, ...)
- Disable ActivityPub feed for a specific page
- 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
- [ ] Page transclusions
- [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] Lists of all pages in a site directory