|
@@ -80,13 +80,11 @@ def fix_image_paths(md_content: str, post_id: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_summary(html_body: str, max_chars: int = 200) -> str:
|
|
def extract_summary(html_body: str, max_chars: int = 200) -> str:
|
|
|
- """从 HTML 中提取纯文本摘要"""
|
|
|
|
|
|
|
+ """从 HTML 中提取纯文本摘要(返回完整文本)"""
|
|
|
soup = BeautifulSoup(html_body, "html.parser")
|
|
soup = BeautifulSoup(html_body, "html.parser")
|
|
|
text = soup.get_text()
|
|
text = soup.get_text()
|
|
|
# 去除多余空白
|
|
# 去除多余空白
|
|
|
text = re.sub(r"\s+", " ", text).strip()
|
|
text = re.sub(r"\s+", " ", text).strip()
|
|
|
- if len(text) > max_chars:
|
|
|
|
|
- return text[:max_chars] + "..."
|
|
|
|
|
return text
|
|
return text
|
|
|
|
|
|
|
|
|
|
|
|
@@ -129,10 +127,29 @@ def generate_static_page(post_id: str, title: str, html_body: str):
|
|
|
|
|
|
|
|
@app.route("/")
|
|
@app.route("/")
|
|
|
def index():
|
|
def index():
|
|
|
- """首页:瀑布流文章列表"""
|
|
|
|
|
|
|
+ """首页:瀑布流文章列表(展示完整博文)"""
|
|
|
posts = load_index()
|
|
posts = load_index()
|
|
|
# 按日期倒序排列
|
|
# 按日期倒序排列
|
|
|
posts.sort(key=lambda p: p.get("date", ""), reverse=True)
|
|
posts.sort(key=lambda p: p.get("date", ""), reverse=True)
|
|
|
|
|
+
|
|
|
|
|
+ # 为每篇文章读取生成的静态 HTML 文件内容
|
|
|
|
|
+ for post in posts:
|
|
|
|
|
+ post_id = post.get("id", "")
|
|
|
|
|
+ generated_path = config.GENERATED_FOLDER / f"{post_id}.html"
|
|
|
|
|
+ if generated_path.exists():
|
|
|
|
|
+ with open(generated_path, "r", encoding="utf-8") as f:
|
|
|
|
|
+ # 提取 <article class="post-article"> 内的内容
|
|
|
|
|
+ html_content = f.read()
|
|
|
|
|
+ # 简单提取 body 内的内容(实际项目中可用 BeautifulSoup)
|
|
|
|
|
+ start = html_content.find('<article class="post-article">')
|
|
|
|
|
+ end = html_content.find("</article>")
|
|
|
|
|
+ if start != -1 and end != -1:
|
|
|
|
|
+ post["content"] = html_content[start + len('<article class="post-article">'):end]
|
|
|
|
|
+ else:
|
|
|
|
|
+ post["content"] = ""
|
|
|
|
|
+ else:
|
|
|
|
|
+ post["content"] = ""
|
|
|
|
|
+
|
|
|
return render_template("index.html", posts=posts)
|
|
return render_template("index.html", posts=posts)
|
|
|
|
|
|
|
|
|
|
|