This commit is contained in:
Andreas Stephanides
2017-04-22 15:48:37 +02:00
parent 817458f1d4
commit 92b237770a
2 changed files with 49 additions and 23 deletions

View File

@@ -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('/'))<cc+2) ]
if (p.path.startswith(path) and # is a subpage
( re.match('.*index',p.path) is None) and # is no index
path_depth(p.path)<path_depth(path)+2) ]
# List all index subpages of the current page i.e. all pages in subdirectories
def get_sub_ipages(path, page):
ppath=page.path
def get_sub_ipages(path):
# ppath=page.path
cc=len(path.split('/'))
if path=="":
cc=0
ppath="index"
else:
ppath=pjoin2([path,"index"])
ps=[p for p in flatpages
if (p.path.startswith(path) and # subpages of this page
not ( re.match('.*index',p.path) is None) and # only index
( re.match(ppath,p.path) is None) and # not identical page
( ppath != p.path) and # not identical page
len(p.path.split('/'))<=cc+2) ] # only one level
return ps
# breadcrumbs decompose the path
# a/b/index -> [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))

View File

@@ -3,8 +3,10 @@
<h1>{{post.title}}</h1>
{{post.date}}
{% if spi|length > 0 %}
{{ post.html|safe }}
{% if spi|length > 0 %}
<hr/>
<b id="up_head"> Unterseiten: </b>
<ul class="nav flex-column flex-sm-row " labeledby="up_head">
@@ -18,8 +20,8 @@
{% endfor %}
</ul>
{% endif %}
{% if sp|length > 0 %}
{% if sp|length > 0 %}
<ul class="nav flex-column flex-sm-row" labeledby="inf_head">
{% for d in sp %}
<li class="nav-item">
@@ -32,8 +34,9 @@
{% endfor %}
</ul>
{% endif %}
<hr/>
<b id="inf_head">Files: </b>
<b id="inf_head">Files:</b>
<ul>
{% for d in ld %}
<li>