From 92b237770af6bb179c8e2ad001ce5f8a5d2664e5 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 22 Apr 2017 15:48:37 +0200 Subject: [PATCH] fixes --- __init__.py | 63 +++++++++++++++++++++++++++++++-------------- templates/page.html | 9 ++++--- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/__init__.py b/__init__.py index b2bbd3b..e7dfa12 100644 --- a/__init__.py +++ b/__init__.py @@ -32,41 +32,58 @@ def list_dir_md(mypath): def list_dir_img(mypath): return [f for f in os.listdir(mypath) if isfile(os.path.join(mypath, f)) and re.match('.*\.jpg',f) is not None] +def path_depth(path): + p_split=path.split('/') + if path =="": + cc=0 + else: + cc=len(path.split('/')) + if p_split[-1]=='index' or p_split[-1]=='index.json' : + cc=cc-1 + return cc + # List all subpages of the current page -def get_sub_pages(path, page): - ppath=page.path - cc=len(path.split('/')) +def get_sub_pages(path): return [p for p in flatpages - if (p.path.startswith(path) and - ( re.match('.*index',p.path) is None) and - len(p.path.split('/')) [a/index a/b/index] -def get_bc(path, page): -# ppath = page.path +def get_breadcrumb_paths(path): elements = path.split('/') elements2 = ['index'] for i in range(1,len(elements)): elements2.append(pjoin2(elements[0:i])+u'/index') -# ps=[p for p in flatpages if p.path in elements2 ] - ps=[flatpages.get(p) for p in elements2] - # ps.append(['index']) - return ps + return elements2 +def get_breadcrumb_pages(paths): + pages=[flatpages.get(p) for p in paths] + return pages + +def get_paths(pages): + paths=[p.path for p in pages] + return paths + +def get_bc(path): + return get_breadcrumb_pages(get_breadcrumb_paths(path)) # load a page from a path information def get_flatpage(path): @@ -117,8 +134,8 @@ def post(name='index'): if is_index == True and not page is None: ld=list_dir_md(path2) il=list_dir_img(path2) - sp=get_sub_pages(path,page) - spi=get_sub_ipages(path,page) + sp=get_sub_pages(path) + spi=get_sub_ipages(path) else: ld=[] sp=[] @@ -127,7 +144,7 @@ def post(name='index'): if not page is None: page_defaults(page,is_index,path) app.logger.info("Render Template"+page["template"] +"for "+path) - return render_template(page.meta["template"], ld=ld, post=page, sp=sp, spi=spi, il=il, pth=path, pagebreadcrumbs=get_bc(path,page)) + return render_template(page.meta["template"], ld=ld, post=page, sp=sp, spi=spi, il=il, pth=path, pagebreadcrumbs=get_bc(path)) if os.path.exists(u'{}/{}'.format(FLATPAGES_ROOT,path)): return send_from_directory(FLATPAGES_ROOT,path) @@ -145,8 +162,8 @@ def postjson(name='index'): if is_index == True and not page is None: ld=list_dir_md(path2) il=list_dir_img(path2) - sp=get_sub_pages(path,page) - spi=get_sub_ipages(path,page) + sp=get_sub_pages(path) + spi=get_sub_ipages(path) else: ld=[] sp=[] @@ -156,6 +173,12 @@ def postjson(name='index'): page_defaults(page,is_index,path) app.logger.info("Render Template"+page["template"] +"for "+path) p=page.meta + bc=get_breadcrumb_paths(path) + p["depth"]=path_depth(path) + p["path"]=path + p["breadcrumbs"]=bc + p["subfolders"]=get_paths(spi) + p["subpages"]= [u'%s.json' % p1 for p1 in get_paths(sp)] p["text"]=page.html return jsonify(page=p) # return render_template(page.meta["template"], ld=ld, post=page, sp=sp, spi=spi, il=il, pth=path, pagebreadcrumbs=get_bc(path,page)) diff --git a/templates/page.html b/templates/page.html index 8f94e67..946e0cb 100644 --- a/templates/page.html +++ b/templates/page.html @@ -3,8 +3,10 @@

{{post.title}}

{{post.date}} -{% if spi|length > 0 %} + {{ post.html|safe }} + +{% if spi|length > 0 %}
Unterseiten: {% endif %} -{% if sp|length > 0 %} +{% if sp|length > 0 %} {% endif %} +
-Files: +Files: