breadcrumb
This commit is contained in:
26
__init__.py
26
__init__.py
@@ -15,7 +15,7 @@ FLATPAGES_ROOT = abspath(cfg.pages_root)
|
||||
FLATPAGES_FP_ROOT = abspath(cfg.pages_root)
|
||||
|
||||
app = Flask(__name__)
|
||||
flatpages = FlatPages(app,'FP')
|
||||
flatpages = FlatPages(app)
|
||||
flatpages.get('index')
|
||||
freezer = Freezer(app)
|
||||
app.config.from_object(__name__)
|
||||
@@ -33,15 +33,25 @@ def get_sub_ipages(path, page):
|
||||
ps=[p for p in flatpages if p.path.startswith(path) and not ( re.match('.*index',p.path) is None) and ( re.match(ppath,p.path) is None)]
|
||||
return ps
|
||||
|
||||
|
||||
def get_bc(path, page):
|
||||
ppath=page.path
|
||||
elements=path.split('/')#[0:-1]
|
||||
elements2=['index']
|
||||
for i in range(0,len(elements)):
|
||||
elements2.append(pjoin2(elements[0:i])+u'/index')
|
||||
ps=[p for p in flatpages if p.path in elements2 ]
|
||||
return ps
|
||||
|
||||
|
||||
|
||||
def get_flatpage(path):
|
||||
is_index=False
|
||||
if path.split('/')[-1]=='index':
|
||||
if not ( re.match('.*index',path) is None):
|
||||
is_index=True
|
||||
pathi = path
|
||||
path='/'.join(path.split('/')[0:-1])
|
||||
pathi = u'{}/{}'.format(path, 'index')
|
||||
page = flatpages.get(pathi)
|
||||
if not page is None:
|
||||
is_index=True
|
||||
page = flatpages.get(pathi)
|
||||
else:
|
||||
page=flatpages.get(path)
|
||||
return (is_index, path, page)
|
||||
@@ -49,6 +59,8 @@ def get_flatpage(path):
|
||||
def pjoin (rt,pth):
|
||||
return u'{}/{}'.format(rt,pth)
|
||||
|
||||
def pjoin2 (pth):
|
||||
return u'/'.join(pth) or u''
|
||||
|
||||
def misskey(a,key):
|
||||
if not a.has_key(key):
|
||||
@@ -81,7 +93,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, pth=path)
|
||||
return render_template(page.meta["template"], ld=ld, post=page, sp=sp, spi=spi, pth=path, pagebreadcrumbs=get_bc(path,page))
|
||||
|
||||
if os.path.exists(u'{}/{}'.format(FLATPAGES_ROOT,path)):
|
||||
return send_from_directory(FLATPAGES_ROOT,path)
|
||||
|
||||
Reference in New Issue
Block a user