macro allpages added and macro subpages fixed

This commit is contained in:
Dirk Alders 2024-10-07 17:19:29 +02:00
parent 305a0e0977
commit 4116e36e7c

View File

@ -72,18 +72,30 @@ class creol_page(object):
def render_text(self, request, txt): def render_text(self, request, txt):
macros = { macros = {
"subpages": self.macro_subpages "subpages": self.macro_subpages,
"allpages": self.macro_allpages,
} }
return mycreole.render(request, txt, self.attachment_path, macros=macros) return mycreole.render(request, txt, self.attachment_path, macros=macros)
def macro_allpages(self, *args, **kwargs):
kwargs["allpages"] = True
return self.macro_subpages(*args, **kwargs)
def macro_subpages(self, *args, **kwargs): def macro_subpages(self, *args, **kwargs):
allpages = kwargs.pop("allpages", False)
#
def parse_depth(s: str): def parse_depth(s: str):
try: try:
return int(s) return int(s)
except ValueError: except ValueError:
pass pass
params = kwargs.get('', '').split(",") params = kwargs.get('', '')
startname = ''
depth = parse_depth(params)
if depth is None:
params = params.split(",")
depth = parse_depth(params[0]) depth = parse_depth(params[0])
if len(params) == 2: if len(params) == 2:
startname = params[1] startname = params[1]
@ -98,9 +110,12 @@ class creol_page(object):
for path in pathlist: for path in pathlist:
contentname = self.__folder_content_filter__(os.path.basename(path)) contentname = self.__folder_content_filter__(os.path.basename(path))
# #
if contentname.startswith(self._rel_path) and contentname != self._rel_path: if (contentname.startswith(self._rel_path) or allpages) and contentname != self._rel_path:
if allpages:
name = contentname
else:
name = contentname[len(self._rel_path)+1:] name = contentname[len(self._rel_path)+1:]
if name.count('/') <= depth and name.startswith(startname): if name.count('/') < depth and name.startswith(startname):
rv += f' <li><a href="{url_page(self._request, contentname)}">{name}</a></li>\n' rv += f' <li><a href="{url_page(self._request, contentname)}">{name}</a></li>\n'
if len(rv) > 0: if len(rv) > 0:
rv = "<ul>\n" + rv + "</ul>\n" rv = "<ul>\n" + rv + "</ul>\n"