Browse Source

aside with category

pull/4/head
afc163 10 years ago
parent
commit
5f13503558
  1. 2
      components/button.md
  2. 2
      components/select.md
  3. 1
      package.json
  4. 10
      static/style.css
  5. 16
      theme/templates/aside.html
  6. 12
      theme/theme.js

2
components/button.md

@ -1,5 +1,7 @@
# Button 按钮
- category: Component
---
这是一个按钮。

2
components/select.md

@ -1,5 +1,7 @@
# Select 选择框
- category: Component
---
这是一个下拉选择器。

1
package.json

@ -12,6 +12,7 @@
},
"dependencies": {
"gh-pages-cli": "~0.2.0",
"lodash": "~3.8.0",
"nico": "*"
},
"scripts": {

10
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 {

16
theme/templates/aside.html

@ -1,10 +1,18 @@
{%- set categories = resource.pages|get_all_category %}
{%- set items = resource.pages|find_category(post.meta.category) %}
<aside class="aside-container">
<ul>
{%- for item in items %}
<li class="{%- if item.title === post.title %}current{%- endif %}">
<a href="{{permalink_url(item)}}">{{item.title}}</a>
{%- for category in categories %}
<li>
<h4>{{category}}</h4>
<ul>
{%- for item in items %}
<li class="{%- if item.title === post.title %}current{%- endif %}">
<a href="{{permalink_url(item)}}">{{item.title}}</a>
</li>
{%- endfor %}
</ul>
</li>
{%- endfor %}
{%- endfor %}
</ul>
</aside>

12
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;
}));
}
};

Loading…
Cancel
Save