from flask import Flask, render_template_string, request, redirect, url_for, flash from werkzeug.utils import secure_filename import os import time from . import git_ops app = Flask(__name__) app.config['UPLOAD_FOLDER'] = os.path.join(os.getcwd(), 'downloads') app.config['CONTENT_FOLDER'] = os.path.join(os.getcwd(), 'content') app.secret_key = os.getenv('FLASK_SECRET_KEY', 'dev-key-123') # Verzeichnisse sicherstellen os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) os.makedirs(app.config['CONTENT_FOLDER'], exist_ok=True) def generate_markdown_content(data, slug): return f"""--- Title: {data['title']} Date: {time.strftime("%Y-%m-%d %H:%M")} Slug: {slug} Description: {data['description']} Abstract: {data['abstract']} PDF_Download: /downloads/{slug}.pdf Audio_Download: /downloads/{slug}.mp3 --- {data['article_body']} """ @app.route('/', methods=['GET']) def index(): form_html = """
{{ content }}
""", title=data['title'], content=markdown_content, slug=slug)
@app.route('/publish', methods=['POST'])
def publish():
slug = request.form.get('slug')
content = request.form.get('content')
title = request.form.get('title')
file_path = os.path.join(app.config['CONTENT_FOLDER'], f"{slug}.md")
with open(file_path, 'w') as f:
f.write(content)
# Git Workflow
success, msg = git_ops.commit_and_push_article(file_path, [], title)
flash(msg)
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True)