From 95bbdef69647bbc2f247282bce77518df9fb9ef2 Mon Sep 17 00:00:00 2001 From: andis Date: Sat, 18 Feb 2017 21:27:29 +0100 Subject: [PATCH] small update --- __init__.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/__init__.py b/__init__.py index 0aae659..fc7e79d 100644 --- a/__init__.py +++ b/__init__.py @@ -6,8 +6,10 @@ from config import Config import os import re from os.path import isfile, abspath +package_directory = os.path.dirname(os.path.abspath(__file__)) -cfg = Config(file('config.cfg')) +#cfg = Config(file('./config.cfg')) +cfg = Config(file(os.path.join(package_directory, 'config.cfg'))) FLATPAGES_AUTO_RELOAD = cfg.pages_reload FLATPAGES_EXTENSION = '.md' @@ -15,7 +17,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__) @@ -30,15 +32,23 @@ def get_sub_pages(path, page): def get_sub_ipages(path, page): ppath=page.path - 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)] + cc=len(path.split('/')) + if path=="": + cc=0 + 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) and len(p.path.split('/'))<=cc+2 ] return ps def get_flatpage(path): is_index=False - if path.split('/')[-1]=='index': + if path == 'index' or path=='': is_index=True - path='/'.join(path.split('/')[0:-1]) - pathi = u'{}/{}'.format(path, 'index') + path='' + pathi='index' + else: + if path.split('/')[-1]=='index': + is_index=True + path='/'.join(path.split('/')[0:-1]) + pathi = u'{}/{}'.format(path, 'index') page = flatpages.get(pathi) if not page is None: is_index=True