Browse Source

switch to lists of categories since that makes way more sense

pull/1/head
wes 7 years ago
parent
commit
532f2db417
  1. 11
      src/posts.py
  2. 15
      src/scripts/app.tag
  3. 20
      src/scripts/categories.tag
  4. 36
      src/scripts/editor.tag
  5. 2
      src/scripts/post.tag
  6. 1
      src/templates/index.html
  7. 8
      src/website.py

11
src/posts.py

@ -7,6 +7,7 @@ from werkzeug.local import Local, LocalProxy, LocalManager
from couchdb.http import ResourceConflict, ResourceNotFound from couchdb.http import ResourceConflict, ResourceNotFound
from flask import jsonify, g from flask import jsonify, g
from flask_marshmallow import Marshmallow from flask_marshmallow import Marshmallow
from itertools import chain
def get_mistune(): def get_mistune():
markdown = getattr(g, "markdown", None) markdown = getattr(g, "markdown", None)
@ -128,16 +129,14 @@ class Posts:
return jsonify(False) return jsonify(False)
def categories(self): def categories(self):
return jsonify( return list(set(chain.from_iterable([
[
c["key"][1] for c in c["key"][1] for c in
self.db.view("blogPosts/categories", self.db.view("blogPosts/categories",
startkey=["category"], startkey=["categories"],
endkey=["category", {}], endkey=["categories", {}],
inclusive_end=False, inclusive_end=False,
reduce=True, reduce=True,
group_level=2, group_level=2,
group=True) group=True)
] ])))
)

15
src/scripts/app.tag

@ -19,7 +19,7 @@
<sidebar <sidebar
if={this.active.get("posts")} if={this.active.get("posts")}
name="Filter By Category" name="Filter By Category"
items={categories}> items={state.categories}>
</sidebar> </sidebar>
</section> </section>
@ -138,7 +138,8 @@ self.state = {
"title" : self.opts.title, "title" : self.opts.title,
"loaded" : false, "loaded" : false,
"initial" : document.getElementsByTagName("noscript")[0].textContent, "initial" : document.getElementsByTagName("noscript")[0].textContent,
"links" : JSON.parse(decodeURIComponent(self.opts.links)) "links" : JSON.parse(decodeURIComponent(self.opts.links)),
"categories" : JSON.parse(decodeURIComponent(self.opts.categories))
}; };
self.active = lens.actives({ self.active = lens.actives({
@ -207,15 +208,6 @@ to(name) {
}).bind(this); }).bind(this);
} }
function getcategories() {
window.cached("/blog/categories")
.then((resp) => resp.json())
.then((resp) => {
self.categories = resp;
self.update();
});
}
self.on("mount", () => { self.on("mount", () => {
self.route.base('/blog/') self.route.base('/blog/')
self.route("/", () => { self.route(`/posts/${self.state._id}`); }); self.route("/", () => { self.route(`/posts/${self.state._id}`); });
@ -226,7 +218,6 @@ self.on("mount", () => {
self.route("about", about); self.route("about", about);
self.route("links", links); self.route("links", links);
route.start(true); route.start(true);
getcategories();
}); });
</script> </script>

20
src/scripts/categories.tag

@ -0,0 +1,20 @@
<categories>
<div class="tags">
<i class="fa fa-tag" aria-hidden="true"></i>
<label
each="{category in categories}"
class="chip"
>
{category}
<button class="btn btn-clear"></button>
</label>
</div>
<script>
var self = this;
self.categories = ["programming", "python"];
</script>
</categories>

36
src/scripts/editor.tag

@ -8,18 +8,28 @@
{!this.isNewPost ? this.currentPost().title : "No Title"} by {!this.isNewPost ? this.currentPost().author : "No Author"} {!this.isNewPost ? this.currentPost().title : "No Title"} by {!this.isNewPost ? this.currentPost().author : "No Author"}
</span> </span>
</div> </div>
<button <div class="centered container">
class="btn btn-primary" <div class="columns">
onclick={goLeft} <div class="column col-6">
> <button
Prev style={{"float" : "right"}}
</button> class="btn btn-primary"
<button onclick={goLeft}
class="btn btn-primary" >
onclick={goRight} Prev
> </button>
Next </div>
</button> <div class="column col-6">
<button
style={{"float" : "left"}}
class="btn btn-primary"
onclick={goRight}
>
Next
</button>
</div>
</div>
</div>
<p> <p>
<span>title</span><input ref="title"> <span>title</span><input ref="title">
<span>author</span><input ref="author"></input> <span>author</span><input ref="author"></input>
@ -42,7 +52,7 @@
onblur={checkplaceholder} onblur={checkplaceholder}
oninput={echo} oninput={echo}
rows="10" rows="10"
cols="10" cols="30"
__disabled={""} __disabled={""}
class="editor form-input centered" class="editor form-input centered"
ref="textarea"> ref="textarea">

2
src/scripts/post.tag

@ -29,6 +29,7 @@
</p> </p>
<div class="divider"></div> <div class="divider"></div>
</div> </div>
<categories></categories>
</div> </div>
<div <div
data-is="postcontrols" data-is="postcontrols"
@ -45,6 +46,7 @@
import './raw.tag'; import './raw.tag';
import './social.tag'; import './social.tag';
import './postcontrols.tag'; import './postcontrols.tag';
import './categories.tag';
import route from 'riot-route'; import route from 'riot-route';
var self = this; var self = this;

1
src/templates/index.html

@ -23,6 +23,7 @@
window.addEventListener("load", function() { window.addEventListener("load", function() {
window.riot.mount("app", window.riot.mount("app",
{ {
categories: "{{ quote(categories) }}",
links : "{{ quote(links) }}", links : "{{ quote(links) }}",
page : "{{ page }}", page : "{{ page }}",
author : "{{ postcontent['author'] }}", author : "{{ postcontent['author'] }}",

8
src/website.py

@ -72,7 +72,8 @@ def NeverWhere(configfile=None):
"postid" : initial_post["_id"], "postid" : initial_post["_id"],
"postcontent" : postcontent, "postcontent" : postcontent,
"links" : dumps([]), "links" : dumps([]),
"projects" : dumps([]) "projects" : dumps([]),
"categories" : dumps(posts.categories())
} }
@login_manager.user_loader @login_manager.user_loader
@ -175,11 +176,6 @@ def NeverWhere(configfile=None):
def allposts(): def allposts():
return posts.allposts() return posts.allposts()
@cache.cached(timeout=10000)
@app.route("/blog/categories")
def categories():
return posts.categories()
# remove a post # remove a post
@app.route("/blog/deletepost/<_id>") @app.route("/blog/deletepost/<_id>")
@login_required @login_required

Loading…
Cancel
Save