Browse Source

fix doctype

pull/1/head
wes 7 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)
def links(self):
def links(self, json=True):
result = list(self.db.iterview("blogPosts/links", 1, include_docs=True))
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 []
def delete(self, _id):

3
src/scripts/app.tag

@ -129,7 +129,8 @@ self.state = {
"author" : self.opts.author,
"title" : self.opts.title,
"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({

9
src/scripts/links.tag

@ -43,14 +43,13 @@ var self = this;
self.loading = false;
self.groups = []
self.groups = self.opts.state.links;
getLinks() {
self.update({"loading" : true});
window.cached("/blog/glinks/")
.then((resp) => resp.text())
.then((resp) => {
console.log(resp);
self.update(
{
"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>
</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">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
@ -7,8 +7,7 @@
</head>
<html>
<body>
<h4>{{ test }}</h4>
<div data-is="app" page="{{ page }}" author="{{ postcontent['author'] }}" postid="{{ postid }}" title="{{ postcontent['title'] }}" initial_post="{{ quote(postcontent['content']) }}" csrf_token="{{ csrf_token() }}"></div>
<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>
</body>
<footer>
<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():
posts = getattr(g, "posts", 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
def get_initial():
@ -64,11 +65,13 @@ def NeverWhere(configfile=None):
# Set template variables to be injected
@app.context_processor
def inject_variables():
return dict(
quote=quote,
postid=initial_post["_id"],
postcontent=defaultdict(str)
)
return {
"quote" : quote,
"postid" : initial_post["_id"],
"postcontent" : defaultdict(str),
"links" : dumps([]),
"projects" : dumps([])
}
@login_manager.user_loader
def load_user(user_id):
@ -86,10 +89,6 @@ def NeverWhere(configfile=None):
print("did not log in successfully")
return render_template("login.html", success=success)
@app.route("/blog/ghprojects", methods=("GET",))
def projects():
return jsonify(loads(cacheit("projects", getProjects)))
# page routes
@cache.cached(timeout=50)
@app.route("/blog/posts/", methods=("GET",))
@ -107,7 +106,12 @@ def NeverWhere(configfile=None):
@cache.cached(timeout=50)
@app.route("/blog/links", methods=("GET",))
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)
@app.route("/blog/about", methods=("GET",))
@ -127,7 +131,9 @@ def NeverWhere(configfile=None):
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)
@ -201,6 +207,10 @@ def NeverWhere(configfile=None):
"""
return posts.links()
@app.route("/blog/ghprojects", methods=("GET",))
def projects():
return jsonify(loads(cacheit("projects", getProjects)))
return app
app = NeverWhere()

Loading…
Cancel
Save