mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-03-28 07:28:57 +08:00
wiki plugin
This commit is contained in:
@@ -3,9 +3,14 @@
|
||||
* .md 使用 4 空格缩进,文件名使用大驼峰用连字符分割
|
||||
* .coffee, *.js, *.json, *.html, *.less, *.jade 使用 2 空格缩进,文件名使用全小写用下划线分割
|
||||
|
||||
## 依赖
|
||||
|
||||
* 加入依赖时注意检查必须允许发布闭源版本,即不能使用 GPL 授权的依赖
|
||||
|
||||
## Node.js
|
||||
|
||||
* 优先使用单引号,总是在行末添加分号
|
||||
* 只在初始化时使用 Sync 版本的 IO 函数
|
||||
|
||||
## Coffee Script
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user