diff options
author | FreeArtMan <dos21h@gmail.com> | 2016-11-09 20:27:16 +0000 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2016-11-09 20:27:16 +0000 |
commit | 0e3bf8fe600072a715764a150dc3c27b6e57da58 (patch) | |
tree | 5d3fa9908322ea2fae88a2b4f798e328d6670af0 | |
parent | 85b685bd72536e0416597b888b3a77ea0ba10afb (diff) | |
download | md-site-0e3bf8fe600072a715764a150dc3c27b6e57da58.tar.gz md-site-0e3bf8fe600072a715764a150dc3c27b6e57da58.zip |
Added tag support
-rwxr-xr-x | src/md.py | 24 | ||||
-rw-r--r-- | src/templ/base.thtml | 3 |
2 files changed, 25 insertions, 2 deletions
@@ -7,6 +7,9 @@ from jinja2 import Environment, PackageLoader, Template, FileSystemLoader import mistune +#global name for templates +article = {} + class TocMixin(): """TOC mixin for Renderer, mix this with Renderer:: @@ -98,6 +101,24 @@ class TocRenderer(TocMixin, mistune.Renderer): pass ################################################################################ +#get first tags and use them to configure some bits +def get_tags(data): + text = "" + tag_section = True + for line in data.split("\n"): + if tag_section: + tag = line.split(":") + l = len(tag) + if l != 2: + tag_section = False + text += line+"\n" + else: + article[tag[0]] = tag[1] + else: + text += line+"\n" + return text + +################################################################################ #check if there is input file if len(sys.argv) < 2: print "Need more arguments" @@ -114,6 +135,7 @@ t = templ_env.get_template("main.thtml") #get md file f = open( md_fn, "r" ) data = f.read() +data = get_tags(data) toc = TocRenderer() md = mistune.Markdown(rule=True,renderer=toc) @@ -122,4 +144,4 @@ md.parse(data) md_rend_toc = toc.render_toc(level=3) md_rend = md_rend_toc + md.render( data ) -print t.render( block = md_rend )
\ No newline at end of file +print t.render( article=article, block = md_rend )
\ No newline at end of file diff --git a/src/templ/base.thtml b/src/templ/base.thtml index 2d6b53a..dc647d7 100644 --- a/src/templ/base.thtml +++ b/src/templ/base.thtml @@ -7,7 +7,8 @@ <link rel="stylesheet" href="/styles/main.css"> <script src="/js/highlight.pack.js"></script> <script>hljs.initHighlightingOnLoad();</script> - <title>{% block title %}{% endblock %}</title> + <title>{{article.title}}</title> + {% if article.keywords %}<meta name="keyword" content="{{article.keywords}}"/>{% endif %} <meta charset="UTF-8" /> </head> <body> |