Templating now works. So updating the index file is functioning. Rudimentary styling of page including flex-design for later mobile adjustment.

This commit is contained in:
maste9 2015-01-26 00:36:36 +01:00 committed by Homer S
parent af7be060b5
commit 55d2175710
10 changed files with 302 additions and 45 deletions

4
.gitignore vendored
View File

@ -10,6 +10,10 @@ __pycache__/
*.py[cod]
>>>>>>> Initial commit
# Emacs backup and lock files
*~
\#*\#
# C extensions
*.so

View File

@ -0,0 +1,49 @@
<!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/">Archiv</a></li>
</ul>
</nav>
<div id="flex-container">
<main class="flex-item">
<h1>Artikel</h1>
</main>
<aside class="flex-item">
<h1>By the way ...</h1>
</aside>
</div>
<footer>
<h1>Das Beste zum Schluss</h1>
</footer>
</body>
</html>

View File

@ -1,11 +1,11 @@
# L10n for all static variables of the blog
# LANG: de
[General]
APP_NAME=picoblogger
APP_VERSION=0.1
MAIN_TITLE=Artikel
NAV_TITLE=Navigation
HOME_BUTTON=Aktuell
ARCHIVE_BUTTON=Archiv
BLOG_CHARSET=utf-8
APP_NAME = picoblogger
APP_VERSION = 0.1
MAIN_TITLE = Artikel
NAV_TITLE = Navigation
HOME_BUTTON = Aktuell
ARCHIVE_BUTTON = Archiv
BLOG_CHARSET = utf-8

View File

@ -1,2 +1,5 @@
[General]
# blog specific conf file
BLOG_TITLE = Mein Blog
BLOG_SUBTITLE = Meine Worte, Meine Meinung ... # Das ist ein Kommentar zum Testen
BLOG_LANG = de

View File

@ -0,0 +1,136 @@
body {
margin:0; padding:0;
font-size:14pt;
}
header *, nav *, footer *, div#flex-container {
margin:0; padding:0;
}
header {
padding:0.5em 0.25em 0 0.25em;
display:block;
width:100%;
height:4em;
background: #000;
}
header h1 {
padding:0.5em 0.5em 0 0;
color:#fff;
text-shadow:#999 0.2em -0.2em 0.1em;
float:right;
}
header h2 {
display:block;
width:20%;
height:auto;
padding: 0 0 0 5em;
color:#999;
font-size:80%;
font-style:oblique;
float:left;
text-align:right;
}
nav {
padding:0.5em 0 0 0.5em;
width:100%; height:1.75em;
background:#999;
font-size:0.8em;
}
nav h1 {
display:block;
float:left;
height:1.75em; width:20%;
font-weight:normal;
font-style:oblique;
font-size:1em;
}
nav h1:after {
content:"://";
}
nav ul {
display:block;
float:left;
height:1.75em; width:80%;
list-style-type:none;
}
nav ul li {
display:block;
width:5em;
float:left;
}
nav ul li:after {
content:"/";
}
nav a {
text-decoration:none;
color:#000;
text-shadow:#999 0.2em -0.2em 0.1em;
}
#flex-container {
width:100%;
/* flexbox specific properties */
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
}
main {
-webkit-flex:7 3 70%;
flex:7 3 70%;
-webkit-order:1;
order:1;
margin:0;
padding:0.5em 0 0 0.5em;
background:#000;
color:#666;
min-height:100%;
}
aside {
webkit-flex:3 7 30%;
flex:3 7 30%;
-webkit-order:2;
order:2;
margin:0;
padding:0.5em 0.5em 0 0;
text-align:right;
background:#666;
color:#000;
min-height:40em;
}
footer {
padding:0.5em 0.25em 0 0.25em;
display:block;
width:100%;
height:3.5em;
background: #000;
color:#999;
}
footer h1 {
display:block;
float:right;
width:10em;
font-size:100%;
margin:0em 11em 0 0;
text-align:center;
}

View File

@ -0,0 +1 @@
<h1>By the way ...</h1>

View File

@ -0,0 +1 @@
<h1>Das Beste zum Schluss</h1>

View File

@ -1,12 +1,13 @@
<html lang="$(BLOG_LANG)">
<!DOCTYPE html />
<html lang="${BLOG_LANG}">
<head>
<title><!--{BLOG_TITLE)</title>
<meta name="author" content="$(BLOG_AUTHOR)" />
<meta name="generator" content="$(APP_NAME) $(APP_VERSION)" />
<meta charset="$(BLOG_CHARSET)" />
<meta name="keywords" content="$(BLOG_KEYWORDS)" />
<meta name="description" content="$(BLOG_DESCRIPTION)" />
<meta name="language" content="$(BLOG_LANG)" />
<title>${BLOG_TITLE}</title>
<meta name="author" content="${BLOG_AUTHOR}" />
<meta name="generator" content="${APP_NAME} ${APP_VERSION}" />
<meta charset="${BLOG_CHARSET}" />
<meta name="keywords" content="${BLOG_KEYWORDS}" />
<meta name="description" content="${BLOG_DESCRIPTION}" />
<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" />
@ -19,21 +20,23 @@
</head>
<body>
<header>
<h1>$(BLOG_TITLE)</h1><h2>$(BLOG_SUBTITLE)</h2>
<h1>${BLOG_TITLE}</h1><h2>${BLOG_SUBTITLE}</h2>
</header>
<nav>
<h1>$(NAV_TITLE)
$(TEMPLATE_NAV)
<h1>${NAV_TITLE}</h1>
${TEMPLATE_NAV}
</nav>
<main>
<h1>$(MAIN_TITLE)</h1>
$(TEMPLATE_MAIN)
<div id="flex-container">
<main class="flex-item">
<h1>${MAIN_TITLE}</h1>
${TEMPLATE_MAIN}
</main>
<aside>
$(TEMPLATE_ASIDE)
<aside class="flex-item">
${TEMPLATE_ASIDE}
</aside>
</div>
<footer>
$(TEMPLATE_FOOTER)
${TEMPLATE_FOOTER}
</footer>
</body>
</html>

View File

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

94
picoblogger/main.py Normal file → Executable file
View File

@ -1,16 +1,17 @@
#!/usr/bin/python3
import os
import configparser
import os,re
from string import Template
from argparse import ArgumentParser
# check for arguments and options
parser = ArgumentParser(description="Manage your weblog via commandline. Creates a static html5 compliant website with your publications.")
parser.add_argument('--blog_dir', default='~/public_html/blog', help='path to blog directory (default: %(default)s)')
parser.add_argument('--blog-dir', dest="blog_dir", default='~/public_html/blog', help='path to blog directory (default: %(default)s)')
parser.add_argument('action', choices=['update'], help='updates blog to current state')
args = parser.parse_args()
print(vars(args))
# set path to blog
try:
blog_dir = os.path.abspath(os.path.expanduser(vars(args)['blog_dir']))
if not os.path.isdir(blog_dir):
@ -19,23 +20,82 @@ try:
except:
raise
def readout_conf(p):
config = configparser.ConfigParser()
config.read(p)
return config
# parse unix-config-style files
pbconf = readout_conf(os.path.join(blog_dir,"pb.conf"))
l10nconf = readout_conf(os.path.join(blog_dir,"l10n",pbconf['General']['BLOG_LANG'],"static.conf"))
def update_blog():
def parse_conf(path):
aVars = {}
f = open(path, "r")
for line in f:
if "#" in line:
line = line[0:line.find("#")]
pattern = '^(\w+)\s*?=\s*(.+)[^#]*$'
match = re.search(pattern, line)
if match:
aVars[match.group(1)] = match.group(2)
return aVars
(pbconf,blogconf,l10nconf) = (False,False,False)
pbconfpath = os.path.join("/","etc","picoblogger","pb.conf")
try:
if os.path.isfile(pbconfpath):
pbconf = parse_conf(pbconfpath)
except:
print("Couldn't parse systems global picoblogger configuration (/etc/picoblogger/pb.conf).")
raise
blogconfpath = os.path.join(blog_dir,"pb.conf")
try:
if os.path.isfile(blogconfpath):
blogconf = parse_conf(blogconfpath)
except:
print("Couldn't parse blog's local configuration ([blog-dir]/pb.conf).")
raise
l10nconfpath = os.path.join(blog_dir,"l10n",blogconf['BLOG_LANG'],"static.conf")
try:
if os.path.isfile(l10nconfpath):
l10nconf = parse_conf(l10nconfpath)
print(l10nconf)
except:
print("Couldn't parse localization file ([blog-dir]/l10n/['BLOG_LANG']/static.conf).")
raise
tplDir = os.path.join(blog_dir,"templates")
print(pbconf['General']['BLOG_LANG'])
print(l10nconf['General']['APP_NAME'])
print(l10nconf.defaults())
tplIndex = os.path.join(blog_dir,"templates","index.htm")
tpl = Template(open(tplIndex,'r'))
def update_blog():
tplIndex = os.path.join(tplDir,"index.htm")
blogIndex = os.path.join(blog_dir,"index.html")
with open(blogIndex,"w", encoding=l10nconf['General']['BLOG_CHARSET']) as f:
print(tpl.safe_substitute(l10nconf), file=f)
tpl = Template(open(tplIndex,'r').read())
tmpIndex = tpl.safe_substitute(l10nconf)
if blogconf:
tmpIndex = Template(tmpIndex).safe_substitute(blogconf)
if pbconf:
tmpIndex = Template(tmpIndex).safe_substitute(pbconf)
sNAV = open(os.path.join(tplDir,"nav.htm")).read()
sNAV = Template(sNAV).safe_substitute(l10nconf)
sMAIN = open(os.path.join(tplDir,"main.htm")).read()
sASIDE = open(os.path.join(tplDir,"aside.htm")).read()
sFOOTER = open(os.path.join(tplDir,"footer.htm")).read()
tplSub = {
"TEMPLATE_NAV":sNAV,
"TEMPLATE_MAIN":sMAIN,
"TEMPLATE_ASIDE":sASIDE,
"TEMPLATE_FOOTER":sFOOTER
}
tmpIndex = Template(tmpIndex).safe_substitute(tplSub)
with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
print(tmpIndex, file=f)
if vars(args)['action'] == 'update':
print("Updating your block.")
update_blog()