mirror of
https://github.com/evennia/evennia.git
synced 2026-04-05 15:37:17 +02:00
Continuing working on blog engine
This commit is contained in:
parent
0fbe696f41
commit
312d4546f8
6 changed files with 23 additions and 20 deletions
Binary file not shown.
|
|
@ -22,7 +22,7 @@ Here starts the main text ...
|
|||
import glob
|
||||
from dataclasses import dataclass
|
||||
from collections import defaultdict
|
||||
from dateutil import parser as dateparser
|
||||
from dateutils import parser as dateparser
|
||||
from datetime import datetime
|
||||
from os.path import abspath, dirname, join as pathjoin, sep
|
||||
import mistletoe
|
||||
|
|
@ -37,6 +37,7 @@ TEMPLATE_DIR = pathjoin(SOURCE_DIR, "templates")
|
|||
BLOG_TEMPLATE = "blog.html"
|
||||
POST_TEMPLATE = "post.html"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Post:
|
||||
title: str
|
||||
|
|
@ -52,8 +53,8 @@ def md2html():
|
|||
blog_template = jinja_env.get_template(BLOG_TEMPLATE)
|
||||
post_template = jinja_env.get_template(POST_TEMPLATE)
|
||||
|
||||
calendar = defaultdict(dict)
|
||||
posts = {}
|
||||
calendar = defaultdict(list)
|
||||
posts = []
|
||||
|
||||
for file_path in glob.glob(pathjoin(SOURCE_DIR, "*.md")):
|
||||
# parse/check if file is on form YY-MM-DD-Blog-Name.md
|
||||
|
|
@ -89,9 +90,6 @@ def md2html():
|
|||
elif line.startswith("images"):
|
||||
image_refs = line
|
||||
|
||||
# unique id for post
|
||||
post_id = hash(str(date.toordinal()) + title)
|
||||
|
||||
markdown_post = "\n".join(lines)
|
||||
# convert markdown to html
|
||||
html_post = mistletoe.markdown(markdown_post)
|
||||
|
|
@ -105,12 +103,26 @@ def md2html():
|
|||
}
|
||||
html_page = post_template.render(context)
|
||||
|
||||
posts[post_id] = html_page
|
||||
calendar[date.year][post_id]
|
||||
# store
|
||||
post = Post(title=title, date=date, image_refs=image_refs, html=html_page)
|
||||
posts.append(post)
|
||||
calendar[date.year].append(post)
|
||||
|
||||
# we have all posts, now insert them into the blog
|
||||
|
||||
posts = sorted(posts, key=lambda pst: -pst.date.toordinal())
|
||||
for year in calendar:
|
||||
calendar[year] = sorted(calendar[year], key=lambda pst: -pst.date.toordinal())
|
||||
|
||||
context = {
|
||||
posts: posts,
|
||||
calendar: calendar
|
||||
}
|
||||
|
||||
html_page = blog_template.render(context)
|
||||
|
||||
return html_page
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(md2html())
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
# A way to do things
|
||||
|
||||
This is a test blog page for using markdown to write
|
||||
[Evennia](https://www.evennia.com) devblog posts.
|
||||
|
||||
## Starting out
|
||||
|
||||
I'm experimenting with a new section of the docs containing these
|
||||
blog posts (obviously the blogs are CC anyway).
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -14,7 +14,7 @@
|
|||
<script src="javascripts/newsfeed.js">
|
||||
</script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<meta name="description" content="Evennia is a modern Python library and server for creating text-based multi-player games and virtual worlds (also known as MUD, MUSH, MU, MUX, MUCK, etc). While Evennia handles all the necessary things every online game needs, like database and networking, you create the game of your dreams by writing normal Python modules.">
|
||||
<meta name="description" content="Evennia is a modern Python library and server for creating text-based multi-player games and virtual worlds (also known as MUD, MUSH, MU, MUX, MUCK, etc). While Evennia handles all the necessary things every online game needs, like database and networking, you create the game of your dreams by writing normal Python modules.">
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js">
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue