Any article older than one month now is moved to archive folder which is substructured into year and month folders.

Now I work on archive.html
This commit is contained in:
maste9 2015-03-10 21:30:25 +01:00 committed by Homer S
parent 62e460dc98
commit f3f343a2a8
4 changed files with 89 additions and 279 deletions

View File

@ -1,127 +0,0 @@
<!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="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="2"><a href="#2">Das ist der zweite Artikel</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>24.02.2015 um 21:19 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>08.03.2015 um 13:47 Uhr</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><a href="tags/lustig.html" class="tag">#lustig</a> <a href="tags/langweilig.html" class="tag">#langweilig</a> <a href="tags/blabla.html" class="tag">#blabla</a> </p>
</footer>
</article>
<article>
<header>
<h1 id="3"><a href="#3">Ein zweiter Test!</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>15.02.2015 um 23:18 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>08.03.2015 um 13:46 Uhr</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 id="1"><a href="#1">Dies ist ein Test</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>15.02.2015 um 23:16 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>08.03.2015 um 13:47 Uhr</dd>
</dl>
</header>
<h1>Type your article <em>right here</em>.</h1>
<p>You may use <em>Markdown</em> to format.</p>
<footer>
<p><a href="tags/test.html" class="tag">#test</a> <a href="tags/picoblogger.html" class="tag">#picoblogger</a> <a href="tags/coden.html" class="tag">#coden</a> </p>
</footer>
</article>
</main>
<aside class="flex-item">
<h1>Übrigens ...</h1>
<h2>Letzte Artikel</h2>
<ul>
<li><a href="#2" title="24.02.2015 um 21:19 Uhr">Das ist der zweite Artikel</a></li><li><a href="#3" title="15.02.2015 um 23:18 Uhr">Ein zweiter Test!</a></li><li><a href="#1" title="15.02.2015 um 23:16 Uhr">Dies ist ein Test</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

@ -1,127 +0,0 @@
<!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="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="2"><a href="#2">Das ist der zweite Artikel</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>24.02.2015 um 21:19 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>08.03.2015 um 13:47 Uhr</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><a href="tags/lustig.html" class="tag">#lustig</a> <a href="tags/langweilig.html" class="tag">#langweilig</a> <a href="tags/blabla.html" class="tag">#blabla</a> </p>
</footer>
</article>
<article>
<header>
<h1 id="3"><a href="#3">Ein zweiter Test!</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>15.02.2015 um 23:18 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>08.03.2015 um 13:46 Uhr</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 id="1"><a href="#1">Dies ist ein Test</a></h1>
<dl>
<dt>Autor</dt><dd>homer77</dd>
<dt>Erstellt am</dt><dd>15.02.2015 um 23:16 Uhr</dd>
<dt>Zuletzt geändert</dt><dd>08.03.2015 um 13:47 Uhr</dd>
</dl>
</header>
<h1>Type your article <em>right here</em>.</h1>
<p>You may use <em>Markdown</em> to format.</p>
<footer>
<p><a href="tags/test.html" class="tag">#test</a> <a href="tags/picoblogger.html" class="tag">#picoblogger</a> <a href="tags/coden.html" class="tag">#coden</a> </p>
</footer>
</article>
</main>
<aside class="flex-item">
<h1>Übrigens ...</h1>
<h2>Letzte Artikel</h2>
<ul>
<li><a href="#2" title="24.02.2015 um 21:19 Uhr">Das ist der zweite Artikel</a></li><li><a href="#3" title="15.02.2015 um 23:18 Uhr">Ein zweiter Test!</a></li><li><a href="#1" title="15.02.2015 um 23:16 Uhr">Dies ist ein Test</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

@ -5,6 +5,7 @@ BLOG_SUBTITLE = Meine Worte, Meine Meinung ... # Das ist ein Kommentar zum Test
BLOG_LANG = de
BLOG_DATE_FORMAT = %d.%m.%Y
BLOG_TIME_FORMAT = um %H:%M Uhr
BLOG_CURRENT_ARTICLES = 2
CONTACT_MAIL_ADDRESS = any@mail.address.org
CONTACT_SOCIAL_ADDRESS = youraccount@anypod.org

View File

@ -62,6 +62,10 @@ print(args)
# logged in user
user = getpass.getuser()
# current and date
timestamp = time.localtime()
# set path to blog
try:
blog_dir = os.path.abspath(os.path.expanduser(vars(args)['blog_dir']))
@ -132,7 +136,7 @@ try:
dateFormat = blogconf['BLOG_DATE_FORMAT']
timeFormat = blogconf['BLOG_TIME_FORMAT']
amountRecent = int(blogconf['RECENT_AMOUNT'])
notToArchive = blogconf['BLOG_CURRENT_ARTICLES']
nrOfCurrentArticles = int(blogconf['BLOG_CURRENT_ARTICLES'])
except:
print("Couldn't parse blog's local configuration (%s)."%blogconfpath)
@ -157,6 +161,9 @@ def parse_article(path):
header = header.split("HEADER_END")[0]
body = markdown.markdown(article.split("HEADER_END")[1])
article_dict = parse_conf(header)
split_path = os.path.split(path)
article_dict['PATH'] = split_path[0]
article_dict['FILENAME'] = split_path[1]
article_dict['BODY'] = body
article_dict['MODIFIED_DATE'] = time.strftime(dateFormat,time.gmtime(os.stat(path).st_mtime))
article_dict['MODIFIED_TIME'] = time.strftime(timeFormat,time.gmtime(os.stat(path).st_mtime))
@ -200,11 +207,11 @@ def article_to_html(article_dict):
sARTICLE = Template(sARTICLE).safe_substitute(tplSub)
return sARTICLE
def join_articles():
artDir = os.path.join(blog_dir,"articles")
def join_articles(artDir = articleDir):
joined_html = ""
articles_dict = {}
for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "\~" in item]:
for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "~" in item]:
article = (parse_article(os.path.join(artDir, name + ".txt")))
# Bring articles into chronological order
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%m/%d/%y %H:%M:%S"))
@ -242,10 +249,10 @@ def recent_to_html(article_dict):
def recent_articles(amount):
artDir = os.path.join(blog_dir,"articles")
artDir = articleDir
joined_html = ""
articles_dict = {}
for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "\~" in item]:
for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "~" in item]:
article = (parse_article(os.path.join(artDir, name + ".txt")))
# Bring articles into chronological order
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%m/%d/%y %H:%M:%S"))
@ -258,25 +265,82 @@ def recent_articles(amount):
return joined_html
def archive_articles(notToArchive):
articles= [item for os.listdir(artDir) if not "\~" in item]
for i in range(notToArchive,):
def archive_articles():
articles = [parse_article(os.path.join(articleDir,item)) for item in os.listdir(articleDir) if not "~" in item]
# print(articles)
cMonth = timestamp.tm_mon
cYear = timestamp.tm_year
# sort articles by date of creation into archive which is structured by subfolders of year and month
for article in articles:
aName = article["FILENAME"]
aPath = os.path.join(article["PATH"], aName)
aDate = time.strptime(article["DATE"],"%m/%d/%y")
aMonth = aDate.tm_mon
aYear = aDate.tm_year
# archive only articles older than current month
if (aMonth < cMonth) or (aYear < cYear):
yearDir = os.path.join(archiveDir,str(aYear))
monthDir = os.path.join(yearDir,str(aMonth))
if not os.path.exists(yearDir):
try:
os.makedirs(monthDir, mode=0o755)
except:
raise
else:
if not os.path.exists(monthDir):
try:
os.mkdir(monthDir, mode=0o755)
except:
raise
replPath = os.path.join(monthDir,aName)
try:
os.replace(aPath,replPath)
print("Archived %s into %s."%(aName,monthDir))
except:
print("Failed archiving %s."%aName)
raise
def list_of_months():
dArchives = {}
years = os.listdir(archiveDir)
for year in years:
yearDir = os.path.join(archiveDir,year)
months = os.listdir(yearDir)
dArchives[year] = []
for month in months:
monthDir = os.path.join(yearDir,month)
tMonth = time.strptime(month+"/"+year,"%m/%Y")
sMonth = time.strftime("%B",tMonth)
dArchives[year].append(sMonth)
print(dArchives)
return dArchives
def list_articles():
pass
os.replace(draft, article)
def update_blog(subsection):
# Joins config defined variables into templates
""" Joins config defined variables into templates"""
tplIndex = os.path.join(tplDir,"index.htm")
blogIndex = os.path.join(blog_dir,"index.html")
if subsection == "recent":
tplIndex = os.path.join(tplDir,"index.htm")
blogIndex = os.path.join(blog_dir,"index.html")
elif subsection == "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)
# sMAIN = open(os.path.join(tplDir,"main.htm")).read()
# sMAIN = Template(sMAIN).safe_substitute(join_articles())
sMAIN = join_articles()
if subsection == "recent":
sMAIN = join_articles()
elif subsection == "archive":
sMAIN = list_articles()
sASIDE = open(os.path.join(tplDir,"aside.htm")).read()
sRECENT = open(os.path.join(tplDir,"recent.htm")).read()
@ -302,7 +366,10 @@ def update_blog(subsection):
sRECENT = Template(sRECENT).safe_substitute(pbconf)
sFOOTER = Template(sFOOTER).safe_substitute(pbconf)
sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":recent_articles(amountRecent)})
if subsection == "recent":
sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":recent_articles(amountRecent)})
elif subsection == "archive":
sRECENT = Template(sRECENT).safe_substitute({"RECENT_ARTICLES":list_of_months()})
sASIDE = Template(sASIDE).safe_substitute({"ASIDE_RECENT":sRECENT, "ASIDE_CONTACT":sCONTACT})
tplSub = {
@ -318,11 +385,6 @@ def update_blog(subsection):
print(tmpIndex, file=f)
# def article_to_html(name):
# article = os.path.join(blog_dir,"articles",name + ".txt")
# txt = open(article).read()
# html = markdown.markdown(txt)
# return html
##################
@ -337,6 +399,7 @@ if vars(args)['target'] == 'blog':
## update subsections or whole blog
if vars(args)['action'] == 'update':
archive_articles()
if vars(args)['subsection'] in ('recent','all'):
pass
@ -392,7 +455,7 @@ if vars(args)['target'] == 'draft':
if vars(args)['action'] == 'edit':
draft = os.path.join(blog_dir,"drafts",vars(args)['name'] + ".txt")
subprocess.call(["emacs", " -nw", draft])
subprocess.call(["emacs", "-nw", draft])
## remove draft
@ -420,7 +483,7 @@ if vars(args)['target'] == 'article':
article = os.path.join(blog_dir,"articles",vars(args)['name'] + ".txt")
tpl = os.path.join(tplDir,"article.tpl")
sTpl = open(tpl).read()
subs = {"DATE" : time.strftime("%x",time.localtime()), "TIME" : time.strftime("%X",time.localtime()),
subs = {"ID":int(time.mktime(time.localtime())), "DATE" : time.strftime("%x",time.localtime()), "TIME" : time.strftime("%X",time.localtime()),
"AUTHOR" : user
}
@ -443,7 +506,7 @@ if vars(args)['target'] == 'article':
if vars(args)['action'] == 'edit':
draft = os.path.join(blog_dir,"articles",vars(args)['id'] + ".txt")
subprocess.call(["emacs", " -nw", draft])
subprocess.call(["emacs", "-nw", draft])