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 flask import jsonify, g
from flask_marshmallow import Marshmallow
from itertools import chain
def get_mistune():
markdown = getattr(g, "markdown", None)
@ -128,16 +129,14 @@ class Posts:
return jsonify(False)
def categories(self):
return jsonify(
[
return list(set(chain.from_iterable([
c["key"][1] for c in
self.db.view("blogPosts/categories",
startkey=["category"],
endkey=["category", {}],
startkey=["categories"],
endkey=["categories", {}],
inclusive_end=False,
reduce=True,
group_level=2,
group=True)
]
)
])))

15
src/scripts/app.tag

@ -19,7 +19,7 @@
<sidebar
if={this.active.get("posts")}
name="Filter By Category"
items={categories}>
items={state.categories}>
</sidebar>
</section>
@ -138,7 +138,8 @@ self.state = {
"title" : self.opts.title,
"loaded" : false,
"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({
@ -207,15 +208,6 @@ to(name) {
}).bind(this);
}
function getcategories() {
window.cached("/blog/categories")
.then((resp) => resp.json())
.then((resp) => {
self.categories = resp;
self.update();
});
}
self.on("mount", () => {
self.route.base('/blog/')
self.route("/", () => { self.route(`/posts/${self.state._id}`); });
@ -226,7 +218,6 @@ self.on("mount", () => {
self.route("about", about);
self.route("links", links);
route.start(true);
getcategories();
});
</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"}
</span>
</div>
<button
class="btn btn-primary"
onclick={goLeft}
>
Prev
</button>
<button
class="btn btn-primary"
onclick={goRight}
>
Next
</button>
<div class="centered container">
<div class="columns">
<div class="column col-6">
<button
style={{"float" : "right"}}
class="btn btn-primary"
onclick={goLeft}
>
Prev
</button>
</div>
<div class="column col-6">
<button
style={{"float" : "left"}}
class="btn btn-primary"
onclick={goRight}
>
Next
</button>
</div>
</div>
</div>
<p>
<span>title</span><input ref="title">
<span>author</span><input ref="author"></input>
@ -42,7 +52,7 @@
onblur={checkplaceholder}
oninput={echo}
rows="10"
cols="10"
cols="30"
__disabled={""}
class="editor form-input centered"
ref="textarea">

2
src/scripts/post.tag

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

1
src/templates/index.html

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

8
src/website.py

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

Loading…
Cancel
Save