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.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 = """
|
||||
<h1>Blog Admin</h1>
|
||||
<form method="POST" action="/preview" enctype="multipart/form-data">
|
||||
return """<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="description" placeholder="Kurzbeschreibung"><br>
|
||||
<textarea name="abstract" placeholder="Abstract"></textarea><br>
|
||||
<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)
|
||||
<textarea name="article_body" placeholder="Inhalt" required></textarea><br>
|
||||
<button type="submit">Vorschau</button></form>"""
|
||||
|
||||
@app.route('/preview', methods=['POST'])
|
||||
def preview():
|
||||
data = request.form
|
||||
slug = secure_filename(data['title']).lower().replace('-', '_')
|
||||
|
||||
# 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>
|
||||
return render_template_string("""<h2>Vorschau: {{ title }}</h2>
|
||||
<form method="POST" action="/publish">
|
||||
<input type="hidden" name="slug" value="{{ slug }}">
|
||||
<input type="hidden" name="title" value="{{ title }}">
|
||||
<input type="hidden" name="content" value='{{ content }}'>
|
||||
<button type="submit">Veröffentlichen</button>
|
||||
</form>
|
||||
""", title=data['title'], content=markdown_content, slug=slug)
|
||||
<input type="hidden" name="content" value='Title: {{ title }}\n\n{{ body }}'>
|
||||
<button type="submit">Veröffentlichen</button></form>""",
|
||||
title=data['title'], body=data['article_body'], 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)
|
||||
slug, title, content = request.form.get('slug'), request.form.get('title'), request.form.get('content')
|
||||
path = os.path.join(app.config['CONTENT_FOLDER'], f"{slug}.md")
|
||||
with open(path, 'w') as f: f.write(content)
|
||||
success, msg = git_ops.commit_and_push_article(path, [], title)
|
||||
flash(msg)
|
||||
return redirect(url_for('index'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
return redirect(url_for('index'))
|
||||
Loading…
Reference in New Issue