From da4301680dabc59de7fc8262d3ec545db92f9aa5 Mon Sep 17 00:00:00 2001 From: jysperm Date: Tue, 30 Sep 2014 14:51:08 +0800 Subject: [PATCH] wiki plugin --- DOC/Coding-Style.md | 5 ++++ README.md | 2 +- plugin/wiki/index.coffee | 5 ++-- plugin/wiki/view/index.jade | 12 ++++++--- plugin/wiki/view/{wiki.jade => page.jade} | 0 plugin/wiki/wiki.coffee | 33 ++++++++++++----------- 6 files changed, 35 insertions(+), 22 deletions(-) rename plugin/wiki/view/{wiki.jade => page.jade} (100%) diff --git a/DOC/Coding-Style.md b/DOC/Coding-Style.md index 15e32ce..638e39e 100644 --- a/DOC/Coding-Style.md +++ b/DOC/Coding-Style.md @@ -3,9 +3,14 @@ * .md 使用 4 空格缩进,文件名使用大驼峰用连字符分割 * .coffee, *.js, *.json, *.html, *.less, *.jade 使用 2 空格缩进,文件名使用全小写用下划线分割 +## 依赖 + +* 加入依赖时注意检查必须允许发布闭源版本,即不能使用 GPL 授权的依赖 + ## Node.js * 优先使用单引号,总是在行末添加分号 +* 只在初始化时使用 Sync 版本的 IO 函数 ## Coffee Script diff --git a/README.md b/README.md index a102634..42787b5 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,6 @@ RootPanel 是一个高度插件化的,基于 Linux 的虚拟服务销售平台 ## 许可协议 -* 开源授权:[AGPLv3](https://github.com/jysperm/RootPanel/blob/master/LICENSE) | [CC-SA](http://creativecommons.org/licenses/sa/1.0/)(文档) | Public Domain(配置文件和示例) +* 开源授权:[AGPLv3](https://github.com/jysperm/RootPanel/blob/master/LICENSE) | [CC-SA](http://creativecommons.org/licenses/sa/1.0/) (文档) | Public Domain (配置文件和示例) * 商业授权(计划中) * 有关授权的 [FAQ](https://github.com/jysperm/RootPanel/blob/develop/FAQ.md#%E6%8E%88%E6%9D%83) diff --git a/plugin/wiki/index.coffee b/plugin/wiki/index.coffee index e5781a3..e389ec7 100644 --- a/plugin/wiki/index.coffee +++ b/plugin/wiki/index.coffee @@ -20,7 +20,8 @@ for category_name in fs.readdirSync("#{__dirname}/../../WIKI") t_category: category_name t_title: file_name language: 'zh_CN' - content_markdown: fs.readFileSync("#{__dirname}/../../WIKI/#{category_name}/#{file_name}") + content_markdown: fs.readFileSync("#{__dirname}/../../WIKI/#{category_name}/#{file_name}").toString() app.get '/wiki', renderAccount, wiki.index -app.use '/wiki', renderAccount, wiki.page + +app.get '/wiki/:category/:title', renderAccount, wiki.page diff --git a/plugin/wiki/view/index.jade b/plugin/wiki/view/index.jade index 92559c5..c23965d 100644 --- a/plugin/wiki/view/index.jade +++ b/plugin/wiki/view/index.jade @@ -1,7 +1,13 @@ extends ../../../core/view/layout -prepend head - title #{title} | #{config.web.name} +prepend header + title 用户手册 | #{config.web.name} block main - != content + for category in category_list + h2= category.category + ul + for page in category.pages + li + a(href="/wiki/#{category.t_category}/#{page.t_title}")= page.title + |   (#{page.language}) diff --git a/plugin/wiki/view/wiki.jade b/plugin/wiki/view/page.jade similarity index 100% rename from plugin/wiki/view/wiki.jade rename to plugin/wiki/view/page.jade diff --git a/plugin/wiki/wiki.coffee b/plugin/wiki/wiki.coffee index c6581bb..27bb578 100644 --- a/plugin/wiki/wiki.coffee +++ b/plugin/wiki/wiki.coffee @@ -1,7 +1,8 @@ -markdown = require('markdown').markdown +{markdown} = require 'markdown' path = require 'path' jade = require 'jade' fs = require 'fs' +_ = require 'underscore' {pluggable} = app @@ -20,27 +21,27 @@ exports.index = (req, res) -> for category_name, pages of pages_by_category result.push + t_category: category_name category: res.t category_name pages: pages - jade.renderFile "#{__dirname}/view/index.jade", + view_data = _.extend res.locals, category_list: result + jade.renderFile "#{__dirname}/view/index.jade", view_data, (err, html) -> + res.send html + exports.page = (req, res) -> - url = req.url.substr '/wiki'.length + matched_page = _.findWhere pluggable.selectHook(req.account, 'plugin.wiki.pages'), + t_category: req.params.category + t_title: req.params.title - unless url - url = 'README.md' + unless matched_page + return res.status(404).end() - filename = path.resolve path.join __dirname, '../../WIKI', url - baseDir = path.resolve path.join __dirname, '../../WIKI' + view_data = _.extend res.locals, + title: res.t matched_page.t_title + content: markdown.toHTML matched_page.content_markdown - unless filename[0 .. baseDir.length - 1] == baseDir - return res.status(403).end() - - fs.readFile filename, (err, data) -> - if err - return res.status(404).send err.toString() - res.render 'wiki', - title: url - content: markdown.toHTML data.toString() + jade.renderFile "#{__dirname}/view/page.jade", view_data, (err, html) -> + res.send html