Skip to content

Commit

Permalink
Updated Nov 23 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiangyuan Li authored and Jiangyuan Li committed Nov 23, 2024
1 parent 5978856 commit 31460f1
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 65 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/venv/
/venv/
/build/
26 changes: 26 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
from flask import Flask, render_template
from flask_frozen import Freezer
from markupsafe import Markup

app = Flask(__name__)
freezer = Freezer(app)
Expand All @@ -10,6 +12,30 @@ 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>")
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()

Expand Down
6 changes: 3 additions & 3 deletions freeze.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from app import app # Import your Flask app from app.py
from flask_frozen import Freezer
from app import app

freezer = Freezer(app)

if __name__ == '__main__':
freezer.freeze() # This will generate the static files
if __name__ == "__main__":
freezer.freeze()
2 changes: 2 additions & 0 deletions posts/my-first-post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>My First Post</h1>
<p id="dev-cal-2">This is the content of my first blog post. It's awesome!</p>
Binary file modified static/.DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,17 @@ nav {
padding: 0 3px;
}

h1,
h2,
footer {
margin-left: 30px;
font-family: 'Inter', 'Source Han Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

main {
margin-top: 70px;
}

/* media queries */

@media (prefers-color-scheme: dark) {
Expand Down
Binary file added static/fonts/SourceHanSansCN-Bold-min.woff2
Binary file not shown.
Binary file added static/fonts/SourceHanSansCN-Regular-min.woff2
Binary file not shown.
16 changes: 16 additions & 0 deletions templates/blog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "layout.html" %}

{% block content %}
<h1>Welcome to My Blog</h1>

<div class="blog-posts">
{% for post in posts %}
<article class="blog-post">
<h2>{{ post.title }}</h2>
<div class="post-content">
{{ post.content | safe }}
</div>
</article>
{% endfor %}
</div>
{% endblock %}
8 changes: 5 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% extends "layout.html" %}

{% block title %}Home - My Frozen Flask App{% endblock %}
{% block title %}Jerry's blog...{% endblock %}

{% block content %}
<h2>Welcome to the Homepage!</h2>
<p>This is the content specific to the homepage.</p>
<h2>Jerry's blog</h2>
<p id="dev-cal-2">This is the content specific to the homepage.</p>
<p id="dev-cal-2">This is the content specific to the homepage.</p>
<p id="dev-cal-2">This is the content specific to the homepage.</p>
{% endblock %}
62 changes: 4 additions & 58 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
</script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='fontawesome/css/all.css') }}">
<link rel="preconnect" href="https://rsms.me/">
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
</head>

<body>
Expand All @@ -38,65 +40,9 @@
</a>
<div class="b-item-1"><span id="titleDisplay"></span></div>
<div id="attic-items">
<div class="b-item-2">things I love</div>
<div class="b-item-2">publications</div>
<div class="b-item">
<a href="./apple.html">Apple</a>
</div>
<div class="b-item">
<a href="./friends.html">Friends</a>
</div>
<div class="b-item">
<a href="./music.html">Music</a>
</div>
<div class="b-item">
<a href="./taylorswift.html">Swiftie</a>
</div>
<div class="b-item-2">festivity</div>
<div class="b-item">
<a href="./christmas.html">Christmas</a>
</div>
<div class="b-item">
<a href="./homemade_giftcard.html">Homemade Giftcard</a>
</div>
<div class="b-item-2">other stuff</div>
<div class="b-item">
<a href="./aluminum_studio.html">About</a>
</div>
<div class="b-item">
<a href="https://blog.jerryly.top">
Blog&emsp13;&emsp13;
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>
</div>
<div class="b-item">
<a href="./classical_ch_sh.html">Classical Chinese for Senior High</a>
</div>
<div class="b-item">
<a href="./classical_ch.html">Classical Chinese for Junior High</a>
</div>
<div class="b-item">
<a href="./clock.html">Clock</a>
</div>
<div class="b-item">
<a href="./contact.html">Contact</a>
</div>
<div class="b-item">
<a href="./develop.html">Develop</a>
</div>
<div class="b-item">
<a href="./flashback.html">Rainbow Room</a>
</div>
<div class="b-item">
<a href="./gallery.html">Gallery</a>
</div>
<div class="b-item">
<a href="./noticeboard.html">Noticeboard</a>
</div>
<div class="b-item">
<a href="./search.html">Search (deprecated)</a>
</div>
<div class="b-item">
<a href="./survey.html">Survey</a>
<a href="{{ url_for('blog') }}">Blog</a>
</div>
</div>
</header>
Expand Down
15 changes: 15 additions & 0 deletions templates/post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "layout.html" %}

{% block title %}
{{ title }} - My Blog
{% endblock %}

{% block content %}
<h1>{{ title }}</h1>

<div class="post-content">
{{ content | safe }}
</div>

<a href="{{ url_for('blog') }}">Back to Blog</a>
{% endblock %}

0 comments on commit 31460f1

Please sign in to comment.