2018-04-24 17:55:59 +02:00
|
|
|
import os
|
2018-04-24 18:17:54 +02:00
|
|
|
from glob import glob
|
|
|
|
|
2018-04-24 17:55:59 +02:00
|
|
|
from flask import Blueprint, send_from_directory, render_template, request, jsonify
|
|
|
|
from flask_httpauth import HTTPDigestAuth
|
|
|
|
import ciclostile
|
|
|
|
|
|
|
|
api = Blueprint('api', __name__)
|
|
|
|
|
|
|
|
# TODO: get from cli param
|
|
|
|
POST_DIR = "."
|
|
|
|
|
|
|
|
# auth = HTTPDigestAuth()
|
|
|
|
# users = {
|
|
|
|
# 'admin': 'password',
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
# @auth.get_password
|
|
|
|
# def get_pw(username):
|
|
|
|
# if username in users:
|
|
|
|
# return users.get(username)
|
|
|
|
# return None
|
|
|
|
|
|
|
|
|
|
|
|
# @api.route('/assets/<path:path>')
|
|
|
|
# def assets(path):
|
|
|
|
# assets_path = os.path.join(target_path, 'assets')
|
|
|
|
# return send_from_directory(assets_path, path)
|
|
|
|
|
|
|
|
|
|
|
|
# @api.route('/<string:page_name>')
|
|
|
|
# @api.route('/<string:page_name>.html')
|
|
|
|
# def page(page_name):
|
|
|
|
# return ciclostile.render(page_name, markdown_path, template_path)
|
|
|
|
|
|
|
|
|
|
|
|
# @api.route('/<string:page_name>/edit')
|
|
|
|
# @auth.login_required
|
|
|
|
# def edit(page_name):
|
|
|
|
# md_text = ciclostile.read_markdown(page_name, markdown_path)
|
|
|
|
# return render_template('edit.html', **locals())
|
|
|
|
|
|
|
|
|
|
|
|
# @api.route('/edit', methods=['POST'])
|
|
|
|
# @auth.login_required
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
|
|
|
@api.route("/posts")
|
|
|
|
def posts_list():
|
2018-04-24 18:20:47 +02:00
|
|
|
"""
|
|
|
|
Returns all .md files under POST_DIR
|
|
|
|
"""
|
2018-04-24 18:17:54 +02:00
|
|
|
posts = glob(f"{POST_DIR}/**/*.md", recursive=True)
|
|
|
|
return jsonify(posts)
|