-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jiangyuan Li
authored and
Jiangyuan Li
committed
Nov 23, 2024
1 parent
67dcff3
commit 3ecc4c2
Showing
9 changed files
with
35 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,32 @@ | ||
from flask import Flask, render_template, abort | ||
import os | ||
from flask import Flask, render_template | ||
from flask_frozen import Freezer | ||
from markupsafe import Markup | ||
|
||
app = Flask(__name__) | ||
freezer = Freezer(app) | ||
|
||
# Base route for the homepage | ||
|
||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
|
||
@app.route("/blog") | ||
def blog(): | ||
posts = [] | ||
for filename in os.listdir("posts"): | ||
if filename.endswith(".html"): | ||
with open(os.path.join("posts", filename)) as f: | ||
content = f.read() | ||
title = os.path.splitext(filename)[0].replace("-", " ").title() | ||
posts.append({"title": title, "content": Markup(content)}) | ||
return render_template("blog.html", posts=posts) | ||
|
||
|
||
@app.route("/blog/<post_slug>.html") | ||
def post(post_slug): | ||
post_file = f"posts/{post_slug}.html" | ||
if os.path.exists(post_file): | ||
with open(post_file) as f: | ||
content = Markup(f.read()) | ||
title = post_slug.replace("-", " ").title() | ||
return render_template("post.html", title=title, content=content) | ||
else: | ||
return "Post not found", 404 | ||
|
||
|
||
if __name__ == '__main__': | ||
freezer.freeze() | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) | ||
post_files = os.listdir('posts/') | ||
posts = [post.replace('.html', '') | ||
for post in post_files if post.endswith('.html')] | ||
print(f"Posts: {posts}") # Debugging line | ||
return render_template('index.html', posts=posts) | ||
|
||
# Route for individual posts | ||
|
||
|
||
@app.route('/posts/<post_name>') | ||
def post(post_name): | ||
post_path = f'posts/{post_name}.html' | ||
try: | ||
with open(post_path, 'r') as file: | ||
content = file.read() | ||
return render_template('post.html', title=post_name.capitalize(), content=content) | ||
except FileNotFoundError: | ||
abort(404) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=True, port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p id="dev-cal-2">大家在高中一定趁大好时光多开心呀</p> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters