You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.4 KiB
81 lines
2.4 KiB
from flask import Flask |
|
from flask import render_template, request |
|
from flask_flatpages import FlatPages |
|
import markdown2, os |
|
import random |
|
|
|
app = Flask(__name__) |
|
application = app |
|
|
|
FLATPAGES_EXTENSION = '.md' |
|
FLATPAGES_MARKDOWN_EXTENSIONS = ['extra'] |
|
FLATPAGES_AUTO_RELOAD = True |
|
|
|
app.config['APPLICATION_ROOT'] = '/lpe' |
|
|
|
app.config.from_object(__name__) |
|
BASE_DIR = os.path.abspath(os.path.dirname(__file__)) |
|
app.config.from_object(__name__) |
|
|
|
pages = FlatPages(app) |
|
pages.get('foo') |
|
|
|
def Liste_cat(): |
|
articles = (p for p in pages if 'date' in p.meta and 'type' in p.meta and p.meta['type']=='blog') |
|
catList = [] |
|
for a in articles: |
|
catList.append(a.meta['category']) |
|
catList = list(dict.fromkeys(catList)) |
|
return catList |
|
|
|
def imagelist(articlename): |
|
dir_path = os.path.dirname(os.path.realpath(articlename))+'/pages/blog/' |
|
gallery_path = os.path.join(dir_path, articlename) |
|
if os.path.exists(gallery_path): |
|
images = [f for f in os.listdir(gallery_path) if f.endswith('.jpg') or f.endswith('.jpeg') or f.endswith('.png') or f.endswith('.gif')] |
|
return gallery_path ,images |
|
else: |
|
return None, None |
|
|
|
@app.route('/') |
|
def index(): |
|
pictoPath = os.listdir('./static/img/shape/') |
|
pictoR = random.choice(pictoPath) |
|
print(pictoR) |
|
page = pages.get_or_404('home') |
|
return render_template('home.html' , page=page , picto=pictoR) |
|
|
|
@app.route('/home/') |
|
def home(): |
|
page = pages.get_or_404('home') |
|
return render_template('home.html' , page=page ) |
|
|
|
@app.route('/<path:path>/') |
|
def pageStat(path): |
|
page = pages.get_or_404(path) |
|
return render_template('home.html' , page=page ) |
|
|
|
|
|
@app.route('/pages/<path:path>') |
|
def serve_pages(path): |
|
return send_from_directory('pages', path) |
|
|
|
@app.route('/blog/') |
|
def blog(): |
|
articles = (p for p in pages if 'date' in p.meta and 'type' in p.meta and p.meta['type']=='blog') |
|
latest = sorted(articles, reverse=True, |
|
key=lambda p: p.meta['date']) |
|
catList = Liste_cat() |
|
return render_template('archive.html', articles=latest , catList=catList ) |
|
|
|
@app.route('/actu/') |
|
def actu(): |
|
articles = (p for p in pages if 'date' in p.meta and 'type' in p.meta and p.meta['type']=='actu') |
|
latest = sorted(articles, reverse=True, |
|
key=lambda p: p.meta['date']) |
|
catList = Liste_cat() |
|
return render_template('archive.html', articles=latest , catList=catList ) |
|
|
|
if __name__ == '__main__': |
|
app.run(host='0.0.0.0') |
|
|
|
|