diff --git a/.gitignore b/.gitignore index 095f499..1be6fa7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,10 @@ __pycache__/ *.py[cod] >>>>>>> Initial commit +# Emacs backup and lock files +*~ +\#*\# + # C extensions *.so diff --git a/picoblogger/blog/index.html b/picoblogger/blog/index.html index e69de29..a4d771a 100644 --- a/picoblogger/blog/index.html +++ b/picoblogger/blog/index.html @@ -0,0 +1,49 @@ + + + + Mein Blog + + + + + + + + + + + + + + +
+

Mein Blog

Meine Worte, Meine Meinung ...

+
+ +
+
+

Artikel

+ +
+ +
+ + + + diff --git a/picoblogger/blog/l10n/de/static.conf b/picoblogger/blog/l10n/de/static.conf index de4ab33..f707041 100644 --- a/picoblogger/blog/l10n/de/static.conf +++ b/picoblogger/blog/l10n/de/static.conf @@ -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 diff --git a/picoblogger/blog/pb.conf b/picoblogger/blog/pb.conf index 6056297..9e5f49b 100644 --- a/picoblogger/blog/pb.conf +++ b/picoblogger/blog/pb.conf @@ -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 diff --git a/picoblogger/blog/style.css b/picoblogger/blog/style.css index e69de29..e7df4b9 100644 --- a/picoblogger/blog/style.css +++ b/picoblogger/blog/style.css @@ -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; + } diff --git a/picoblogger/blog/templates/aside.htm b/picoblogger/blog/templates/aside.htm new file mode 100644 index 0000000..2893ba0 --- /dev/null +++ b/picoblogger/blog/templates/aside.htm @@ -0,0 +1 @@ +

By the way ...

diff --git a/picoblogger/blog/templates/footer.htm b/picoblogger/blog/templates/footer.htm new file mode 100644 index 0000000..35800d3 --- /dev/null +++ b/picoblogger/blog/templates/footer.htm @@ -0,0 +1 @@ +

Das Beste zum Schluss

diff --git a/picoblogger/blog/templates/index.htm b/picoblogger/blog/templates/index.htm index edff59e..01f0e88 100644 --- a/picoblogger/blog/templates/index.htm +++ b/picoblogger/blog/templates/index.htm @@ -1,12 +1,13 @@ - + + - <!--{BLOG_TITLE) - - - - - - + ${BLOG_TITLE} + + + + + + @@ -19,21 +20,23 @@
-

$(BLOG_TITLE)

$(BLOG_SUBTITLE)

+

${BLOG_TITLE}

${BLOG_SUBTITLE}

-
-

$(MAIN_TITLE)

- $(TEMPLATE_MAIN) +
+
+

${MAIN_TITLE}

+ ${TEMPLATE_MAIN}
-
diff --git a/picoblogger/blog/templates/nav.htm b/picoblogger/blog/templates/nav.htm index eb7a1b8..216e6ac 100644 --- a/picoblogger/blog/templates/nav.htm +++ b/picoblogger/blog/templates/nav.htm @@ -1,4 +1,4 @@ diff --git a/picoblogger/main.py b/picoblogger/main.py old mode 100644 new mode 100755 index 785971d..50c69da --- a/picoblogger/main.py +++ b/picoblogger/main.py @@ -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()