Browse Source

list function for browsing

pull/1/head
wes 8 years ago
parent
commit
d92837fede
  1. 12
      list.js
  2. 18
      src/posts.py
  3. 11
      src/scripts/browse.tag
  4. 3
      src/scripts/sidebar.tag
  5. 6
      src/website.py

12
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});
}

18
src/posts.py

@ -30,20 +30,22 @@ class Posts:
self.db = self.client["blog"] 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: if _id:
doc = self.db[_id] doc = self.db[_id]
doc["title"] = title doc["title"] = title
doc["content"] = content doc["content"] = content
doc["author"] = author doc["author"] = author
doc["category"] = category doc["categories"] = categories
doc["_id"] = _id doc["_id"] = _id
else: else:
doc = { doc = {
"title" : title, "title" : title,
"content" : content, "content" : content,
"author" : author, "author" : author,
"category" : category, "categories" : categories,
"type" : "post" "type" : "post"
} }
@ -69,13 +71,14 @@ class Posts:
return post return post
def iterpost(self, endkey=False, startkey=False, category="programming"): def postIterator(self, viewname):
def inner(endkey=False, startkey=False):
if startkey and not endkey: if startkey and not endkey:
results = self.db.iterview("blogPosts/blog-posts", 2, include_docs=True, startkey=startkey) results = self.db.iterview(viewname, 2, include_docs=True, startkey=startkey)
elif endkey and not startkey: elif endkey and not startkey:
results = self.db.iterview("blogPosts/blog-posts", 1, include_docs=True, endkey=endkey) results = self.db.iterview(viewname, 1, include_docs=True, endkey=endkey)
else: else:
results = self.db.iterview("blogPosts/blog-posts", 2, include_docs=True) results = self.db.iterview(viewname, 2, include_docs=True)
docs = [result.doc for result in results] docs = [result.doc for result in results]
@ -98,6 +101,7 @@ class Posts:
return jsonify(docs[1 if startkey else 0]) return jsonify(docs[1 if startkey else 0])
return jsonify("end") return jsonify("end")
return inner
def allposts(self): def allposts(self):
result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True) result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True)

11
src/scripts/browse.tag

@ -0,0 +1,11 @@
<browse>
<div>
</div>
<script type="es6">
import route from 'riot-route';
var self = this;
</script>
</browse>

3
src/scripts/sidebar.tag

@ -16,7 +16,8 @@
show={this.swiped !== undefined} show={this.swiped !== undefined}
style={ this.styles() } style={ this.styles() }
id="sidebar" id="sidebar"
class={"animated "+(this.swiped !== undefined ? (this.swiped ? "fadeInLeft" : "fadeOutLeft") : "" ) +" container"} class={"animated " + (this.swiped !== undefined ?
(this.swiped ? "fadeInLeft" : "fadeOutLeft") : "" ) + " container"}
> >
<div <div
style={{"height" : "100%", "overflow-x" : "hidden"}} style={{"height" : "100%", "overflow-x" : "hidden"}}

6
src/website.py

@ -73,7 +73,7 @@ def NeverWhere(configfile=None):
"postcontent" : postcontent, "postcontent" : postcontent,
"links" : dumps([]), "links" : dumps([]),
"projects" : dumps([]), "projects" : dumps([]),
"categories" : dumps(posts.categories()) "categories" : cacheit("categories", lambda : dumps(posts.categories()))
} }
@login_manager.user_loader @login_manager.user_loader
@ -145,13 +145,13 @@ def NeverWhere(configfile=None):
@cache.cached(timeout=50) @cache.cached(timeout=50)
@app.route("/blog/switchpost/<pid>/<category>") @app.route("/blog/switchpost/<pid>/<category>")
def getpostid(pid, category): def getpostid(pid, category):
return posts.iterpost(startkey=pid, category=category) return posts.iterpost(startkey=pid)
# get the post previous to this one # get the post previous to this one
@cache.cached(timeout=50) @cache.cached(timeout=50)
@app.route("/blog/prevpost/<pid>/<category>") @app.route("/blog/prevpost/<pid>/<category>")
def prevpost(pid, category): def prevpost(pid, category):
return posts.iterpost(endkey=pid, category=category) return posts.iterpost(endkey=pid)
# get the contents of any post # get the contents of any post
# rendered in JSON # rendered in JSON

Loading…
Cancel
Save