diff --git a/app.py b/app.py index 10c6f44..7e1b86e 100644 --- a/app.py +++ b/app.py @@ -2,90 +2,19 @@ This module is based on flask_flatpages and creates a website structure based on a file structure. By default the .md extension creates a html website """ -import logging + import sys -from flask import Flask, Blueprint,render_template, send_from_directory,jsonify, url_for - -from flatpages_index import FlatPagesIndex -import flatpages_index - -from config import Config -from envs import env import os - -# This is the directory, required for absolute file paths -package_directory = os.path.dirname(os.path.abspath(__file__)) -# Loading the config file -cfg = Config((os.path.join(package_directory, 'config.cfg'))) - -# Loading constants from config file -FLATPAGES_AUTO_RELOAD = cfg.get("FLATPAGES_AUTO_RELOAD",True) # Default can be overwritten by config cfg -FLATPAGES_EXTENSION = cfg.get("FLATPAGES_EXTENSION",".md") # Default can be overwritten by config cfg -FLATPAGES_ROOT = os.path.abspath(cfg.pages_root) - +from flaskpages import create_app # Initialize application -app = Flask(__name__) -app.config.from_object(__name__) - -app.logger.setLevel(logging.DEBUG) - -flatpages = FlatPagesIndex(app) -flatpages_index.Links.endpoint="stuff.page" -flatpages_index.Links.url=(lambda s,x: url_for(s.endpoint, name=x)) -#flatpages_index.Links.image_url=(lambda s,x: url_for('stuff.page', name=x)) -flatpages_index.Links.file_url=(lambda s,x: url_for('stuff.page', name=x)) -flatpages_index.Links.thumb_url=(lambda s,x: url_for('stuff.thumb', size=128,name=x)) - -flatpages.get('index') +app=create_app() app.logger.info('Initialize Doc App') -app.logger.info('flatpages loaded %d pages' % len(flatpages._pages)) -app.logger.info("Data directory is: %s" % flatpages.root) -app.logger.info("Url prefix;: %s" % cfg.url_prefix) -app.logger.info("Extensions: %s" % FLATPAGES_EXTENSION) - - -page_blueprint = Blueprint('stuff', __name__) - -@page_blueprint.route('/thumb//') -def thumb(size=64,name=''): - pass - -@page_blueprint.route('//') -@page_blueprint.route('/') -def page(name='index'): - page = flatpages.get(name) - - if page: - page["has_img"]=True - page.links.endpoint='stuff.page' - return render_template(page["template"], post=page, - pth=page["dirpath"]) - - if os.path.exists(os.path.join(FLATPAGES_ROOT,name)): - return send_from_directory(FLATPAGES_ROOT,name) - else: - return send_from_directory('static',name) +app.logger.debug("Url prefix;: %s" % app.config["URL_PREFIX"]) +app.logger.debug("Extensions: %s" % app.config["FLATPAGES_EXTENSION"]) -@page_blueprint.route('/.json',strict_slashes=False) -def pagejson(name='index'): - page = flatpages.get(name) - if not page is None: - page["has_img"]=False - page.links.endpoint='stuff.pagejson' -# page.links.file_url=lambda n: url_for('intern.post', name=n) - return jsonify(page=dict(page)) - - if os.path.exists(u'{}/{}'.format(FLATPAGES_ROOT,path)): - return send_from_directory(FLATPAGES_ROOT,path) - else: - return send_from_directory('static',path) - - - -app.register_blueprint(page_blueprint, url_prefix=cfg.url_prefix,static_folder='static') diff --git a/simple_sample/templates/layout.html b/simple_sample/templates/layout.html deleted file mode 100644 index e2ecacf..0000000 --- a/simple_sample/templates/layout.html +++ /dev/null @@ -1,25 +0,0 @@ -{# -*-jinja2-*- #} - - - - -
-
-
- - - {% block content %} - {% endblock %} - - -
-
-
- - - diff --git a/simple_sample/templates/page.html b/simple_sample/templates/page.html deleted file mode 100644 index 6f119a2..0000000 --- a/simple_sample/templates/page.html +++ /dev/null @@ -1,67 +0,0 @@ -{# -*-jinja2-*- #} -{% extends "layout.html" %} - -{% block content %} - -

{{post.title}}

-{{post.date}} -{% if post.links["subindexpages"] | length > 0 %} -
- Unterseiten: - -{% endif %} - -{{ post.html|safe }} - - -{% if post.links["subpages"] |length > 0 %} - -{% endif %} - -{% if post.links["files"] |length > 0 %} - -
- -Files: -
    - {% for d in post.links.files %} -
  • - {{d.title}} -
  • - {% endfor %} -
-{% endif %} - -{% if post.links["images"] |length > 0 %} - -
- -Images: -
    - {% for d in post.links.images %} -
  • - {{d.title}} -
  • - {% endfor %} -
-{% endif %} - -{% endblock %} diff --git a/simple_sample/templates/page_plain.html b/simple_sample/templates/page_plain.html deleted file mode 100644 index b728cbb..0000000 --- a/simple_sample/templates/page_plain.html +++ /dev/null @@ -1,68 +0,0 @@ -{# -*-jinja2-*- #} -{% extends "layout.html" %} - -{% block content %} - -

{{post.title}}

-{{post.date}} -{% if post.links["subindexpages"] | length > 0 %} -
- Unterseiten: - -{% endif %} - -{{ post.html|safe }} - - -{% if post.links.subpages |length > 0 %} -hi - -{% endif %} - -{% if post.links["files"] |length > 0 %} - -
- -Files: -
    - {% for d in post.links.files %} -
  • - {{d.title}} -
  • - {% endfor %} -
-{% endif %} - -{% if post.links["images"] |length > 0 %} - -
- -Images: -
    - {% for d in post.links.images %} -
  • - {{d.title}} -
  • - {% endfor %} -
-{% endif %} - -{% endblock %} diff --git a/simple_sample/templates/title.html b/simple_sample/templates/title.html deleted file mode 100644 index 6f119a2..0000000 --- a/simple_sample/templates/title.html +++ /dev/null @@ -1,67 +0,0 @@ -{# -*-jinja2-*- #} -{% extends "layout.html" %} - -{% block content %} - -

{{post.title}}

-{{post.date}} -{% if post.links["subindexpages"] | length > 0 %} -
- Unterseiten: - -{% endif %} - -{{ post.html|safe }} - - -{% if post.links["subpages"] |length > 0 %} - -{% endif %} - -{% if post.links["files"] |length > 0 %} - -
- -Files: -
    - {% for d in post.links.files %} -
  • - {{d.title}} -
  • - {% endfor %} -
-{% endif %} - -{% if post.links["images"] |length > 0 %} - -
- -Images: -
    - {% for d in post.links.images %} -
  • - {{d.title}} -
  • - {% endfor %} -
-{% endif %} - -{% endblock %} diff --git a/uwsgi.ini b/uwsgi.ini index 07e284a..ddd61d3 100644 --- a/uwsgi.ini +++ b/uwsgi.ini @@ -15,7 +15,7 @@ socket = /var/run/simple_sample.sock chmod-socket = 666 module = simple_sample callable= app -wsgi-file = run.py +wsgi-file = app.py logdate = true #logger = file:/srv/simple_sample_flat_index/uwsgi.log loglevel = debug