fixes
This commit is contained in:
63
__init__.py
63
__init__.py
@@ -32,41 +32,58 @@ def list_dir_md(mypath):
|
|||||||
def list_dir_img(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]
|
return [f for f in os.listdir(mypath) if isfile(os.path.join(mypath, f)) and re.match('.*\.jpg',f) is not None]
|
||||||
|
|
||||||
# List all subpages of the current page
|
def path_depth(path):
|
||||||
def get_sub_pages(path, page):
|
p_split=path.split('/')
|
||||||
ppath=page.path
|
if path =="":
|
||||||
|
cc=0
|
||||||
|
else:
|
||||||
cc=len(path.split('/'))
|
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):
|
||||||
return [p for p in flatpages
|
return [p for p in flatpages
|
||||||
if (p.path.startswith(path) and
|
if (p.path.startswith(path) and # is a subpage
|
||||||
( re.match('.*index',p.path) is None) and
|
( re.match('.*index',p.path) is None) and # is no index
|
||||||
len(p.path.split('/'))<cc+2) ]
|
path_depth(p.path)<path_depth(path)+2) ]
|
||||||
|
|
||||||
# List all index subpages of the current page i.e. all pages in subdirectories
|
# List all index subpages of the current page i.e. all pages in subdirectories
|
||||||
def get_sub_ipages(path, page):
|
def get_sub_ipages(path):
|
||||||
ppath=page.path
|
# ppath=page.path
|
||||||
cc=len(path.split('/'))
|
cc=len(path.split('/'))
|
||||||
if path=="":
|
if path=="":
|
||||||
cc=0
|
cc=0
|
||||||
|
ppath="index"
|
||||||
|
else:
|
||||||
|
ppath=pjoin2([path,"index"])
|
||||||
ps=[p for p in flatpages
|
ps=[p for p in flatpages
|
||||||
if (p.path.startswith(path) and # subpages of this page
|
if (p.path.startswith(path) and # subpages of this page
|
||||||
not ( re.match('.*index',p.path) is None) and # only index
|
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
|
len(p.path.split('/'))<=cc+2) ] # only one level
|
||||||
return ps
|
return ps
|
||||||
|
|
||||||
# breadcrumbs decompose the path
|
# breadcrumbs decompose the path
|
||||||
# a/b/index -> [a/index a/b/index]
|
# a/b/index -> [a/index a/b/index]
|
||||||
def get_bc(path, page):
|
def get_breadcrumb_paths(path):
|
||||||
# ppath = page.path
|
|
||||||
elements = path.split('/')
|
elements = path.split('/')
|
||||||
elements2 = ['index']
|
elements2 = ['index']
|
||||||
for i in range(1,len(elements)):
|
for i in range(1,len(elements)):
|
||||||
elements2.append(pjoin2(elements[0:i])+u'/index')
|
elements2.append(pjoin2(elements[0:i])+u'/index')
|
||||||
# ps=[p for p in flatpages if p.path in elements2 ]
|
return elements2
|
||||||
ps=[flatpages.get(p) for p in elements2]
|
|
||||||
# ps.append(['index'])
|
|
||||||
return ps
|
|
||||||
|
|
||||||
|
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
|
# load a page from a path information
|
||||||
def get_flatpage(path):
|
def get_flatpage(path):
|
||||||
@@ -117,8 +134,8 @@ def post(name='index'):
|
|||||||
if is_index == True and not page is None:
|
if is_index == True and not page is None:
|
||||||
ld=list_dir_md(path2)
|
ld=list_dir_md(path2)
|
||||||
il=list_dir_img(path2)
|
il=list_dir_img(path2)
|
||||||
sp=get_sub_pages(path,page)
|
sp=get_sub_pages(path)
|
||||||
spi=get_sub_ipages(path,page)
|
spi=get_sub_ipages(path)
|
||||||
else:
|
else:
|
||||||
ld=[]
|
ld=[]
|
||||||
sp=[]
|
sp=[]
|
||||||
@@ -127,7 +144,7 @@ def post(name='index'):
|
|||||||
if not page is None:
|
if not page is None:
|
||||||
page_defaults(page,is_index,path)
|
page_defaults(page,is_index,path)
|
||||||
app.logger.info("Render Template"+page["template"] +"for "+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)):
|
if os.path.exists(u'{}/{}'.format(FLATPAGES_ROOT,path)):
|
||||||
return send_from_directory(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:
|
if is_index == True and not page is None:
|
||||||
ld=list_dir_md(path2)
|
ld=list_dir_md(path2)
|
||||||
il=list_dir_img(path2)
|
il=list_dir_img(path2)
|
||||||
sp=get_sub_pages(path,page)
|
sp=get_sub_pages(path)
|
||||||
spi=get_sub_ipages(path,page)
|
spi=get_sub_ipages(path)
|
||||||
else:
|
else:
|
||||||
ld=[]
|
ld=[]
|
||||||
sp=[]
|
sp=[]
|
||||||
@@ -156,6 +173,12 @@ def postjson(name='index'):
|
|||||||
page_defaults(page,is_index,path)
|
page_defaults(page,is_index,path)
|
||||||
app.logger.info("Render Template"+page["template"] +"for "+path)
|
app.logger.info("Render Template"+page["template"] +"for "+path)
|
||||||
p=page.meta
|
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
|
p["text"]=page.html
|
||||||
return jsonify(page=p)
|
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))
|
# return render_template(page.meta["template"], ld=ld, post=page, sp=sp, spi=spi, il=il, pth=path, pagebreadcrumbs=get_bc(path,page))
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
<h1>{{post.title}}</h1>
|
<h1>{{post.title}}</h1>
|
||||||
{{post.date}}
|
{{post.date}}
|
||||||
{% if spi|length > 0 %}
|
|
||||||
{{ post.html|safe }}
|
{{ post.html|safe }}
|
||||||
|
|
||||||
|
{% if spi|length > 0 %}
|
||||||
<hr/>
|
<hr/>
|
||||||
<b id="up_head"> Unterseiten: </b>
|
<b id="up_head"> Unterseiten: </b>
|
||||||
<ul class="nav flex-column flex-sm-row " labeledby="up_head">
|
<ul class="nav flex-column flex-sm-row " labeledby="up_head">
|
||||||
@@ -18,8 +20,8 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if sp|length > 0 %}
|
|
||||||
|
|
||||||
|
{% if sp|length > 0 %}
|
||||||
<ul class="nav flex-column flex-sm-row" labeledby="inf_head">
|
<ul class="nav flex-column flex-sm-row" labeledby="inf_head">
|
||||||
{% for d in sp %}
|
{% for d in sp %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
@@ -32,8 +34,9 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
<b id="inf_head">Files: </b>
|
<b id="inf_head">Files:</b>
|
||||||
<ul>
|
<ul>
|
||||||
{% for d in ld %}
|
{% for d in ld %}
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
Reference in New Issue
Block a user