Skip to content

Commit 3a707ec

Browse files
committed
try to get a handrolled static site generator working
1 parent d9151d4 commit 3a707ec

19 files changed

Lines changed: 2192 additions & 297 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ _site/
33
.jekyll-cache/
44
.jekyll-metadata
55
.bundle
6+
.venv

Gemfile

Lines changed: 0 additions & 2 deletions
This file was deleted.

Gemfile.lock

Lines changed: 0 additions & 247 deletions
This file was deleted.

_posts/2017-09-07-introducing-command-handler.md renamed to blog/2017-09-07-introducing-command-handler.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
---
2-
layout: post
3-
author: Bob
4-
categories:
5-
- ports & adapters
6-
tags:
7-
- python
8-
- architecture
1+
blog_heading: Introducing Command Handler
2+
blog_author: Bob
93
---
104

115
The term DDD comes from the book by Eric Evans: ["Domain-Driven Design: Tackling

_posts/2017-09-08-repository-and-unit-of-work-pattern-in-python.md renamed to blog/2017-09-08-repository-and-unit-of-work-pattern-in-python.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
---
2-
layout: post
3-
author: Bob
4-
categories:
5-
- ports & adapters
6-
tags:
7-
- python
8-
- architecture
1+
blog_author: Bob
2+
blog_heading: Repository and Unit of Work Pattern
3+
94
---
105

116
In the previous part

_posts/2017-09-13-commands-and-queries-handlers-and-views.md renamed to blog/2017-09-13-commands-and-queries-handlers-and-views.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
---
2-
layout: post
3-
author: Bob
4-
categories:
5-
- ports & adapters
6-
tags:
7-
- python
8-
- architecture
1+
blog_author: Bob
2+
blog_heading: Commands, Handlers, Queries and Views
3+
94
---
105

116
In the first and second parts of this series I introduced the

_posts/2017-09-19-why-use-domain-events.md renamed to blog/2017-09-19-why-use-domain-events.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
---
2-
layout: post
3-
author: Bob
4-
categories:
5-
- ports & adapters
6-
tags:
7-
- python
8-
- architecture
1+
blog_heading: Why use domain events?
2+
blog_author: Bob
3+
94
---
105

116
Nota bene: this instalment in the Ports and Adapters with Command Handlers

_posts/2020-01-25-testing_external_api_calls.md renamed to blog/2020-01-25-testing_external_api_calls.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
---
2-
title: Writing tests for external API calls
3-
layout: post
4-
author: Harry
5-
categories:
6-
- testing
7-
tags:
8-
- tdd
9-
- fakes
10-
- mocks
11-
- adapters
1+
blog_heading: Writing tests for external API calls
2+
blog_author: Harry
3+
124
---
135

146

blog/index.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

generate-html.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
# copied from https://github.com/tonybaloney/tonybaloney.github.io/blob/master/blog-gen.py
3+
import markdown
4+
import jinja2
5+
import glob
6+
from datetime import date, datetime
7+
from email.utils import formatdate, format_datetime # for RFC2822 formatting
8+
9+
TEMPLATE_FILE = "templates/blog_post_template.html"
10+
FEED_TEMPLATE_FILE = "templates/rss_feed_template.xml"
11+
BASE_URL = "https://tonybaloney.github.io/"
12+
13+
def main():
14+
posts = glob.glob("blog/*.md")
15+
extensions = ['extra', 'smarty', 'meta']
16+
_md = markdown.Markdown(extensions=extensions, output_format='html5')
17+
18+
loader = jinja2.FileSystemLoader(searchpath="./")
19+
env = jinja2.Environment(loader=loader)
20+
21+
all_posts = []
22+
for post in posts:
23+
print("rendering {0}".format(post))
24+
post_date = date.fromisoformat(post[5:15])
25+
url = post.replace(".md", ".html").replace("blog/", "posts/")
26+
with open(post) as post_f:
27+
html = _md.convert(post_f.read())
28+
context = {
29+
'blog_publish_date': post_date,
30+
**_md.Meta
31+
}
32+
doc = env.get_template(TEMPLATE_FILE).render(content=html, baseurl=BASE_URL, url=url, **context)
33+
34+
post_html = url
35+
with open(post_html, "w") as post_html_f:
36+
post_html_f.write(doc)
37+
# 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)))
39+
40+
# Order blog posts by date published
41+
all_posts.sort(key=lambda item: item['date'], reverse=True)
42+
# Make the RSS feed
43+
with open("rss.xml", "w") as rss_f:
44+
rss_f.write(env.get_template(FEED_TEMPLATE_FILE).render(posts=all_posts, date=formatdate()))
45+
46+
47+
if __name__ == "__main__":
48+
main()

0 commit comments

Comments
 (0)