学生端选课进课闭环
This commit is contained in:
@@ -2,32 +2,25 @@ import os
|
||||
from flask import Blueprint, jsonify, current_app, send_from_directory
|
||||
from ..services.markdown_service import (
|
||||
convert_markdown_to_html, wrap_with_styles,
|
||||
save_html, copy_images
|
||||
save_html, copy_images, load_markdown_file
|
||||
|
||||
)
|
||||
|
||||
bp = Blueprint("markdown", __name__)
|
||||
|
||||
@bp.route("/<course_id>-<filename>-markdown", methods=["GET"])
|
||||
def convert_md(course_id, filename):
|
||||
md_file_path = os.path.join(current_app.config["MARKDOWN_DIR"], course_id, f"{filename}.md")
|
||||
|
||||
if not os.path.exists(md_file_path):
|
||||
return jsonify({"error": "Markdown file not found"}), 404
|
||||
|
||||
@bp.route("/<course_id>-<chapter_name>-<lesson_name>-markdown", methods=["GET"])
|
||||
def convert_md(course_id, chapter_name, lesson_name):
|
||||
print(f"convert_md: {course_id}, {chapter_name}, {lesson_name}")
|
||||
md_file = load_markdown_file(course_id, chapter_name, lesson_name)
|
||||
# 转换 markdown -> html
|
||||
html = convert_markdown_to_html(md_file_path)
|
||||
html = convert_markdown_to_html(md_file)
|
||||
html_with_styles = wrap_with_styles(html)
|
||||
|
||||
# 保存 HTML 文件到 static
|
||||
html_output_path = os.path.join(current_app.config["STATIC_DIR"], f"{filename}.html")
|
||||
html_output_path = os.path.join(current_app.config["STATIC_DIR"], f"{chapter_name}-{lesson_name}.html")
|
||||
save_html(html_with_styles, html_output_path)
|
||||
|
||||
# 拷贝图片资源
|
||||
image_source = os.path.join(current_app.config["MARKDOWN_DIR"], course_id, current_app.config["IMAGE_DIR"], filename)
|
||||
image_target = os.path.join(current_app.config["STATIC_DIR"], current_app.config["IMAGE_DIR"], filename)
|
||||
copy_images(image_source, image_target)
|
||||
|
||||
return jsonify({"html_url": f"/static/{filename}.html"})
|
||||
return jsonify({"html_url": f"/static/{chapter_name}-{lesson_name}.html"})
|
||||
|
||||
# 提供静态文件访问
|
||||
@bp.route("/static/<path:filename>")
|
||||
|
||||
Reference in New Issue
Block a user