First success with templating articles into index.html
Markdown works rudimentary. Unfortunately it does not support some features by now maybe due to my poor templating without correct line breaking?
This commit is contained in:
parent
bdff627aee
commit
64da3357c1
|
@ -33,6 +33,62 @@
|
||||||
<div id="flex-container">
|
<div id="flex-container">
|
||||||
<main class="flex-item">
|
<main class="flex-item">
|
||||||
<h1>Artikel</h1>
|
<h1>Artikel</h1>
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h1>Ein zweiter Test!</h1>
|
||||||
|
<dl>
|
||||||
|
<dt>Autor</dt><dd>homer77</dd>
|
||||||
|
<dt>Erstellt am</dt><dd>02/15/15</dd>
|
||||||
|
<dt>Zuletzt geändert</dt><dd>02/15/15</dd>
|
||||||
|
</dl>
|
||||||
|
</header>
|
||||||
|
<h1>Das ist ein weiter Testartikel</h1>
|
||||||
|
<h2>Ich muss das abschließen für heute</h2>
|
||||||
|
<p><a href="https://example.org">Klick mich</a></p>
|
||||||
|
<footer>
|
||||||
|
<p> </p>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h1>Das ist der zweite Artikel</h1>
|
||||||
|
<dl>
|
||||||
|
<dt>Autor</dt><dd>homer77</dd>
|
||||||
|
<dt>Erstellt am</dt><dd>02/24/15</dd>
|
||||||
|
<dt>Zuletzt geändert</dt><dd>02/24/15</dd>
|
||||||
|
</dl>
|
||||||
|
</header>
|
||||||
|
<p>Dies ist der zweite Test.
|
||||||
|
Ich schreibe verschiedene Zeilen Text und teste damit <strong>Markdown</strong></p>
|
||||||
|
<p>Ist das jetzt ein neuer <em>Absatz</em>?</p>
|
||||||
|
<p>Und wie kann ich Code-Blöcke wie <code>apt-get install</code> einfügen? Funktioniert das mit 3 oder 4 Backticks?</p>
|
||||||
|
<p><code>Gehen auch
|
||||||
|
mehrere
|
||||||
|
Code-zeilen?</code></p>
|
||||||
|
<p>Und was ist mit Listen?
|
||||||
|
- Erster Eintrag
|
||||||
|
- Zweiter Eintrag
|
||||||
|
- Erster Untereintrag
|
||||||
|
- Dritter Eintrag</p>
|
||||||
|
<footer>
|
||||||
|
<p>lustig,langweilig,blabla</p>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h1>Dies ist ein Test</h1>
|
||||||
|
<dl>
|
||||||
|
<dt>Autor</dt><dd>homer77</dd>
|
||||||
|
<dt>Erstellt am</dt><dd>02/15/15</dd>
|
||||||
|
<dt>Zuletzt geändert</dt><dd>02/15/15</dd>
|
||||||
|
</dl>
|
||||||
|
</header>
|
||||||
|
<h1>Type your article <em>right here</em>.</h1>
|
||||||
|
<p>You may use <em>Markdown</em> to format.</p>
|
||||||
|
<footer>
|
||||||
|
<p>test,picoblogger,coden</p>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
<aside class="flex-item">
|
<aside class="flex-item">
|
||||||
|
|
|
@ -9,7 +9,7 @@ header *, nav *, footer *, div#flex-container {
|
||||||
margin:0; padding:0;
|
margin:0; padding:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
header {
|
body > header {
|
||||||
padding:0.5em 0.25em 0 0.25em;
|
padding:0.5em 0.25em 0 0.25em;
|
||||||
display:block;
|
display:block;
|
||||||
width:100%;
|
width:100%;
|
||||||
|
@ -17,7 +17,7 @@ header {
|
||||||
background: #000;
|
background: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
header h1 {
|
body > header h1 {
|
||||||
font-family:"URW Gothic L";
|
font-family:"URW Gothic L";
|
||||||
font-weight:lighter;
|
font-weight:lighter;
|
||||||
padding:0.5em 0.5em 0 0;
|
padding:0.5em 0.5em 0 0;
|
||||||
|
@ -26,7 +26,7 @@ header h1 {
|
||||||
float:right;
|
float:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
header h2 {
|
body > header h2 {
|
||||||
font-family:"URW Gothic L";
|
font-family:"URW Gothic L";
|
||||||
font-weight:lighter;
|
font-weight:lighter;
|
||||||
display:block;
|
display:block;
|
||||||
|
@ -115,6 +115,55 @@ main h1 {
|
||||||
font-weight:lighter;
|
font-weight:lighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main article {
|
||||||
|
width:90%;
|
||||||
|
margin:0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
main > article > header {
|
||||||
|
background:#222;
|
||||||
|
clear:both;
|
||||||
|
}
|
||||||
|
|
||||||
|
main > article > header > h1 {
|
||||||
|
width:100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
main > article > header > dl {
|
||||||
|
clear:both;
|
||||||
|
width:100%;
|
||||||
|
background:#222;
|
||||||
|
font-size:70%;
|
||||||
|
}
|
||||||
|
|
||||||
|
main > article > header > dl > dt {
|
||||||
|
display:inline;
|
||||||
|
}
|
||||||
|
main > article > header > dl > dt:after {
|
||||||
|
content:": ";
|
||||||
|
}
|
||||||
|
|
||||||
|
main > article > header > dl > dd {
|
||||||
|
display:inline;
|
||||||
|
font-weight:bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
article > h1, article > h2, article > h3, article > h4 {
|
||||||
|
display:block;
|
||||||
|
position:relative;
|
||||||
|
width:100%; height: auto;
|
||||||
|
float:left;
|
||||||
|
font-family:"Gentium",serif;
|
||||||
|
font-weight:lighter;
|
||||||
|
}
|
||||||
|
|
||||||
|
main > article > h1 { }
|
||||||
|
main > article > h2 { }
|
||||||
|
main > article > h3 { }
|
||||||
|
main > article > h4 { }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
aside {
|
aside {
|
||||||
webkit-flex:3 7 30%;
|
webkit-flex:3 7 30%;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h1>${ARTICLE_TITLE}</h1>
|
||||||
|
<dl>
|
||||||
|
<dt>${TEMPLATE_ARTICLE_AUTHOR}</dt><dd>${ARTICLE_AUTHOR}</dd>
|
||||||
|
<dt>${TEMPLATE_ARTICLE_CREATED}</dt><dd>${ARTICLE_CREATED}</dd>
|
||||||
|
<dt>${TEMPLATE_ARTICLE_MODIFIED}</dt><dd>${ARTICLE_MODIFIED}</dd>
|
||||||
|
</dl>
|
||||||
|
</header>
|
||||||
|
${ARTICLE_BODY}
|
||||||
|
<footer>
|
||||||
|
<p>${ARTICLE_TAGS}</p>
|
||||||
|
</footer>
|
||||||
|
</article>
|
|
@ -0,0 +1,12 @@
|
||||||
|
# HEADER_BEGIN
|
||||||
|
|
||||||
|
DATE : ${DATE}
|
||||||
|
TIME : ${TIME}
|
||||||
|
AUTHOR : ${AUTHOR}
|
||||||
|
TAGS :
|
||||||
|
TITLE :
|
||||||
|
|
||||||
|
# HEADER_END
|
||||||
|
|
||||||
|
Type your article right here.
|
||||||
|
You may use Markdown to format.
|
|
@ -96,7 +96,7 @@ def parse_conf(path):
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
f = open(path, "r")
|
f = open(path, "r")
|
||||||
else:
|
else:
|
||||||
f = path
|
f = path.split("\n")
|
||||||
for line in f:
|
for line in f:
|
||||||
if "#" in line:
|
if "#" in line:
|
||||||
line = line[0:line.find("#")]
|
line = line[0:line.find("#")]
|
||||||
|
@ -143,14 +143,12 @@ except:
|
||||||
|
|
||||||
def parse_article(path):
|
def parse_article(path):
|
||||||
article = open(path,"r").read()
|
article = open(path,"r").read()
|
||||||
header = article.lstrip("HEADER_BEGIN")
|
header = article.split("HEADER_BEGIN")[1]
|
||||||
print(header)
|
header = header.split("HEADER_END")[0]
|
||||||
header = header.rstrip("HEADER_END")
|
body = markdown.markdown(article.split("HEADER_END")[1])
|
||||||
print(header)
|
|
||||||
body = markdown.markdown(article.lstrip("HEADER_END")[1])
|
|
||||||
print(body)
|
|
||||||
article_dict = parse_conf(header)
|
article_dict = parse_conf(header)
|
||||||
article_dict['BODY'] = body
|
article_dict['BODY'] = body
|
||||||
|
article_dict['MODIFIED'] = time.strftime("%x",time.gmtime(os.stat(path).st_mtime))
|
||||||
|
|
||||||
return article_dict
|
return article_dict
|
||||||
|
|
||||||
|
@ -163,22 +161,21 @@ def article_to_html(article_dict):
|
||||||
tplSub = {
|
tplSub = {
|
||||||
"ARTICLE_TITLE":article_dict['TITLE'],
|
"ARTICLE_TITLE":article_dict['TITLE'],
|
||||||
"ARTICLE_AUTHOR":article_dict['AUTHOR'],
|
"ARTICLE_AUTHOR":article_dict['AUTHOR'],
|
||||||
"ARTICLE_CREATED":article_dict['CREATED'],
|
"ARTICLE_CREATED":article_dict['DATE'],
|
||||||
"ARTICLE_MODIFIED":article_dict['MODIFIED'],
|
"ARTICLE_MODIFIED":article_dict['MODIFIED'],
|
||||||
"ARTICLE_BODY":article_dict['BODY'],
|
"ARTICLE_BODY":article_dict['BODY'],
|
||||||
"ARTICLE_TAGS":article_dict['TAGS']
|
"ARTICLE_TAGS":article_dict['TAGS']
|
||||||
}
|
}
|
||||||
|
|
||||||
sARTICLE = Template(sARTICLE).safe_substitute(tplSub)
|
sARTICLE = Template(sARTICLE).safe_substitute(tplSub)
|
||||||
|
|
||||||
return sARTICLE
|
return sARTICLE
|
||||||
|
|
||||||
def join_articles():
|
def join_articles():
|
||||||
artDir = os.path.join(blog_dir,"articles")
|
artDir = os.path.join(blog_dir,"articles")
|
||||||
joined_html = ""
|
joined_html = ""
|
||||||
|
|
||||||
for name in [os.path.splitext(item)[0] for item in os.listdir(draftDir) if not "~" in item]:
|
for name in [os.path.splitext(item)[0] for item in os.listdir(draftDir) if not "\~" in item]:
|
||||||
joined_html += article_to_html(parse_article(os.path.join(artDir, name + ".txt")))
|
joined_html += article_to_html(parse_article(os.path.join(artDir, name + ".txt")))
|
||||||
|
|
||||||
return joined_html
|
return joined_html
|
||||||
|
|
||||||
|
@ -198,8 +195,9 @@ def update_blog(subsection):
|
||||||
|
|
||||||
sNAV = open(os.path.join(tplDir,"nav.htm")).read()
|
sNAV = open(os.path.join(tplDir,"nav.htm")).read()
|
||||||
sNAV = Template(sNAV).safe_substitute(l10nconf)
|
sNAV = Template(sNAV).safe_substitute(l10nconf)
|
||||||
sMAIN = open(os.path.join(tplDir,"main.htm")).read()
|
# sMAIN = open(os.path.join(tplDir,"main.htm")).read()
|
||||||
sMAIN = Template(sMAIN).safe_substitute(join_articles())
|
# sMAIN = Template(sMAIN).safe_substitute(join_articles())
|
||||||
|
sMAIN = join_articles()
|
||||||
sASIDE = open(os.path.join(tplDir,"aside.htm")).read()
|
sASIDE = open(os.path.join(tplDir,"aside.htm")).read()
|
||||||
sFOOTER = open(os.path.join(tplDir,"footer.htm")).read()
|
sFOOTER = open(os.path.join(tplDir,"footer.htm")).read()
|
||||||
|
|
||||||
|
@ -215,11 +213,11 @@ def update_blog(subsection):
|
||||||
with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
||||||
print(tmpIndex, file=f)
|
print(tmpIndex, file=f)
|
||||||
|
|
||||||
def article_to_html(name):
|
# def article_to_html(name):
|
||||||
article = os.path.join(blog_dir,"articles",name + ".txt")
|
# article = os.path.join(blog_dir,"articles",name + ".txt")
|
||||||
txt = open(article).read()
|
# txt = open(article).read()
|
||||||
html = markdown.markdown(txt)
|
# html = markdown.markdown(txt)
|
||||||
return html
|
# return html
|
||||||
|
|
||||||
|
|
||||||
##################
|
##################
|
||||||
|
@ -326,7 +324,9 @@ if vars(args)['target'] == 'article':
|
||||||
## edit article
|
## edit article
|
||||||
|
|
||||||
if vars(args)['action'] == 'edit':
|
if vars(args)['action'] == 'edit':
|
||||||
pass
|
draft = os.path.join(blog_dir,"articles",vars(args)['id'] + ".txt")
|
||||||
|
subprocess.call(["emacs", " -nw", draft])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## remove article
|
## remove article
|
||||||
|
|
Loading…
Reference in New Issue