diff --git a/__init__.py b/__init__.py index e69de29..6f740f8 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1,89 @@ +import sys +from flask import Flask, render_template, send_from_directory +from flask_flatpages import FlatPages, pygments_style_defs +from flask_frozen import Freezer +from config import Config +import os +import re +from os.path import isfile, abspath + +cfg = Config(file('config.cfg')) + +FLATPAGES_AUTO_RELOAD = cfg.pages_reload +FLATPAGES_EXTENSION = '.md' +FLATPAGES_ROOT = cfg.pages_root + +app = Flask(__name__) +flatpages = FlatPages(app) +freezer = Freezer(app) +#app.config.from_object(__name__) + +def list_dir(mypath): + return [f for f in os.listdir(mypath) if isfile(os.path.join(mypath, f)) and re.match('.*\.md.*',f) is None] + +def get_sub_pages(path, page): + ppath=page.path + cc=len(path.split('/')) + return [p for p in flatpages if p.path.startswith(path) and ( re.match('.*index',p.path) is None) and len(p.path.split('/'))/') +def post(name='index'): + is_index, path, page = get_flatpage(name) + app.logger.info('render'+name) + path2 = pjoin(FLATPAGES_ROOT,path) + + if is_index == True and not page is None: + ld=list_dir(path2) + sp=get_sub_pages(path,page) + spi=get_sub_ipages(path,page) + else: + ld=[] + sp=[] + spi=[] + + 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) + + if os.path.exists(u'{}/{}'.format(FLATPAGES_ROOT,path)): + return send_from_directory(FLATPAGES_ROOT,path) + else: + return send_from_directory('static',path) + diff --git a/cont.py b/cont.py index 8fd0a67..e69de29 100644 --- a/cont.py +++ b/cont.py @@ -1,95 +0,0 @@ -import sys -from flask import Flask, render_template, send_from_directory -from flask_flatpages import FlatPages, pygments_style_defs -from flask_frozen import Freezer -from config import Config -import os -import re -from os.path import isfile, abspath - -cfg = Config(file('config.cfg')) - -FLATPAGES_AUTO_RELOAD = cfg.pages_reload -FLATPAGES_EXTENSION = '.md' -FLATPAGES_ROOT = cfg.pages_root - -app = Flask(__name__) -flatpages = FlatPages(app) -freezer = Freezer(app) -app.config.from_object(__name__) - -def list_dir(mypath): - return [f for f in os.listdir(mypath) if isfile(os.path.join(mypath, f)) and re.match('.*\.md.*',f) is None] - -def get_sub_pages(path, page): - ppath=page.path - cc=len(path.split('/')) - return [p for p in flatpages if p.path.startswith(path) and ( re.match('.*index',p.path) is None) and len(p.path.split('/'))/') -def post(name='index'): - is_index, path, page = get_flatpage(name) - - path2 = pjoin(FLATPAGES_ROOT,path) - - if is_index == True and not page is None: - ld=list_dir(path2) - sp=get_sub_pages(path,page) - spi=get_sub_ipages(path,page) - else: - ld=[] - sp=[] - spi=[] - - if not page is None: - page_defaults(page,is_index,path) - app.logger.info("Render Template"+page["template"] +"for "+path) - return render_template(page["template"], ld=ld, post=page, sp=sp, spi=spi, pth=path) - - if os.path.exists('{}/{}'.format(FLATPAGES_ROOT,path)): - return send_from_directory(FLATPAGES_ROOT,path) - else: - return send_from_directory('static',path) - - -if __name__ == "__main__": - if len(sys.argv) > 1 and sys.argv[1] == "build": - freezer.freeze() - else: - app.run(host='0.0.0.0',port=4444, debug=True)