moved stuff to instance

This commit is contained in:
2021-11-19 20:34:15 +00:00
parent d7fe29fa16
commit a5d25372bc
6 changed files with 6 additions and 304 deletions

81
app.py
View File

@@ -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<int:size>/<path:name>/')
def thumb(size=64,name=''):
pass
@page_blueprint.route('/<path:name>/')
@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('/<path:name>.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')

View File

@@ -1,25 +0,0 @@
{# -*-jinja2-*- #}
<html>
<head></head>
<LINK href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<body>
<div class="container">
<div class="row">
<div class="col-12">
<nav class="breadcrumb" style="background-color: #FFF">
{% for b in post.links.breadcrumbs %}
<a href="{#url_for('page',name=b.path)#}{{b.url}}" class="breadcrumb-item">{{b.title}} </a>
{% endfor %}
</nav>
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>

View File

@@ -1,67 +0,0 @@
{# -*-jinja2-*- #}
{% extends "layout.html" %}
{% block content %}
<h1>{{post.title}}</h1>
{{post.date}}
{% if post.links["subindexpages"] | length > 0 %}
<hr/>
<b id="up_head"> Unterseiten: </b>
<ul class="nav flex-column flex-sm-row " labeledby="up_head">
{% for d in post.links["subindexpages"] %}
<li class="nav-item">
<a href="{{d.url}}" class="nav-link">
<h6> {{d.title}} <small class="text-muted">{{d.desc}} </small> </h6>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{{ post.html|safe }}
{% if post.links["subpages"] |length > 0 %}
<ul class="nav flex-column flex-sm-row" labeledby="inf_head">
{% for d in post.sub_pages %}
<li class="nav-item">
<a href="{{d.url}}" class="nav-link text-info">
<h6> {{d.title}} <small class="text-muted">{{d.desc}} </small>
</h6>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if post.links["files"] |length > 0 %}
<hr/>
<b id="inf_head">Files:</b>
<ul>
{% for d in post.links.files %}
<li>
<a href="{{d.url}}">{{d.title}} </a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if post.links["images"] |length > 0 %}
<hr/>
<b id="inf_head">Images:</b>
<ul>
{% for d in post.links.images %}
<li>
<a href="{{d.url}}">{{d.title}} </a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

View File

@@ -1,68 +0,0 @@
{# -*-jinja2-*- #}
{% extends "layout.html" %}
{% block content %}
<h1>{{post.title}}</h1>
{{post.date}}
{% if post.links["subindexpages"] | length > 0 %}
<hr/>
<b id="up_head"> Unterseiten: </b>
<ul class="nav flex-column flex-sm-row " labeledby="up_head">
{% for d in post.links["subindexpages"] %}
<li class="nav-item">
<a href="{{d.url}}" class="nav-link">
<h6> {{d.title}} <small class="text-muted">{{d.desc}} </small> </h6>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{{ post.html|safe }}
{% if post.links.subpages |length > 0 %}
hi
<ul class="nav flex-column flex-sm-row" labeledby="inf_head">
{% for d in post.links.subpages %}
<li class="nav-item">
<a href="{{d.url}}" class="nav-link text-info">
<h6> {{d.title}} <small class="text-muted">{{d.desc}} </small>
</h6>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if post.links["files"] |length > 0 %}
<hr/>
<b id="inf_head">Files:</b>
<ul>
{% for d in post.links.files %}
<li>
<a href="{{d.url}}">{{d.title}} </a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if post.links["images"] |length > 0 %}
<hr/>
<b id="inf_head">Images:</b>
<ul>
{% for d in post.links.images %}
<li>
<a href="{{d.url}}">{{d.title}} </a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

View File

@@ -1,67 +0,0 @@
{# -*-jinja2-*- #}
{% extends "layout.html" %}
{% block content %}
<h1>{{post.title}}</h1>
{{post.date}}
{% if post.links["subindexpages"] | length > 0 %}
<hr/>
<b id="up_head"> Unterseiten: </b>
<ul class="nav flex-column flex-sm-row " labeledby="up_head">
{% for d in post.links["subindexpages"] %}
<li class="nav-item">
<a href="{{d.url}}" class="nav-link">
<h6> {{d.title}} <small class="text-muted">{{d.desc}} </small> </h6>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{{ post.html|safe }}
{% if post.links["subpages"] |length > 0 %}
<ul class="nav flex-column flex-sm-row" labeledby="inf_head">
{% for d in post.sub_pages %}
<li class="nav-item">
<a href="{{d.url}}" class="nav-link text-info">
<h6> {{d.title}} <small class="text-muted">{{d.desc}} </small>
</h6>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if post.links["files"] |length > 0 %}
<hr/>
<b id="inf_head">Files:</b>
<ul>
{% for d in post.links.files %}
<li>
<a href="{{d.url}}">{{d.title}} </a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if post.links["images"] |length > 0 %}
<hr/>
<b id="inf_head">Images:</b>
<ul>
{% for d in post.links.images %}
<li>
<a href="{{d.url}}">{{d.title}} </a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

View File

@@ -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