|
10 | 10 | FEED_TEMPLATE_FILE = "templates/rss_feed_template.xml" |
11 | 11 | BASE_URL = "https://tonybaloney.github.io/" |
12 | 12 |
|
| 13 | + |
| 14 | + |
13 | 15 | def main(): |
14 | | - posts = glob.glob("blog/*.md") |
| 16 | + md_post_paths = glob.glob("blog/*.md") |
15 | 17 | extensions = ['extra', 'smarty', 'meta', 'codehilite'] |
16 | 18 | _md = markdown.Markdown(extensions=extensions, output_format='html5') |
17 | 19 |
|
18 | 20 | loader = jinja2.FileSystemLoader(searchpath="./") |
19 | 21 | env = jinja2.Environment(loader=loader) |
20 | 22 |
|
21 | 23 | all_posts = [] |
22 | | - for post in posts: |
| 24 | + for post in md_post_paths: |
23 | 25 | print("rendering {0}".format(post)) |
24 | 26 | 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/") |
26 | 28 | with open(post) as f: |
27 | 29 | html = _md.convert(f.read()) |
28 | 30 | context = { |
29 | 31 | 'blog_publish_date': post_date, |
30 | 32 | **_md.Meta |
31 | 33 | } |
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) |
33 | 35 |
|
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) |
37 | 38 | # 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 |
39 | 40 |
|
40 | 41 | # index |
41 | 42 | print("rendering index.html") |
42 | 43 | with open('index.md') as f: |
43 | 44 | 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 | + ) |
45 | 49 | with open('index.html', "w") as f: |
46 | 50 | f.write(doc) |
47 | 51 |
|
|
0 commit comments