diff --git a/list.js b/list.js new file mode 100644 index 0000000..76e14c0 --- /dev/null +++ b/list.js @@ -0,0 +1,12 @@ +function(head, req) { + var row, results; + results = []; + categories = (req.query.categories !== undefined ? JSON.parse(req.query.categories) : []); + while (row = getRow()) { + if (categories.length == 0 || + categories.some(function(c) { return row.key.indexOf(c) !== -1; })) { + results.push([row.key, row.id]); + } + } + return JSON.stringify({q : req.query.categories, results : results}); +} diff --git a/src/posts.py b/src/posts.py index d5a2d40..93d6113 100644 --- a/src/posts.py +++ b/src/posts.py @@ -30,20 +30,22 @@ class Posts: self.db = self.client["blog"] - def savepost(self, title="", content="", author="", category="programming", _id=False): + self.iterpost = self.postIterator("blogPosts/blog-posts") + + def savepost(self, title="", content="", author="", categories=[], _id=False): if _id: doc = self.db[_id] doc["title"] = title doc["content"] = content doc["author"] = author - doc["category"] = category + doc["categories"] = categories doc["_id"] = _id else: doc = { "title" : title, "content" : content, "author" : author, - "category" : category, + "categories" : categories, "type" : "post" } @@ -69,35 +71,37 @@ class Posts: return post - def iterpost(self, endkey=False, startkey=False, category="programming"): - if startkey and not endkey: - results = self.db.iterview("blogPosts/blog-posts", 2, include_docs=True, startkey=startkey) - elif endkey and not startkey: - results = self.db.iterview("blogPosts/blog-posts", 1, include_docs=True, endkey=endkey) - else: - results = self.db.iterview("blogPosts/blog-posts", 2, include_docs=True) + def postIterator(self, viewname): + def inner(endkey=False, startkey=False): + if startkey and not endkey: + results = self.db.iterview(viewname, 2, include_docs=True, startkey=startkey) + elif endkey and not startkey: + results = self.db.iterview(viewname, 1, include_docs=True, endkey=endkey) + else: + results = self.db.iterview(viewname, 2, include_docs=True) - docs = [result.doc for result in results] + docs = [result.doc for result in results] - for doc in docs: - doc["content"] = markdown(doc["content"]) + for doc in docs: + doc["content"] = markdown(doc["content"]) - if not docs: - return jsonify("end") + if not docs: + return jsonify("end") - if endkey and not startkey: - if len(docs) < 2 or docs[0] == endkey: - return jsonify("start") - return jsonify(docs[-2]) + if endkey and not startkey: + if len(docs) < 2 or docs[0] == endkey: + return jsonify("start") + return jsonify(docs[-2]) - if len(docs) == 1: - return jsonify(docs[0]) + if len(docs) == 1: + return jsonify(docs[0]) - if docs: - # if no startkey or endkey were specified, return the 0th post - return jsonify(docs[1 if startkey else 0]) + if docs: + # if no startkey or endkey were specified, return the 0th post + return jsonify(docs[1 if startkey else 0]) - return jsonify("end") + return jsonify("end") + return inner def allposts(self): result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True) diff --git a/src/scripts/browse.tag b/src/scripts/browse.tag new file mode 100644 index 0000000..eaef839 --- /dev/null +++ b/src/scripts/browse.tag @@ -0,0 +1,11 @@ + +
+
+ + +
diff --git a/src/scripts/sidebar.tag b/src/scripts/sidebar.tag index 3075fa3..37721ec 100644 --- a/src/scripts/sidebar.tag +++ b/src/scripts/sidebar.tag @@ -16,7 +16,8 @@ show={this.swiped !== undefined} style={ this.styles() } id="sidebar" - class={"animated "+(this.swiped !== undefined ? (this.swiped ? "fadeInLeft" : "fadeOutLeft") : "" ) +" container"} + class={"animated " + (this.swiped !== undefined ? + (this.swiped ? "fadeInLeft" : "fadeOutLeft") : "" ) + " container"} >
/") def getpostid(pid, category): - return posts.iterpost(startkey=pid, category=category) + return posts.iterpost(startkey=pid) # get the post previous to this one @cache.cached(timeout=50) @app.route("/blog/prevpost//") def prevpost(pid, category): - return posts.iterpost(endkey=pid, category=category) + return posts.iterpost(endkey=pid) # get the contents of any post # rendered in JSON