pnbp

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 573446b1c05b78de1525fb6915453586fd2c49dd
Author: CPWD <cpwd@lap.(none)>
Date:   Tue May 20 13:55:51 2014

Add all the things

Diffstat:
 .gitignore          | 17 +++++++++++++++++
 about               | 21 +++++++++++++++++++++
 compile.py          | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 data/index.json     |  1 +
 data/test.json      |  1 +
 mod/__init__.py     |  7 +++++++
 mod/blog.py         | 40 ++++++++++++++++++++++++++++++++++++++++
 pages.json          |  4 ++++
 templates/post.html |  4 ++++
 templates/std.html  |  8 ++++++++
 10 files changed, 151 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,17 @@ +#emacs hooblab +auto-save-list +custom.el +url/ +.org-id-locations +\#* +org-mode-config.el +*~ +.#* +\#*\# +*.log +.DS_Store +org-clock-save.el +emacs-config.el + +#python hooblab +*.pyc diff --git a/about b/about @@ -0,0 +1,21 @@ +pnbp - pnbp is not a blogging platform (p = python). + +pnbp is a static content manager that does things with configurability and obscurity. + +pnbp should NOT: + + - suggest the way things should be done + + - not be able to do something purely because it can't be configured to do so + +pnbp should DO: + + - easy API for generator - widget interactions + + - report issues in compiling site with clear, concise results. + +pnbp flow of compiling: + +compile.py -> reads config.json -> iterate through pages -> generates page template -> run pagevar + +compiled pages in .data in pages directory, along with index.php and subpages.conf+ \ No newline at end of file diff --git a/compile.py b/compile.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +''' +' pnbp - pnbp is not a blogging platform +' +' compile.py +' +''' +import mod +import json + +pages = open("pages.json") + +pagedata = json.load(pages) + +pages.close() + +def main(): + print("Going through pages...") + + for name,v in pagedata.items(): + template = open(v['template']).read() + + template = generateTemplate(template,v['pagevar']) + + print("page '{}' using template '{}'...".format(name,v['template'])) + + pages = runMods(template,v['pagemod']) + +# Adds in variables defined in pages.json +# +# t = raw template, var = "pagevar" variables in pages.json (<pagename> -> "pagevar") +def generateTemplate(t,var): + for search,replace in var.items(): + t = t.replace("%"+search,replace) + return t + +# Runs modules defined in pages.json +# +# t = raw template, var = "pagemod" variables in pages.json (<pagename> -> "pagemod") +def runMods(t,var): + subpage = {} + for name, mdata in var.items(): + subpage.update(getattr(mod,mdata['mod']).getPages(t,mdata['settings'],name)) + return subpage + +if __name__ == "__main__": + main() + print("Finished.") diff --git a/data/index.json b/data/index.json @@ -0,0 +1 @@ +[{"post":"0","title":"I don't know what I'm doing","content":"Hello! How're you tuhday?"},{"post":"1","title":"I might have an idea of what I'm doing.","content":"Uh. hi."}]+ \ No newline at end of file diff --git a/data/test.json b/data/test.json @@ -0,0 +1 @@ +[{"post":"0","title":"I don't know what I'm doing","content":"Hello! How're you tuhday?"},{"post":"1","title":"I might have an idea of what I'm doing.","content":"Uh. hi."}]+ \ No newline at end of file diff --git a/mod/__init__.py b/mod/__init__.py @@ -0,0 +1,7 @@ +#Imports all mods from mod/ +import os +for module in os.listdir(os.path.dirname(__file__)): + if module == '__init__.py' or module[-3:] != '.py': + continue + __import__(module[:-3], locals(), globals()) +del module diff --git a/mod/blog.py b/mod/blog.py @@ -0,0 +1,40 @@ +import json + +def getPages(template,settings,name): + pages = {} + settings['postTemplate'] = settings.get("postTemplate","./templates/post.html") + settings['defaultPostCount'] = settings.get("defaultPostCount","0") + data = json.load(open(settings['data'])) + temp = open(settings['postTemplate']).read() + + # Generates all posts on page + a = "" + for i in data: + post = generatePost(i, settings, temp, int(settings['defaultPostCount'])) + a = post + a + pages[slug(i['title'])] = template.replace("%"+name,post) + + pages['default'] = template.replace("%"+name,a) + return pages + +def generatePost(data, settings, post, defaultPostCount): + if defaultPostCount == 0 or int(data['post']) >= defaultPostCount: + for name,x in data.items(): + if name == 'title': + post = post.replace("%titlelink",slug(x)) + + post = post.replace("%"+name, x) + + return post + + +# Helper functions + +# slug("hi's") -> his- removes all "unwanted" characters and creates a URL-friendly slug +def slug(string): + invalidChars = ["<",">","#","%","{","}","|","\\","^","[","]","`","'",";","/","?",":","@","&","+",",","."] + for x in invalidChars: + string = string.replace(x, "") + + string = string.replace(" ","_") + return string.lower() diff --git a/pages.json b/pages.json @@ -0,0 +1,4 @@ +{ +"index":{"template":"templates/std.html","pagevar":{"title":"This is a test page"},"pagemod":{"content":{"mod":"blog","settings":{"defaultPostCount":"0","data":"./data/index.json"}}}}, +"test":{"template":"templates/std.html","pagevar":{"title":"This is THE test page"},"pagemod":{"content":{"mod":"blog","settings":{"defaultPostCount":"1","data":"./data/test.json"}}}} +}+ \ No newline at end of file diff --git a/templates/post.html b/templates/post.html @@ -0,0 +1,4 @@ +<div> + <a href="?title=%titlelink"><h1>%title</h1></a> + <p>%content</p> +</div> diff --git a/templates/std.html b/templates/std.html @@ -0,0 +1,8 @@ +<html> + <head> + <title>%title</title> + </head> + <body> + %content + </body> +</html>