From 5f13503558edd0c56111f7b700379b410087514b Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 11 May 2015 18:09:13 +0800 Subject: [PATCH] aside with category --- components/button.md | 2 ++ components/select.md | 2 ++ package.json | 1 + static/style.css | 10 +++++++++- theme/templates/aside.html | 16 ++++++++++++---- theme/theme.js | 12 ++++++++++-- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/components/button.md b/components/button.md index fad5d5fc30..b7bb5c0bd2 100644 --- a/components/button.md +++ b/components/button.md @@ -1,5 +1,7 @@ # Button 按钮 +- category: Component + --- 这是一个按钮。 diff --git a/components/select.md b/components/select.md index d0af029681..eea01aeaca 100644 --- a/components/select.md +++ b/components/select.md @@ -1,5 +1,7 @@ # Select 选择框 +- category: Component + --- 这是一个下拉选择器。 diff --git a/package.json b/package.json index 4ae337f034..72a6638a15 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "gh-pages-cli": "~0.2.0", + "lodash": "~3.8.0", "nico": "*" }, "scripts": { diff --git a/static/style.css b/static/style.css index beeb8ee7a0..1712b7bf13 100644 --- a/static/style.css +++ b/static/style.css @@ -341,7 +341,15 @@ footer ul li > a { height: 100%; background: #F9F9F9; position: absolute; - padding-top: 30px; + padding-top: 15px; +} + +.aside-container li h4 { + font-size: 16px; + font-weight: bold; + padding-left: 50px; + margin: 10px 0; + color: #5C6B77; } .aside-container li a { diff --git a/theme/templates/aside.html b/theme/templates/aside.html index 7202b2999e..616525d399 100644 --- a/theme/templates/aside.html +++ b/theme/templates/aside.html @@ -1,10 +1,18 @@ +{%- set categories = resource.pages|get_all_category %} {%- set items = resource.pages|find_category(post.meta.category) %} diff --git a/theme/theme.js b/theme/theme.js index 80390cefa7..e7e06f22db 100644 --- a/theme/theme.js +++ b/theme/theme.js @@ -1,3 +1,5 @@ +var _ = require('lodash'); + module.exports = function(nico) { var exports = {}; @@ -10,9 +12,7 @@ module.exports = function(nico) { } if (filename === 'readme.md') { post.filename = post.meta.filename = 'index'; - post.meta.category = 'docs'; } - post.meta.category = post.meta.category || post.meta.directory; return post; }; @@ -37,6 +37,14 @@ module.exports = function(nico) { return parseInt(a, 10) - parseInt(b, 10); }); return ret; + }, + get_all_category: function(pages) { + return _.uniq(Object.keys(pages).map(function(key) { + var item = nico.sdk.post.read(key); + return item.meta.category; + }).filter(function(item) { + return item; + })); } };