src/dlw/admin.py aktualisiert
This commit is contained in:
parent
804b10f33e
commit
33c4f6af28
|
|
@ -9,77 +9,33 @@ app.config['UPLOAD_FOLDER'] = os.path.join(os.getcwd(), 'downloads')
|
||||||
app.config['CONTENT_FOLDER'] = os.path.join(os.getcwd(), 'content')
|
app.config['CONTENT_FOLDER'] = os.path.join(os.getcwd(), 'content')
|
||||||
app.secret_key = os.getenv('FLASK_SECRET_KEY', 'dev-key-123')
|
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['UPLOAD_FOLDER'], exist_ok=True)
|
||||||
os.makedirs(app.config['CONTENT_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'])
|
@app.route('/', methods=['GET'])
|
||||||
def index():
|
def index():
|
||||||
form_html = """
|
return """<h1>Blog Admin</h1><form method="POST" action="/preview" enctype="multipart/form-data">
|
||||||
<h1>Blog Admin</h1>
|
|
||||||
<form method="POST" action="/preview" enctype="multipart/form-data">
|
|
||||||
<input type="text" name="title" placeholder="Titel" required><br>
|
<input type="text" name="title" placeholder="Titel" required><br>
|
||||||
<input type="text" name="description" placeholder="Kurzbeschreibung"><br>
|
<textarea name="article_body" placeholder="Inhalt" required></textarea><br>
|
||||||
<textarea name="abstract" placeholder="Abstract"></textarea><br>
|
<button type="submit">Vorschau</button></form>"""
|
||||||
<textarea name="article_body" placeholder="Inhalt (Markdown)" required></textarea><br>
|
|
||||||
PDF: <input type="file" name="pdf_file"><br>
|
|
||||||
MP3: <input type="file" name="audio_file"><br>
|
|
||||||
<button type="submit">Vorschau</button>
|
|
||||||
</form>
|
|
||||||
"""
|
|
||||||
return render_template_string(form_html)
|
|
||||||
|
|
||||||
@app.route('/preview', methods=['POST'])
|
@app.route('/preview', methods=['POST'])
|
||||||
def preview():
|
def preview():
|
||||||
data = request.form
|
data = request.form
|
||||||
slug = secure_filename(data['title']).lower().replace('-', '_')
|
slug = secure_filename(data['title']).lower().replace('-', '_')
|
||||||
|
return render_template_string("""<h2>Vorschau: {{ title }}</h2>
|
||||||
# Dateien temporär speichern (vereinfacht für dieses Beispiel)
|
|
||||||
if 'pdf_file' in request.files:
|
|
||||||
request.files['pdf_file'].save(os.path.join(app.config['UPLOAD_FOLDER'], f"{slug}.pdf"))
|
|
||||||
if 'audio_file' in request.files:
|
|
||||||
request.files['audio_file'].save(os.path.join(app.config['UPLOAD_FOLDER'], f"{slug}.mp3"))
|
|
||||||
|
|
||||||
markdown_content = generate_markdown_content(data, slug)
|
|
||||||
return render_template_string("""
|
|
||||||
<h2>Vorschau: {{ title }}</h2>
|
|
||||||
<pre>{{ content }}</pre>
|
|
||||||
<form method="POST" action="/publish">
|
<form method="POST" action="/publish">
|
||||||
<input type="hidden" name="slug" value="{{ slug }}">
|
<input type="hidden" name="slug" value="{{ slug }}">
|
||||||
<input type="hidden" name="title" value="{{ title }}">
|
<input type="hidden" name="title" value="{{ title }}">
|
||||||
<input type="hidden" name="content" value='{{ content }}'>
|
<input type="hidden" name="content" value='Title: {{ title }}\n\n{{ body }}'>
|
||||||
<button type="submit">Veröffentlichen</button>
|
<button type="submit">Veröffentlichen</button></form>""",
|
||||||
</form>
|
title=data['title'], body=data['article_body'], slug=slug)
|
||||||
""", title=data['title'], content=markdown_content, slug=slug)
|
|
||||||
|
|
||||||
@app.route('/publish', methods=['POST'])
|
@app.route('/publish', methods=['POST'])
|
||||||
def publish():
|
def publish():
|
||||||
slug = request.form.get('slug')
|
slug, title, content = request.form.get('slug'), request.form.get('title'), request.form.get('content')
|
||||||
content = request.form.get('content')
|
path = os.path.join(app.config['CONTENT_FOLDER'], f"{slug}.md")
|
||||||
title = request.form.get('title')
|
with open(path, 'w') as f: f.write(content)
|
||||||
|
success, msg = git_ops.commit_and_push_article(path, [], 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)
|
flash(msg)
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run(debug=True)
|
|
||||||
Loading…
Reference in New Issue