There had been some restructuring on code:

* update_blog has been split up into functions which build index, archive and current articles separately
* Main's h1-title now shows the same terms like in nav-bar.
* Articles now have perma-links - at least for current articles at this moment. Same function will be added soon for archieved articles.

picoblogger is now close to beta testing I would claim ...
This commit is contained in:
maste9 2015-03-22 00:08:55 +01:00 committed by Homer S
parent 1ce84e67d0
commit 344bb82fb4
11 changed files with 431 additions and 34 deletions

View File

@ -0,0 +1,86 @@
<!DOCTYPE html />
<html lang="de">
<head>
<title>Mein Blog</title>
<meta name="author" content="${BLOG_AUTHOR}" />
<meta name="generator" content="picoblogger 0.1" />
<meta charset="utf-8" />
<meta name="keywords" content="${BLOG_KEYWORDS}" />
<meta name="description" content="${BLOG_DESCRIPTION}" />
<meta name="language" content="de" />
<meta name="robots" content="index,follow" />
<!-- <link rel="stylesheet" href="css/print.css" media="print" /> -->
<link rel="stylesheet" href="../css/style.css" media="all" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml"
title="RSS" href="feed.xml" />
<link rel="shortcut icon" href="images/favicon.ico" type="images/vnd.microsoft.icon" />
</head>
<body>
<header>
<h1>Mein Blog</h1><h2>Meine Worte, Meine Meinung ... </h2>
</header>
<nav>
<h1>Navigation</h1>
<ul>
<li><a href="index.html" class="home">Aktuell</a></li>
<li><a href="archive.html">Archiv</a></li>
</ul>
</nav>
<div id="flex-container">
<main class="flex-item">
<h1>Artikel</h1>
<article>
<header>
<h1 id="1426006082"><a href="1426006082.html">This article should stay on index!</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>10.03.2015 um 17:48 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>10.03.2015 um 16:49 Uhr</dd>
</dl>
</header>
<p>As this should be the only article on this machine written in march 2015 all the others should be moved to the correct folders in archive folder.</p>
<p>Let's have a look!</p>
<footer>
<p><a href="tags/archive.html" class="tag">#archive</a> <a href="tags/test.html" class="tag">#test</a> <a href="tags/current.html" class="tag">#current</a> </p>
</footer>
</article>
</main>
<aside class="flex-item">
<h1>Übrigens ...</h1>
<h2>Letzte Artikel</h2>
<ul>
<li><a href="1426966835.html" title="21.03.2015 um 20:40 Uhr">Sixth Article - Just to Simulate Regular Use</a></li><li><a href="1426006082.html" title="10.03.2015 um 17:48 Uhr">This article should stay on index!</a></li>
</ul>
<h2>Kontakt</h2>
<dl class="contact">
<dt>E-Mail</dt>
<dd>any@mail.address.org</dd>
<dt>Diaspora</dt>
<dd>youraccount@anypod.org</dd>
</dl>
</aside>
</div>
<footer>
<h1>Appendix</h1>
<dl>
<dt>powered with:</dt>
<dd>
<ul>
<li><a href="https://github.com/maste9/picoblogger">picoblogger</a></li>
</ul>
</dd>
</dl>
</footer>
</body>
</html>

View File

@ -0,0 +1,86 @@
<!DOCTYPE html />
<html lang="de">
<head>
<title>Mein Blog</title>
<meta name="author" content="${BLOG_AUTHOR}" />
<meta name="generator" content="picoblogger 0.1" />
<meta charset="utf-8" />
<meta name="keywords" content="${BLOG_KEYWORDS}" />
<meta name="description" content="${BLOG_DESCRIPTION}" />
<meta name="language" content="de" />
<meta name="robots" content="index,follow" />
<!-- <link rel="stylesheet" href="css/print.css" media="print" /> -->
<link rel="stylesheet" href="../css/style.css" media="all" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml"
title="RSS" href="feed.xml" />
<link rel="shortcut icon" href="images/favicon.ico" type="images/vnd.microsoft.icon" />
</head>
<body>
<header>
<h1>Mein Blog</h1><h2>Meine Worte, Meine Meinung ... </h2>
</header>
<nav>
<h1>Navigation</h1>
<ul>
<li><a href="index.html" class="home">Aktuell</a></li>
<li><a href="archive.html">Archiv</a></li>
</ul>
</nav>
<div id="flex-container">
<main class="flex-item">
<h1>Artikel</h1>
<article>
<header>
<h1 id="1426966835"><a href="1426966835.html">Sixth Article - Just to Simulate Regular Use</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>21.03.2015 um 20:40 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>21.03.2015 um 19:43 Uhr</dd>
</dl>
</header>
<h2>Work goes on</h2>
<p>and now focuses on archive.</p>
<footer>
<p><a href="tags/notag.html" class="tag">#notag</a> </p>
</footer>
</article>
</main>
<aside class="flex-item">
<h1>Übrigens ...</h1>
<h2>Letzte Artikel</h2>
<ul>
<li><a href="1426966835.html" title="21.03.2015 um 20:40 Uhr">Sixth Article - Just to Simulate Regular Use</a></li><li><a href="1426006082.html" title="10.03.2015 um 17:48 Uhr">This article should stay on index!</a></li>
</ul>
<h2>Kontakt</h2>
<dl class="contact">
<dt>E-Mail</dt>
<dd>any@mail.address.org</dd>
<dt>Diaspora</dt>
<dd>youraccount@anypod.org</dd>
</dl>
</aside>
</div>
<footer>
<h1>Appendix</h1>
<dl>
<dt>powered with:</dt>
<dd>
<ul>
<li><a href="https://github.com/maste9/picoblogger">picoblogger</a></li>
</ul>
</dd>
</dl>
</footer>
</body>
</html>

View File

@ -0,0 +1,71 @@
<!DOCTYPE html />
<html lang="de">
<head>
<title>Mein Blog</title>
<meta name="author" content="${BLOG_AUTHOR}" />
<meta name="generator" content="picoblogger 0.1" />
<meta charset="utf-8" />
<meta name="keywords" content="${BLOG_KEYWORDS}" />
<meta name="description" content="${BLOG_DESCRIPTION}" />
<meta name="language" content="de" />
<meta name="robots" content="index,follow" />
<!-- <link rel="stylesheet" href="css/print.css" media="print" /> -->
<link rel="stylesheet" href="../css/style.css" media="all" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml"
title="RSS" href="feed.xml" />
<link rel="shortcut icon" href="images/favicon.ico" type="images/vnd.microsoft.icon" />
</head>
<body>
<header>
<h1>Mein Blog</h1><h2>Meine Worte, Meine Meinung ... </h2>
</header>
<nav>
<h1>Navigation</h1>
<ul>
<li><a href="index.html" class="home">Aktuell</a></li>
<li><a href="archive.html">Archiv</a></li>
</ul>
</nav>
<div id="flex-container">
<main class="flex-item">
<h1>Archiv</h1>
<h2>2015</h2><h3>2</h3><li><a href="2.html" title="24.02.2015 um 21:19 Uhr">Das ist der zweite Artikel</a></li><li><a href="3.html" title="15.02.2015 um 23:18 Uhr">Ein zweiter Test!</a></li><li><a href="1.html" title="15.02.2015 um 23:16 Uhr">Dies ist ein Test</a></li><h3>1</h3><li><a href="1426004699.html" title="10.01.2015 um 17:24 Uhr">May the Fourth Be With You!!</a></li>
</main>
<aside class="flex-item">
<h1>Übrigens ...</h1>
<h2>Letzte Artikel</h2>
<ul>
<ul><li>2015</li><ul><li>2</li><li>1</li></ul></ul>
</ul>
<h2>Kontakt</h2>
<dl class="contact">
<dt>E-Mail</dt>
<dd>any@mail.address.org</dd>
<dt>Diaspora</dt>
<dd>youraccount@anypod.org</dd>
</dl>
</aside>
</div>
<footer>
<h1>Appendix</h1>
<dl>
<dt>powered with:</dt>
<dd>
<ul>
<li><a href="https://github.com/maste9/picoblogger">picoblogger</a></li>
</ul>
</dd>
</dl>
</footer>
</body>
</html>

View File

@ -0,0 +1,101 @@
<!DOCTYPE html />
<html lang="de">
<head>
<title>Mein Blog</title>
<meta name="author" content="${BLOG_AUTHOR}" />
<meta name="generator" content="picoblogger 0.1" />
<meta charset="utf-8" />
<meta name="keywords" content="${BLOG_KEYWORDS}" />
<meta name="description" content="${BLOG_DESCRIPTION}" />
<meta name="language" content="de" />
<meta name="robots" content="index,follow" />
<!-- <link rel="stylesheet" href="css/print.css" media="print" /> -->
<link rel="stylesheet" href="../css/style.css" media="all" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml"
title="RSS" href="feed.xml" />
<link rel="shortcut icon" href="images/favicon.ico" type="images/vnd.microsoft.icon" />
</head>
<body>
<header>
<h1>Mein Blog</h1><h2>Meine Worte, Meine Meinung ... </h2>
</header>
<nav>
<h1>Navigation</h1>
<ul>
<li><a href="index.html" class="home">Aktuell</a></li>
<li><a href="archive.html">Archiv</a></li>
</ul>
</nav>
<div id="flex-container">
<main class="flex-item">
<h1>Aktuell</h1>
<article>
<header>
<h1 id="1426966835"><a href="1426966835.html">Sixth Article - Just to Simulate Regular Use</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>21.03.2015 um 20:40 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>21.03.2015 um 19:43 Uhr</dd>
</dl>
</header>
<h2>Work goes on</h2>
<p>and now focuses on archive.</p>
<footer>
<p><a href="tags/notag.html" class="tag">#notag</a> </p>
</footer>
</article>
<article>
<header>
<h1 id="1426006082"><a href="1426006082.html">This article should stay on index!</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>10.03.2015 um 17:48 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>10.03.2015 um 16:49 Uhr</dd>
</dl>
</header>
<p>As this should be the only article on this machine written in march 2015 all the others should be moved to the correct folders in archive folder.</p>
<p>Let's have a look!</p>
<footer>
<p><a href="tags/archive.html" class="tag">#archive</a> <a href="tags/test.html" class="tag">#test</a> <a href="tags/current.html" class="tag">#current</a> </p>
</footer>
</article>
</main>
<aside class="flex-item">
<h1>Übrigens ...</h1>
<h2>Letzte Artikel</h2>
<ul>
<li><a href="1426966835.html" title="21.03.2015 um 20:40 Uhr">Sixth Article - Just to Simulate Regular Use</a></li><li><a href="1426006082.html" title="10.03.2015 um 17:48 Uhr">This article should stay on index!</a></li>
</ul>
<h2>Kontakt</h2>
<dl class="contact">
<dt>E-Mail</dt>
<dd>any@mail.address.org</dd>
<dt>Diaspora</dt>
<dd>youraccount@anypod.org</dd>
</dl>
</aside>
</div>
<footer>
<h1>Appendix</h1>
<dl>
<dt>powered with:</dt>
<dd>
<ul>
<li><a href="https://github.com/maste9/picoblogger">picoblogger</a></li>
</ul>
</dd>
</dl>
</footer>
</body>
</html>

View File

@ -4,7 +4,6 @@
APP_NAME = picoblogger
APP_VERSION = 0.1
MAIN_TITLE = Artikel
TEMPLATE_ARTICLE_AUTHOR = Autor
TEMPLATE_ARTICLE_CREATED = Erstellt am
TEMPLATE_ARTICLE_MODIFIED = Zuletzt geändert
@ -16,8 +15,9 @@ CONTACT_MAIL_TITLE = E-Mail
CONTACT_SOCIAL_TITLE = Diaspora
NAV_TITLE = Navigation
HOME_BUTTON = Aktuell
ARCHIVE_BUTTON = Archiv
CURRENT = Aktuell
ARCHIVE = Archiv
ARTICLE = Artikel
BLOG_CHARSET = utf-8
FOOTER_TITLE = Appendix

View File

@ -1,6 +1,6 @@
<article>
<header>
<h1 id="${ARTICLE_ID}"><a href="#${ARTICLE_ID}">${ARTICLE_TITLE}</a></h1>
<h1 id="${ARTICLE_ID}"><a href="${ARTICLE_ID}.html">${ARTICLE_TITLE}</a></h1>
<dl>
<dt>${TEMPLATE_ARTICLE_AUTHOR}</dt><dd>${ARTICLE_AUTHOR}</dd>
<dt>${TEMPLATE_ARTICLE_CREATED}</dt><dd>${ARTICLE_CREATED_DATE} ${ARTICLE_CREATED_TIME}</dd>

View File

@ -10,7 +10,7 @@
<meta name="language" content="${BLOG_LANG}" />
<meta name="robots" content="index,follow" />
<!-- <link rel="stylesheet" href="css/print.css" media="print" /> -->
<link rel="stylesheet" href="style.css" media="all" />
<link rel="stylesheet" href="../css/style.css" media="all" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
@ -28,7 +28,6 @@
</nav>
<div id="flex-container">
<main class="flex-item">
<h1>${MAIN_TITLE}</h1>
${TEMPLATE_MAIN}
</main>
<aside class="flex-item">

View File

@ -0,0 +1 @@
<h1>${MAIN_TITLE}</h1>

View File

@ -1,4 +1,4 @@
<ul>
<li><a href="index.html" class="home">${HOME_BUTTON}</a></li>
<li><a href="archive.html">${ARCHIVE_BUTTON}</a></li>
<li><a href="index.html" class="home">${CURRENT}</a></li>
<li><a href="archive.html">${ARCHIVE}</a></li>
</ul>

View File

@ -79,6 +79,8 @@ except:
# path to blog's templates
tplDir = os.path.join(blog_dir,"templates")
tplIndex = os.path.join(tplDir,"index.htm")
tplIndex = Template(open(tplIndex,'r').read())
# path to drafts
draftDir = os.path.join(blog_dir,"drafts")
@ -89,6 +91,11 @@ articleDir = os.path.join(blog_dir,"articles")
# path to archive
archiveDir = os.path.join(blog_dir,"archive")
# path to html files
htmlDir = os.path.join(blog_dir,"html")
htmlIndex = os.path.join(htmlDir,"index.html")
htmlArchive = os.path.join(htmlDir,"archive.html")
# paths to configs
pbconfpath = os.path.join("/","etc","picoblogger","pb.conf") # global config
blogconfpath = os.path.join(blog_dir,"pb.conf") # local config
@ -224,7 +231,7 @@ def join_articles(artDir = articleDir):
return joined_html
def recent_to_html(article_dict):
sLINK = '<li><a href="#${ARTICLE_ID}" title="${ARTICLE_CREATED_DATE} ${ARTICLE_CREATED_TIME}">${ARTICLE_TITLE}</a></li>'
sLINK = '<li><a href="${ARTICLE_ID}.html" title="${ARTICLE_CREATED_DATE} ${ARTICLE_CREATED_TIME}">${ARTICLE_TITLE}</a></li>'
# Read out article txt file
@ -359,33 +366,34 @@ def list_archive(archived_months):
html += ""
return html
def templating(dic):
sMAIN = ""
if 'sMAIN_TITLE' in dic.keys():
title = dic['sMAIN_TITLE']
sMAIN = open(os.path.join(tplDir,"main.htm")).read()
sMAIN = Template(sMAIN).safe_substitute({'MAIN_TITLE':title})
if 'sMAIN' in dic.keys():
main = dic['sMAIN']
sMAIN += main
if 'sRECENT' in dic.keys():
recent = dic['sRECENT']
if 'sASIDE' in dic.keys():
aside = dic['sASIDE']
def update_blog(subsection):
""" Joins config defined variables into templates"""
if subsection in ("recent","all"):
tplIndex = os.path.join(tplDir,"index.htm")
blogIndex = os.path.join(blog_dir,"index.html")
elif subsection in ("archive"):
tplIndex = os.path.join(tplDir,"index.htm")
blogIndex = os.path.join(blog_dir,"archive.html")
tpl = Template(open(tplIndex,'r').read())
sNAV = open(os.path.join(tplDir,"nav.htm")).read()
sNAV = Template(sNAV).safe_substitute(l10nconf)
if subsection == "recent":
sMAIN = join_articles()
elif subsection == "archive":
sMAIN = list_archive(list_of_months())
sASIDE = open(os.path.join(tplDir,"aside.htm")).read()
sRECENT = open(os.path.join(tplDir,"recent.htm")).read()
sCONTACT = open(os.path.join(tplDir,"contact.htm")).read()
sFOOTER = open(os.path.join(tplDir,"footer.htm")).read()
tmpIndex = tpl.safe_substitute(l10nconf)
tmpIndex = tplIndex.safe_substitute(l10nconf)
sASIDE = Template(sASIDE).safe_substitute(l10nconf)
sCONTACT = Template(sCONTACT).safe_substitute(l10nconf)
sRECENT = Template(sRECENT).safe_substitute(l10nconf)
@ -398,16 +406,13 @@ def update_blog(subsection):
sRECENT = Template(sRECENT).safe_substitute(blogconf)
sFOOTER = Template(sFOOTER).safe_substitute(blogconf)
if pbconf:
tmpIndex = Template(tmpIndex).safe_substitute(pbconf)
tmpIndex = Template(tpIndex).safe_substitute(pbconf)
sASIDE = Template(sASIDE).safe_substitute(pbconf)
sCONTACT = Template(sCONTACT).safe_substitute(pbconf)
sRECENT = Template(sRECENT).safe_substitute(pbconf)
sFOOTER = Template(sFOOTER).safe_substitute(pbconf)
if subsection in ("recent","all"):
sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":recent_articles(amountRecent)})
elif subsection == "archive":
sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":months_to_html(list_of_months())})
sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":recent})
sASIDE = Template(sASIDE).safe_substitute({"ASIDE_RECENT":sRECENT, "ASIDE_CONTACT":sCONTACT})
tplSub = {
@ -418,9 +423,57 @@ def update_blog(subsection):
}
tmpIndex = Template(tmpIndex).safe_substitute(tplSub)
return tmpIndex
with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
print(tmpIndex, file=f)
def build_index():
param = {}
param['sRECENT'] = recent_articles(amountRecent)
param['sMAIN'] = join_articles()
param['sMAIN_TITLE'] = l10nconf['CURRENT']
htmlString = templating(param)
with open(htmlIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
print(htmlString, file=f)
def build_archive():
param={}
param['sRECENT'] = months_to_html(list_of_months())
param['sMAIN'] = list_archive(list_of_months())
param['sMAIN_TITLE'] = l10nconf['ARCHIVE']
htmlString = templating(param)
with open(htmlArchive,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
print(htmlString, file=f)
def build_article(path):
param={}
dic = parse_article(path)
param['sRECENT'] = recent_articles(amountRecent)
param['sMAIN'] = article_to_html(dic)
param['sMAIN_TITLE'] = l10nconf['ARTICLE']
htmlArticle = os.path.join(htmlDir,dic['ID']+".html")
htmlString = "<h1>"
htmlString = templating(param)
with open(htmlArticle,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
print(htmlString, file=f)
def build_current_articles():
for name in [os.path.splitext(item)[0] for item in os.listdir(articleDir) if not "~" in item]:
build_article(os.path.join(articleDir, name + ".txt"))
def update_blog(subsection):
""" Joins config defined variables into templates"""
if subsection in ("recent","all"):
build_index()
build_current_articles()
elif subsection in ("archive","all"):
build_archive()