Skip to content

Commit eae322f

Browse files
committed
continue moving stuff out of index.md
1 parent 0656c02 commit eae322f

File tree

4 files changed

+116
-15
lines changed

4 files changed

+116
-15
lines changed

generate-html.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,42 @@
1010
FEED_TEMPLATE_FILE = "templates/rss_feed_template.xml"
1111
BASE_URL = "https://tonybaloney.github.io/"
1212

13+
14+
1315
def main():
14-
posts = glob.glob("blog/*.md")
16+
md_post_paths = glob.glob("blog/*.md")
1517
extensions = ['extra', 'smarty', 'meta', 'codehilite']
1618
_md = markdown.Markdown(extensions=extensions, output_format='html5')
1719

1820
loader = jinja2.FileSystemLoader(searchpath="./")
1921
env = jinja2.Environment(loader=loader)
2022

2123
all_posts = []
22-
for post in posts:
24+
for post in md_post_paths:
2325
print("rendering {0}".format(post))
2426
post_date = date.fromisoformat(post[5:15])
25-
url = post.replace(".md", ".html").replace("blog/", "posts/")
27+
post_html_path = post.replace(".md", ".html").replace("blog/", "posts/")
2628
with open(post) as f:
2729
html = _md.convert(f.read())
2830
context = {
2931
'blog_publish_date': post_date,
3032
**_md.Meta
3133
}
32-
doc = env.get_template(TEMPLATE_FILE).render(content=html, baseurl=BASE_URL, url=url, **context)
34+
doc = env.get_template(TEMPLATE_FILE).render(content=html, baseurl=BASE_URL, url=post_html_path, **context)
3335

34-
post_html = url
35-
with open(post_html, "w") as post_html_f:
36-
post_html_f.write(doc)
36+
with open(post_html_path, "w") as f:
37+
f.write(doc)
3738
# all_posts.append(dict(**_md.Meta, date=post_date, rfc2822_date=format_datetime(post_date), link="{0}{1}".format(BASE_URL, url)))
38-
all_posts.append(dict(**_md.Meta, date=post_date, rfc2822_date='', link="{0}{1}".format(BASE_URL, url))) # TODO fix date
39+
all_posts.append(dict(**_md.Meta, date=post_date, rfc2822_date='', link="{0}{1}".format(BASE_URL, post_html_path))) # TODO fix date
3940

4041
# index
4142
print("rendering index.html")
4243
with open('index.md') as f:
4344
index_html = _md.convert(f.read())
44-
doc = env.get_template('templates/index.html').render(content=index_html)
45+
doc = env.get_template('templates/index.html').render(
46+
content=index_html,
47+
posts=all_posts,
48+
)
4549
with open('index.html', "w") as f:
4650
f.write(doc)
4751

index.html

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,76 @@ <h1>The Book</h1>
4848
</li>
4949

5050
<li>
51-
Read in Early Release via O'Reilly Learning (aka Safari)
51+
Read in online on O'Reilly Learning (aka Safari)
5252
<a href="https://learning.oreilly.com/library/view/architecture-patterns-with/9781492052197/">learning.oreilly.com</a>
5353
</li>
5454

5555
<li>
56-
Preorder on [Amazon.com](https://amzn.to/37pR2DH) or [Amazon.co.uk](https://amzn.to/38CmFu1)
56+
Preorder print books on
57+
<a href="https://amzn.to/37pR2DH">Amazon.com</a>
58+
or
59+
<a href="https://amzn.to/38CmFu1">Amazon.co.uk</a>.
60+
</li>
61+
<li>
62+
Buy a DRM-free ebook at
63+
<a href="https://www.ebooks.com/en-us/book/209971850/architecture-patterns-with-python/harry-percival/">ebooks.com</a>
64+
</li>
65+
</ul>
66+
67+
<h1>Blog</h1>
68+
69+
<h3>Recent posts</h3>
70+
71+
<ul>
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
<li>
83+
<a href="">2020-01-25 </a>
84+
</li>
85+
86+
87+
</ul>
88+
89+
<h3>Classic 2017 Episodes on Ports & Adapters, by Bob</h3>
90+
5791

92+
<ul>
93+
94+
95+
<li>
96+
<a href="https://tonybaloney.github.io/posts/2017-09-07-introducing-command-handler.html">2017-09-07 </a>
97+
</li>
98+
99+
100+
101+
<li>
102+
<a href="https://tonybaloney.github.io/posts/2017-09-19-why-use-domain-events.html">2017-09-19 </a>
103+
</li>
104+
105+
106+
107+
<li>
108+
<a href="https://tonybaloney.github.io/posts/2017-09-13-commands-and-queries-handlers-and-views.html">2017-09-13 </a>
109+
</li>
110+
111+
112+
113+
<li>
114+
<a href="https://tonybaloney.github.io/posts/2017-09-08-repository-and-unit-of-work-pattern-in-python.html">2017-09-08 </a>
115+
</li>
116+
117+
118+
119+
120+
</ul>
58121

59122

60123
</section>

rss.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Simple patterns for building complex apps
88
</description>
99
<link>https://cosmicpython.com</link>
10-
<lastBuildDate>Sun, 15 Mar 2020 21:52:20 -0000</lastBuildDate>
10+
<lastBuildDate>Sun, 15 Mar 2020 22:03:35 -0000</lastBuildDate>
1111
<pubDate>Sat, 4 Jan 2020 19:15:54 -0500</pubDate>
1212
<atom:link href="https://cosmicpython.com/rss.xml" rel="self" type="application/rss+xml" />
1313

templates/index.html

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,47 @@ <h1>The Book</h1>
2525
</li>
2626

2727
<li>
28-
Read in Early Release via O'Reilly Learning (aka Safari)
28+
Read in online on O'Reilly Learning (aka Safari)
2929
<a href="https://learning.oreilly.com/library/view/architecture-patterns-with/9781492052197/">learning.oreilly.com</a>
3030
</li>
3131

3232
<li>
33-
Preorder on [Amazon.com](https://amzn.to/37pR2DH) or [Amazon.co.uk](https://amzn.to/38CmFu1)
33+
Preorder print books on
34+
<a href="https://amzn.to/37pR2DH">Amazon.com</a>
35+
or
36+
<a href="https://amzn.to/38CmFu1">Amazon.co.uk</a>.
37+
</li>
38+
<li>
39+
Buy a DRM-free ebook at
40+
<a href="https://www.ebooks.com/en-us/book/209971850/architecture-patterns-with-python/harry-percival/">ebooks.com</a>
41+
</li>
42+
</ul>
3443

44+
<h1>Blog</h1>
3545

36-
{% endblock %}
46+
<h3>Recent posts</h3>
47+
48+
<ul>
49+
{% for post in posts %}
50+
{% if post.date.year != 2017 %}
51+
<li>
52+
<a href="{{ post.url }}">{{ post.date }} {{ post.title }}</a>
53+
</li>
54+
{% endif %}
55+
{% endfor %}
56+
</ul>
3757

58+
<h3>Classic 2017 Episodes on Ports & Adapters, by Bob</h3>
59+
60+
61+
<ul>
62+
{% for post in posts %}
63+
{% if post.date.year == 2017 %}
64+
<li>
65+
<a href="{{ post.link }}">{{ post.date }} {{ post.title }}</a>
66+
</li>
67+
{% endif %}
68+
{% endfor %}
69+
</ul>
70+
71+
{% endblock %}

0 commit comments

Comments
 (0)