forked from unit/ciclostile
50 lines
1.3 KiB
Python
Executable File
50 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import os
|
|
from flask import Flask, send_from_directory, render_template, request,\
|
|
redirect
|
|
import ciclostile
|
|
|
|
working_dir = os.getcwd()
|
|
|
|
target_path, template_path, markdown_path = [
|
|
os.path.join(working_dir, folder_name)
|
|
for folder_name in ['target', 'templates', 'markdown']
|
|
]
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route('/assets/<path:path>')
|
|
def assets(path):
|
|
assets_path = os.path.join(target_path, 'assets')
|
|
return send_from_directory(assets_path, path)
|
|
|
|
|
|
@app.route('/<string:page_name>')
|
|
@app.route('/<string:page_name>.html')
|
|
def page(page_name):
|
|
return ciclostile.render(page_name, markdown_path, template_path)
|
|
|
|
|
|
@app.route('/<string:page_name>/edit')
|
|
def edit(page_name):
|
|
md_text = ciclostile.read_markdown(page_name, markdown_path)
|
|
return render_template('edit.html', **locals())
|
|
|
|
|
|
@app.route('/edit', methods=['POST'])
|
|
def edit_actions():
|
|
page_name = request.form['page_name']
|
|
md_text = request.form['md_text']
|
|
|
|
if request.form['action'] == 'preview':
|
|
return ciclostile.render_from_text(md_text, template_path)
|
|
|
|
if request.form['action'] == 'save':
|
|
ciclostile.save(md_text, page_name, markdown_path)
|
|
return page(page_name)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run()
|