Browse Source

fix doctype

pull/1/head
wes 8 years ago
parent
commit
70adc3ba17
  1. 5
      src/posts.py
  2. 3
      src/scripts/app.tag
  3. 9
      src/scripts/links.tag
  4. 5
      src/templates/index.html
  5. 34
      src/website.py

5
src/posts.py

@ -87,10 +87,11 @@ class Posts:
return jsonify(posts) return jsonify(posts)
def links(self): def links(self, json=True):
result = list(self.db.iterview("blogPosts/links", 1, include_docs=True)) result = list(self.db.iterview("blogPosts/links", 1, include_docs=True))
if len(result) >= 1: if len(result) >= 1:
return jsonify(result[0].doc.get("links", [])) xs = result[0].doc.get("links", [])
return jsonify(xs) if json else xs
return [] return []
def delete(self, _id): def delete(self, _id):

3
src/scripts/app.tag

@ -129,7 +129,8 @@ self.state = {
"author" : self.opts.author, "author" : self.opts.author,
"title" : self.opts.title, "title" : self.opts.title,
"loaded" : false, "loaded" : false,
"initial" : decodeURIComponent(self.opts.initial_post) "initial" : decodeURIComponent(self.opts.initial_post),
"links" : JSON.parse(decodeURIComponent(self.opts.links))
}; };
self.active = lens.actives({ self.active = lens.actives({

9
src/scripts/links.tag

@ -43,14 +43,13 @@ var self = this;
self.loading = false; self.loading = false;
self.groups = [] self.groups = self.opts.state.links;
getLinks() { getLinks() {
self.update({"loading" : true}); self.update({"loading" : true});
window.cached("/blog/glinks/") window.cached("/blog/glinks/")
.then((resp) => resp.text()) .then((resp) => resp.text())
.then((resp) => { .then((resp) => {
console.log(resp);
self.update( self.update(
{ {
"groups" : JSON.parse(resp), "groups" : JSON.parse(resp),
@ -59,7 +58,11 @@ getLinks() {
}) })
} }
self.on("mount", self.getLinks); self.on("mount", () => {
if (self.opts.state.page != "links") {
self.getLinks();
}
});
</script> </script>
</links> </links>

5
src/templates/index.html

@ -1,4 +1,4 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" <!DOCTYPE html"
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@ -7,8 +7,7 @@
</head> </head>
<html> <html>
<body> <body>
<h4>{{ test }}</h4> <div data-is="app" links="{{ quote(links) }}" page="{{ page }}" author="{{ postcontent['author'] }}" postid="{{ postid }}" title="{{ postcontent['title'] }}" initial_post="{{ quote(postcontent['content']) }}" csrf_token="{{ csrf_token() }}"></div>
<div data-is="app" page="{{ page }}" author="{{ postcontent['author'] }}" postid="{{ postid }}" title="{{ postcontent['title'] }}" initial_post="{{ quote(postcontent['content']) }}" csrf_token="{{ csrf_token() }}"></div>
</body> </body>
<footer> <footer>
<script async type="text/javascript" src="/scripts/riotblog.min.js"></script> <script async type="text/javascript" src="/scripts/riotblog.min.js"></script>

34
src/website.py

@ -40,7 +40,8 @@ def cacheit(key, thunk):
def get_posts(): def get_posts():
posts = getattr(g, "posts", None) posts = getattr(g, "posts", None)
if posts is None: if posts is None:
posts = g._posts = Posts(app.config["COUCHDB_USER"], app.config["COUCHDB_PASSWORD"]) posts = g._posts = Posts(app.config["COUCHDB_USER"],
app.config["COUCHDB_PASSWORD"])
return posts return posts
def get_initial(): def get_initial():
@ -64,11 +65,13 @@ def NeverWhere(configfile=None):
# Set template variables to be injected # Set template variables to be injected
@app.context_processor @app.context_processor
def inject_variables(): def inject_variables():
return dict( return {
quote=quote, "quote" : quote,
postid=initial_post["_id"], "postid" : initial_post["_id"],
postcontent=defaultdict(str) "postcontent" : defaultdict(str),
) "links" : dumps([]),
"projects" : dumps([])
}
@login_manager.user_loader @login_manager.user_loader
def load_user(user_id): def load_user(user_id):
@ -86,10 +89,6 @@ def NeverWhere(configfile=None):
print("did not log in successfully") print("did not log in successfully")
return render_template("login.html", success=success) return render_template("login.html", success=success)
@app.route("/blog/ghprojects", methods=("GET",))
def projects():
return jsonify(loads(cacheit("projects", getProjects)))
# page routes # page routes
@cache.cached(timeout=50) @cache.cached(timeout=50)
@app.route("/blog/posts/", methods=("GET",)) @app.route("/blog/posts/", methods=("GET",))
@ -107,7 +106,12 @@ def NeverWhere(configfile=None):
@cache.cached(timeout=50) @cache.cached(timeout=50)
@app.route("/blog/links", methods=("GET",)) @app.route("/blog/links", methods=("GET",))
def showLinks(): def showLinks():
return render_template("index.html", page="links") return render_template("index.html",
links=dumps(
list(
posts.links(json=False))),
page="links"
)
@cache.cached(timeout=50) @cache.cached(timeout=50)
@app.route("/blog/about", methods=("GET",)) @app.route("/blog/about", methods=("GET",))
@ -127,7 +131,9 @@ def NeverWhere(configfile=None):
lambda: dumps(posts.getpost(_id, json=False))) lambda: dumps(posts.getpost(_id, json=False)))
) )
return render_template("index.html", page="posts", postcontent=dict(post_content)) return render_template("index.html",
page="posts",
postcontent=dict(post_content))
@cache.cached(timeout=50) @cache.cached(timeout=50)
@ -201,6 +207,10 @@ def NeverWhere(configfile=None):
""" """
return posts.links() return posts.links()
@app.route("/blog/ghprojects", methods=("GET",))
def projects():
return jsonify(loads(cacheit("projects", getProjects)))
return app return app
app = NeverWhere() app = NeverWhere()

Loading…
Cancel
Save