From 06a97ff5cb9003a50867afbf16180c424864408d Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 9 May 2015 17:36:15 +0800 Subject: [PATCH] update --- nico.js | 26 +++++++++++++++ nico.json | 13 -------- package.json | 2 +- theme/templates/aside.html | 9 +++++- theme/templates/component.html | 2 +- theme/templates/layout.html | 5 ++- theme/theme.js | 58 +++++++++++++++++++++++++--------- 7 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 nico.js delete mode 100644 nico.json diff --git a/nico.js b/nico.js new file mode 100644 index 0000000000..02e71cef3d --- /dev/null +++ b/nico.js @@ -0,0 +1,26 @@ +var path = require('path'); + +// {{ settings for nico +exports.theme = 'theme'; +exports.source = process.cwd(); +exports.output = path.join(process.cwd(), '_site'); +exports.permalink = '{{directory}}/{{filename}}'; +exports.ignorefilter = function(filepath, subdir) { + var extname = path.extname(filepath); + if (extname === '.tmp' || extname === '.bak') { + return false; + } + if (/\.DS_Store/.test(filepath)) { + return false; + } + if (/^(_site|_theme|node_modules|\.idea)/.test(subdir)) { + return false; + } + return true; +}; +exports.writers = [ + 'nico.PageWriter', + 'nico.StaticWriter', + 'nico.FileWriter' +]; +// end settings }} diff --git a/nico.json b/nico.json deleted file mode 100644 index e73d8eed4c..0000000000 --- a/nico.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "source": ".", - "output": "_site", - "theme": "theme", - "sitename": "Ant Design", - "siteurl": "", - "permalink": "{{directory}}/{{filename}}", - "writers": [ - "nico.PageWriter", - "nico.FileWriter", - "nico.StaticWriter" - ] -} diff --git a/package.json b/package.json index bee56a9d41..4ae337f034 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "scripts": { "build": "npm run clean && nico build", - "start": "npm run clean && nico server", + "start": "npm run clean && nico server --watch", "clean": "rm -rf _site", "deploy": "npm run build && gh-pages -d _site -b master" } diff --git a/theme/templates/aside.html b/theme/templates/aside.html index 74798d3091..092bbc7795 100644 --- a/theme/templates/aside.html +++ b/theme/templates/aside.html @@ -1 +1,8 @@ -aside +{%- set items = resource.pages|find_category(post.meta.category) %} + diff --git a/theme/templates/component.html b/theme/templates/component.html index a401ad077e..91e0cfc508 100644 --- a/theme/templates/component.html +++ b/theme/templates/component.html @@ -3,7 +3,7 @@ {% block title %}{{post.title}} - {{config.site.name}}{% endblock %} {% block description %}{% if post.summay %}{{post.summary}}{% endif %}{% endblock %} {% block main -%} - {%- include "aside.html" %} +{%- include "aside.html" %}

{{ post.title }}

{{ post.html }} diff --git a/theme/templates/layout.html b/theme/templates/layout.html index 57fc04b6cb..e7f9ad89df 100644 --- a/theme/templates/layout.html +++ b/theme/templates/layout.html @@ -29,7 +29,7 @@
  • 原则
  • -
  • 组件 +
  • 组件
  • 模式
  • @@ -41,6 +41,9 @@ + {%- if post.meta.template === 'component' %} + {%- include "aside.html" %} + {%- endif %} {%- if post.filename === 'index' %}
    diff --git a/theme/theme.js b/theme/theme.js index 706aa77b55..80390cefa7 100644 --- a/theme/theme.js +++ b/theme/theme.js @@ -1,16 +1,44 @@ -exports.reader = function(post) { - var filename = post.meta.filepath.toLowerCase(); - if (filename.indexOf('components') >= 0) { - post.template = post.meta.template = 'component'; - } else { - post.template = post.meta.template = (post.meta.template || 'page'); - } - if (filename === 'readme.md') { - post.filename = post.meta.filename = 'index'; - post.meta.category = 'docs'; - } - if (!post.meta.category) { - post.meta.category = post.meta.directory; - } - return post; +module.exports = function(nico) { + var exports = {}; + + exports.reader = function(post) { + var filename = post.meta.filepath.toLowerCase(); + if (filename.indexOf('components') >= 0) { + post.template = post.meta.template = 'component'; + } else { + post.template = post.meta.template = (post.meta.template || 'page'); + } + 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; + }; + + exports.filters = { + find_category: function(pages, cat) { + var ret = []; + Object.keys(pages).forEach(function(key) { + var item = nico.sdk.post.read(key); + if (item.meta.category === cat) { + ret.push(item); + } + }); + ret = ret.sort(function(a, b) { + if (/index$/i.test(a.filename)) { + a.meta.order = 1; + } + if (/index$/i.test(b.filename)) { + b.meta.order = 1; + } + a = a.meta.order || 10; + b = b.meta.order || 10; + return parseInt(a, 10) - parseInt(b, 10); + }); + return ret; + } + }; + + return exports; };