Skip to content

Commit ce01de6

Browse files
committed
first stab at rendering index.html from index.md
1 parent 8e558d3 commit ce01de6

3 files changed

Lines changed: 53 additions & 13 deletions

File tree

generate-html.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def main():
2323
print("rendering {0}".format(post))
2424
post_date = date.fromisoformat(post[5:15])
2525
url = post.replace(".md", ".html").replace("blog/", "posts/")
26-
with open(post) as post_f:
27-
html = _md.convert(post_f.read())
26+
with open(post) as f:
27+
html = _md.convert(f.read())
2828
context = {
2929
'blog_publish_date': post_date,
3030
**_md.Meta
@@ -35,7 +35,15 @@ def main():
3535
with open(post_html, "w") as post_html_f:
3636
post_html_f.write(doc)
3737
# 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)))
38+
all_posts.append(dict(**_md.Meta, date=post_date, rfc2822_date='', link="{0}{1}".format(BASE_URL, url))) # TODO fix date
39+
40+
# index
41+
print("rendering index.html")
42+
with open('index.md') as f:
43+
index_html = _md.convert(f.read())
44+
doc = env.get_template('templates/index.html').render(content=index_html)
45+
with open('index.html', "w") as f:
46+
f.write(doc)
3947

4048
# Order blog posts by date published
4149
all_posts.sort(key=lambda item: item['date'], reverse=True)

index.html

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
2-
<html lang=en>
2+
<html lang="en">
3+
34
<head>
45
<meta charset="utf-8">
56
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -10,6 +11,7 @@
1011
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.css">
1112
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pygments-css@1.0.0/friendly.css">
1213
</head>
14+
1315
<body>
1416
<main class="wrapper">
1517

@@ -22,15 +24,46 @@ <h1 class="title">Cosmic Python</h1>
2224
</nav>
2325

2426
<section class="container">
25-
<h1 class="title">Cosmic Python</h1>
26-
<p>Simple patterns for building complex applications</p>
27+
28+
<p># cosmic_python</p>
29+
<p><strong><em>simple patterns for building complex applications</em></strong></p>
30+
<hr>
31+
<p><em>(Because &ldquo;Cosmos&rdquo; is the <a href="https://www.goodreads.com/quotes/604655-cosmos-is-a-greek-word-for-the-order-of-the">opposite of Chaos</a>, you see)</em></p>
32+
<p><img src="images/cover.png" alt="Cover Image for Architecture Patterns with Python Book" style="float: right;" width="200" /></p>
33+
<h2>The Book</h2>
34+
<ul>
35+
<li>Read for free from the sources using Github previews:
36+
<a href="https://github.com/cosmicpython/book#table-of-contents">github.com/cosmicpython/book</a></li>
37+
<li>Read in Early Release via O&rsquo;Reilly Learning (aka Safari)
38+
<a href="https://learning.oreilly.com/library/view/architecture-patterns-with/9781492052197/">learning.oreilly.com</a></li>
39+
<li>Preorder on <a href="https://amzn.to/37pR2DH">Amazon.com</a> or <a href="https://amzn.to/38CmFu1">Amazon.co.uk</a></li>
40+
</ul>
41+
<h2>Blog</h2>
42+
<h3>Recent posts</h3>
43+
<ul>
44+
{% for post in site.posts reversed %}
45+
{% assign year = post.date | date: "%Y" %}
46+
{% if year != "2017" %}
47+
<li>
48+
<a href="{{ post.url }}">{{ post.date | date: "%Y-%m-%d" }} {{ post.title }}</a>
49+
</li>
50+
{% endif %}
51+
{% endfor %}
52+
</ul>
2753

28-
<ul>
54+
<h3>Classic 2017 Episodes on Ports &amp; Adapters, by Bob</h3>
55+
<ul>
56+
{% for post in site.posts reversed %}
57+
{% assign year = post.date | date: "%Y" %}
58+
{% if year == "2017" %}
59+
<li>
60+
<a href="{{ post.url }}">{{ post.date | date: "%Y-%m-%d" }} {{ post.title }}</a>
61+
</li>
62+
{% endif %}
63+
{% endfor %}
64+
</ul>
2965

30-
<li><a href="/posts/2017-09-07-introducing-command-handler.html">Introduction to Command Handler</a></li>
31-
</ul>
3266
</section>
33-
3467
</main>
3568
</body>
36-
</html>
69+
</html>

index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
title:
32
layout: page
43
feature_image: "https://www.jpl.nasa.gov/spaceimages/images/largesize/PIA13111_hires.jpg"
@@ -11,7 +10,7 @@ feature_text: |
1110

1211
_(Because "Cosmos" is the [opposite of Chaos](https://www.goodreads.com/quotes/604655-cosmos-is-a-greek-word-for-the-order-of-the), you see)_
1312

14-
{% include figure.html image="images/cover.png" alt="Cover Image for Architecture Patterns with Python Book" position="right" width="200" %}
13+
<img src="images/cover.png" alt="Cover Image for Architecture Patterns with Python Book" style="float: right;" width="200" />
1514

1615

1716
## The Book

0 commit comments

Comments
 (0)