页内目录生成功能
This commit is contained in:
parent
dccde88723
commit
42be16d87b
|
|
@ -66,4 +66,4 @@ amWiki是一套非常简单基于atom编辑器的轻量级wiki文库系统。
|
|||
## 如何使用
|
||||
1. 使用http访问项目的index.html
|
||||
2. PC端使用左侧导航栏、移动端使用右上角导航弹出菜单切换页面
|
||||
3. 在导航栏或导航菜单顶部,可以使用栏位对导航目录进行**包含筛选**
|
||||
3. 在导航栏或导航菜单顶部,可以使用  栏位对导航目录进行**包含筛选**
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@
|
|||
.markdown-body{font-size:14px;}
|
||||
.markdown-body code{padding-top:0.15em;padding-bottom:0.15em;margin:0 1px;font-size:90%;color:#000;background-color:rgba(0,0,0,0.05);}
|
||||
.markdown-body code.hljs{color:#333;}
|
||||
.hljs-string{color:#183691;}
|
||||
.hljs-built_in{color:#0086b3;}
|
||||
.markdown-body .hljs-string{color:#183691;}
|
||||
.markdown-body .hljs-built_in{color:#0086b3;}
|
||||
.markdown-body .anchor{margin-right:2px;margin-left:-20px;}
|
||||
.markdown-body blockquote{padding:8px 15px;background-color:#fafafa;}
|
||||
.markdown-body .anchor img{visibility:hidden;}
|
||||
.markdown-body h1:hover .anchor img,.markdown-body h2:hover .anchor img,.markdown-body h3:hover .anchor img{visibility:visible;}
|
||||
|
||||
/* ---------- base ---------- */
|
||||
body{background:#e7e8eb !important;min-width:720px;}
|
||||
|
|
@ -58,9 +62,6 @@ body{background:#e7e8eb !important;min-width:720px;}
|
|||
.menubar ul li a.on{color:#007ed9;background:#f4f5f9;}
|
||||
|
||||
.main{padding:45px;margin-left:250px;}
|
||||
.main .markdown-body .anchor{margin-right:2px;margin-left:-20px;}
|
||||
.main .anchor img{visibility:hidden;}
|
||||
.main h1:hover .anchor img,.main h2:hover .anchor img,.main h3:hover .anchor img{visibility:visible;}
|
||||
|
||||
/* ---------- response ---------- */
|
||||
@media screen and (max-width:720px){
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ $(function () {
|
|||
//菜单折叠
|
||||
var $menuBar = $('#menuBar');
|
||||
$menuBar.on('click', 'i', function () {
|
||||
var $this = $(this);
|
||||
if ($this.hasClass('on')) {
|
||||
$this.removeClass('on');
|
||||
$menuBar.find('h5').removeClass('on').next('ul').hide();
|
||||
} else {
|
||||
$this.addClass('on');
|
||||
$menuBar.find('h5').addClass('on').next('ul').show();
|
||||
}
|
||||
var $this = $(this);
|
||||
if ($this.hasClass('on')) {
|
||||
$this.removeClass('on');
|
||||
$menuBar.find('h5').removeClass('on').next('ul').hide();
|
||||
} else {
|
||||
$this.addClass('on');
|
||||
$menuBar.find('h5').addClass('on').next('ul').show();
|
||||
}
|
||||
});
|
||||
$menuBar.on('click', 'h5', function () {
|
||||
var $this = $(this),
|
||||
|
|
@ -83,7 +83,7 @@ $(function () {
|
|||
//读取导航目录
|
||||
$.get('library/_navigation_.md', function (data) {
|
||||
$menuBar.html(marked(data));
|
||||
$menuBar.prepend('<i title="展开/折叠导航栏所有菜单"></i>');
|
||||
$menuBar.prepend('<i title="展开/折叠导航栏所有菜单"></i>');
|
||||
setView();
|
||||
}, 'text');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
# 客户日志流水接口
|
||||
|
||||
## 接口简介
|
||||
实时查询客户各种操作(例如登录,拓客等)的流水日志
|
||||
|
||||
## 接口详情
|
||||
|
||||
### 请求地址
|
||||
/cloud/customer-flow
|
||||
/api/customer-flow
|
||||
|
||||
### 请求类型
|
||||
GET
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
var fs = require("fs");
|
||||
|
||||
module.exports = {
|
||||
make: function (editorPath) {
|
||||
console.log(editorPath);
|
||||
var arc = fs.readFileSync(editorPath, 'utf-8');
|
||||
var lines = arc.split('\n');
|
||||
if (lines.length == 1) {
|
||||
lines = lines[0].split('\r');
|
||||
}
|
||||
var contents = '';
|
||||
var lineStr = '';
|
||||
var hashStr = '';
|
||||
var h1 = '';
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
lines[i] = lines[i].replace(/^\s*/, '');
|
||||
switch (lines[i].split(/\s/)[0]) {
|
||||
case '#':
|
||||
lineStr = lines[i].split('# ')[1].replace(/^\s+|\s+$/g, '');
|
||||
h1 = h1 == '' ? lineStr.replace(/\[(.*?)\]\(.*?\)/g, '$1') : h1;
|
||||
break;
|
||||
case '##':
|
||||
//去除首位空格
|
||||
lineStr = lines[i].split('## ')[1].replace(/^\s+|\s+$/g, '');
|
||||
//去除链接
|
||||
lineStr = lineStr.replace(/\[(.*?)\]\(.*?\)/g, '$1');
|
||||
//去除所有空格
|
||||
hashStr = lineStr.replace(/\s+/g, '');
|
||||
//添加内容
|
||||
contents += '1. [' + lineStr + '](#' + hashStr + ' "' + lineStr + '")\n';
|
||||
break;
|
||||
case '###':
|
||||
lineStr = lines[i].split('### ')[1].replace(/^\s+|\s+$/g, '');
|
||||
lineStr = lineStr.replace(/\[(.*?)\]\(.*?\)/g, '$1');
|
||||
hashStr = lineStr.replace(/\s+/g, '');
|
||||
contents += '\t1. [' + lineStr + '](#' + hashStr + ' "' + lineStr + '")\n';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (contents.substr(0,2) != '1.') {
|
||||
contents = '1. ' + h1 + '\n' + contents;
|
||||
}
|
||||
contents = '>' + contents;
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
170
lib/creator.js
170
lib/creator.js
|
|
@ -19,44 +19,44 @@ var readDir = function (path, callback) {
|
|||
};
|
||||
|
||||
//复制文件
|
||||
var copyFile = function(from, to){
|
||||
var encoding = from.indexOf('png') >= 0 ? 'binary' : 'utf-8';
|
||||
var file = fs.readFileSync(from, encoding);
|
||||
fs.writeFileSync(to, file, encoding);
|
||||
var copyFile = function (from, to) {
|
||||
var encoding = from.indexOf('png') >= 0 ? 'binary' : 'utf-8';
|
||||
var file = fs.readFileSync(from, encoding);
|
||||
fs.writeFileSync(to, file, encoding);
|
||||
};
|
||||
|
||||
//创建amWiki需要的文件夹
|
||||
var createDir = function(outputPath){
|
||||
if(!fs.existsSync(outputPath + 'amWiki/')){
|
||||
fs.mkdirSync(outputPath + 'amWiki/', 0777);
|
||||
}
|
||||
if(!fs.existsSync(outputPath + 'amWiki/js/')){
|
||||
fs.mkdirSync(outputPath + 'amWiki/js/', 0777);
|
||||
}
|
||||
if(!fs.existsSync(outputPath + 'amWiki/css')){
|
||||
fs.mkdirSync(outputPath + 'amWiki/css', 0777);
|
||||
}
|
||||
if(!fs.existsSync(outputPath + 'amWiki/images')){
|
||||
fs.mkdirSync(outputPath + 'amWiki/images', 0777);
|
||||
}
|
||||
if(!fs.existsSync(outputPath + 'library/')){
|
||||
fs.mkdirSync(outputPath + 'library/', 0777);
|
||||
if(!fs.existsSync(outputPath + 'library/01-关于amWiki')){
|
||||
fs.mkdirSync(outputPath + 'library/01-关于amWiki', 0777);
|
||||
}
|
||||
if(!fs.existsSync(outputPath + 'library/02-学习markdown')){
|
||||
fs.mkdirSync(outputPath + 'library/02-学习markdown', 0777);
|
||||
}
|
||||
if(!fs.existsSync(outputPath + 'library/03-文档示范')){
|
||||
fs.mkdirSync(outputPath + 'library/03-文档示范', 0777);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
var createDir = function (outputPath) {
|
||||
if (!fs.existsSync(outputPath + 'amWiki/')) {
|
||||
fs.mkdirSync(outputPath + 'amWiki/', 0777);
|
||||
}
|
||||
if (!fs.existsSync(outputPath + 'amWiki/js/')) {
|
||||
fs.mkdirSync(outputPath + 'amWiki/js/', 0777);
|
||||
}
|
||||
if (!fs.existsSync(outputPath + 'amWiki/css')) {
|
||||
fs.mkdirSync(outputPath + 'amWiki/css', 0777);
|
||||
}
|
||||
if (!fs.existsSync(outputPath + 'amWiki/images')) {
|
||||
fs.mkdirSync(outputPath + 'amWiki/images', 0777);
|
||||
}
|
||||
if (!fs.existsSync(outputPath + 'library/')) {
|
||||
fs.mkdirSync(outputPath + 'library/', 0777);
|
||||
if (!fs.existsSync(outputPath + 'library/01-关于amWiki')) {
|
||||
fs.mkdirSync(outputPath + 'library/01-关于amWiki', 0777);
|
||||
}
|
||||
if (!fs.existsSync(outputPath + 'library/02-学习markdown')) {
|
||||
fs.mkdirSync(outputPath + 'library/02-学习markdown', 0777);
|
||||
}
|
||||
if (!fs.existsSync(outputPath + 'library/03-文档示范')) {
|
||||
fs.mkdirSync(outputPath + 'library/03-文档示范', 0777);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
//创建amWiki本地文件
|
||||
//创建amWiki本地文件
|
||||
buildAt: function (editorPath, configPath) {
|
||||
if (editorPath.indexOf('config.json') < 0) {
|
||||
alert('当前不是"config.json"文件!');
|
||||
|
|
@ -66,67 +66,69 @@ module.exports = {
|
|||
var outputPath = editorPath.split('config.json')[0].replace(/\\/g, '/');
|
||||
|
||||
var config = fs.readFileSync(editorPath, 'utf-8');
|
||||
if (config.length == 0) {
|
||||
if (!confirm('没有读取到任何配置,继续创建么?')){
|
||||
return;
|
||||
}
|
||||
if (config.length == 0) {
|
||||
if (!confirm('没有读取到任何配置,继续创建么?')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//默认配置
|
||||
config = JSON.parse(config);
|
||||
config.name = config.name || 'amWiki文档库系统';
|
||||
config.version = typeof config.version == 'string' ? config.version : 'by Tevin';
|
||||
|
||||
fs.readdir(outputPath, function (err, files) {
|
||||
if (files.length > 1) {
|
||||
if (!confirm('此处已有一些文件或文件夹,是否仍然在此创建amWiki?')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
var index = fs.readFileSync(filesPath + 'index.tmp', 'utf-8');
|
||||
index = index.replace(/\{\{name\}\}/g, config.name).replace('{{version}}', config.version);
|
||||
fs.writeFileSync(outputPath + 'index.html', index, 'utf-8');
|
||||
fs.readdir(outputPath, function (err, files) {
|
||||
if (files.length > 1) {
|
||||
if (!confirm('此处已有一些文件或文件夹,是否仍然在此创建amWiki?')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
var index = fs.readFileSync(filesPath + 'index.tmp', 'utf-8');
|
||||
index = index.replace(/\{\{name\}\}/g, config.name).replace('{{version}}', config.version);
|
||||
fs.writeFileSync(outputPath + 'index.html', index, 'utf-8');
|
||||
|
||||
var hasLibrary = createDir(outputPath);
|
||||
var fileList = [
|
||||
['primercss.github.css', 'amWiki/css/primercss.github.css'],
|
||||
['lhjs.github-gist.css', 'amWiki/css/lhjs.github-gist.css'],
|
||||
['amWiki.css', 'amWiki/css/amWiki.css'],
|
||||
['forEach.js', 'amWiki/js/forEach.js'],
|
||||
['jquery-1.11.3.min.js', 'amWiki/js/jquery-1.11.3.min.js'],
|
||||
['marked.min.js', 'amWiki/js/marked.min.js'],
|
||||
['highlight.min.js', 'amWiki/js/highlight.min.js'],
|
||||
['amWiki.js', 'amWiki/js/amWiki.js'],
|
||||
['icon_close.png', 'amWiki/images/icon_close.png'],
|
||||
['icon_arrow_blue.png', 'amWiki/images/icon_arrow_blue.png'],
|
||||
['icon_arrow_gray.png', 'amWiki/images/icon_arrow_gray.png'],
|
||||
['icon_filter.png', 'amWiki/images/icon_filter.png'],
|
||||
['icon_link.png', 'amWiki/images/icon_link.png'],
|
||||
['icon_home.png', 'amWiki/images/icon_home.png'],
|
||||
['icon_menu.png', 'amWiki/images/icon_menu.png'],
|
||||
['logo.png', 'amWiki/images/logo.png'],
|
||||
['menubar_bg.png', 'amWiki/images/menubar_bg.png'],
|
||||
['point.png', 'amWiki/images/point.png']
|
||||
]
|
||||
for (var i = 0; i < fileList.length; i++) {
|
||||
copyFile(filesPath + fileList[i][0], outputPath + fileList[i][1]);
|
||||
}
|
||||
var hasLibrary = createDir(outputPath);
|
||||
var fileList = [
|
||||
['primercss.github.css', 'amWiki/css/primercss.github.css'],
|
||||
['lhjs.github-gist.css', 'amWiki/css/lhjs.github-gist.css'],
|
||||
['amWiki.css', 'amWiki/css/amWiki.css'],
|
||||
['forEach.js', 'amWiki/js/forEach.js'],
|
||||
['jquery-1.11.3.min.js', 'amWiki/js/jquery-1.11.3.min.js'],
|
||||
['marked.min.js', 'amWiki/js/marked.min.js'],
|
||||
['highlight.min.js', 'amWiki/js/highlight.min.js'],
|
||||
['amWiki.js', 'amWiki/js/amWiki.js'],
|
||||
['icon_close.png', 'amWiki/images/icon_close.png'],
|
||||
['icon_arrow_blue.png', 'amWiki/images/icon_arrow_blue.png'],
|
||||
['icon_arrow_gray.png', 'amWiki/images/icon_arrow_gray.png'],
|
||||
['icon_filter.png', 'amWiki/images/icon_filter.png'],
|
||||
['icon_link.png', 'amWiki/images/icon_link.png'],
|
||||
['icon_to_unfolding.png', 'amWiki/images/icon_to_unfolding.png'],
|
||||
['icon_to_folding.png', 'amWiki/images/icon_to_folding.png'],
|
||||
['icon_home.png', 'amWiki/images/icon_home.png'],
|
||||
['icon_menu.png', 'amWiki/images/icon_menu.png'],
|
||||
['logo.png', 'amWiki/images/logo.png'],
|
||||
['menubar_bg.png', 'amWiki/images/menubar_bg.png'],
|
||||
['point.png', 'amWiki/images/point.png']
|
||||
]
|
||||
for (var i = 0; i < fileList.length; i++) {
|
||||
copyFile(filesPath + fileList[i][0], outputPath + fileList[i][1]);
|
||||
}
|
||||
|
||||
if(!hasLibrary){
|
||||
var home = fs.readFileSync(filesPath + 'home.md', 'utf-8');
|
||||
home = home.replace('{{name}}', config.name);
|
||||
fs.writeFileSync(outputPath + 'library/首页.md', home, 'utf-8');
|
||||
var fileList2 = [
|
||||
['../README.md', 'library/01-关于amWiki/001-了解amWiki文库.md'],
|
||||
['markdown.md', 'library/02-学习markdown/001-markdown快速开始.md'],
|
||||
['highlighting.md', 'library/02-学习markdown/002-markdown语法高亮.md'],
|
||||
['apidemo.md', 'library/03-文档示范/001-通用API文档示例.md']
|
||||
];
|
||||
for (var j = 0; j < fileList2.length; j++) {
|
||||
copyFile(filesPath + fileList2[j][0], outputPath + fileList2[j][1]);
|
||||
}
|
||||
}
|
||||
if (!hasLibrary) {
|
||||
var home = fs.readFileSync(filesPath + 'home.md', 'utf-8');
|
||||
home = home.replace('{{name}}', config.name);
|
||||
fs.writeFileSync(outputPath + 'library/首页.md', home, 'utf-8');
|
||||
var fileList2 = [
|
||||
['../README.md', 'library/01-关于amWiki/001-了解amWiki文库.md'],
|
||||
['markdown.md', 'library/02-学习markdown/001-markdown快速开始.md'],
|
||||
['highlighting.md', 'library/02-学习markdown/002-markdown语法高亮.md'],
|
||||
['apidemo.md', 'library/03-文档示范/001-通用API文档示例.md']
|
||||
];
|
||||
for (var j = 0; j < fileList2.length; j++) {
|
||||
copyFile(filesPath + fileList2[j][0], outputPath + fileList2[j][1]);
|
||||
}
|
||||
}
|
||||
|
||||
navUpdate.updateNav(outputPath + 'library/');
|
||||
navUpdate.updateNav(outputPath + 'library/');
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{CompositeDisposable,File,Directory} = require 'atom'
|
||||
navUpdate = require './navUpdate'
|
||||
createLibrary = require './creator'
|
||||
creator = require './creator'
|
||||
contents = require './contents'
|
||||
|
||||
module.exports =
|
||||
|
||||
|
|
@ -13,7 +14,8 @@ module.exports =
|
|||
'amWiki:updateNav': => @updateNav()
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
'amWiki:create': => @createWiki()
|
||||
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
'amWiki:contents': => @makeContents()
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
'amWiki:pasteImg': => @pasterImg()
|
||||
|
||||
|
|
@ -32,7 +34,16 @@ module.exports =
|
|||
editor = atom.workspace.getActiveTextEditor()
|
||||
return unless editor
|
||||
# console.log(atom);
|
||||
createLibrary.buildAt(editor.getPath(), atom.configDirPath)
|
||||
creator.buildAt(editor.getPath(), atom.configDirPath)
|
||||
|
||||
makeContents: ->
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
return unless editor
|
||||
grammar = editor.getGrammar()
|
||||
return unless grammar
|
||||
return unless grammar.scopeName is 'source.gfm'
|
||||
ct = contents.make(editor.getPath()) or ''
|
||||
@insertText ct, editor
|
||||
|
||||
pasterImg: ->
|
||||
# console.log('pasterImg')
|
||||
|
|
@ -70,7 +81,7 @@ module.exports =
|
|||
# ascClip = "assets/#{filename}"
|
||||
# clipboard.writeText(ascClip)
|
||||
|
||||
@insertUrl ".getBaseName()}/#{filename})",editor
|
||||
@insertText ".getBaseName()}/#{filename})", editor
|
||||
|
||||
return false
|
||||
|
||||
|
|
@ -92,7 +103,7 @@ module.exports =
|
|||
# console.log('finish clip image')
|
||||
callback()
|
||||
|
||||
insertUrl: (url,editor) ->
|
||||
insertText: (url, editor) ->
|
||||
editor.insertText(url)
|
||||
|
||||
deactivate: ->
|
||||
|
|
|
|||
|
|
@ -19,20 +19,20 @@ var readDir = function (path, callback) {
|
|||
module.exports = {
|
||||
updateNav: function (editorPath) {
|
||||
if (editorPath.indexOf('library') < 0) {
|
||||
alert('只有当你打开一个位于library文件夹下的文件时,才能更新“_navigation_.md”!');
|
||||
alert('只有当你打开一个位于library文件夹下的文件时,才能更新“_navigation_.md”!');
|
||||
return;
|
||||
}
|
||||
var path = editorPath.split('library')[0] + 'library/';
|
||||
readDir(path, function (err, data) {
|
||||
if (!err) {
|
||||
var markdown = '';
|
||||
markdown += '\n#### [首页](?file=首页 "返回首页") ####\n';
|
||||
markdown += '\n#### [首页](?file=首页 "返回首页")\n';
|
||||
for (var dir in data) {
|
||||
if (data.hasOwnProperty(dir)) {
|
||||
if (dir == 'assets') {
|
||||
continue;
|
||||
}
|
||||
markdown += '\n##### ' + dir.substring(3) + ' #####\n';
|
||||
markdown += '\n##### ' + dir.substring(3) + '\n';
|
||||
for (var i = 0; i < data[dir].length; i++) {
|
||||
var name = data[dir][i].split('.md')[0];
|
||||
markdown += '- [' + name.substring(4) + '](?file=' +
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
'menu': [
|
||||
{
|
||||
'label': 'Packages'
|
||||
'submenu': [{
|
||||
'label': 'amWiki 文库',
|
||||
'submenu': [{
|
||||
'label': '通过 “config.json” 创建新amWiki文库',
|
||||
'command': 'amWiki:create'
|
||||
},{
|
||||
'label': '提取h1-h3标题为页内目录',
|
||||
'command': 'amWiki:contents'
|
||||
},{
|
||||
'label': '手动刷新 “_navigation_.md”',
|
||||
'command': 'amWiki:updateNav'
|
||||
}]
|
||||
'menu': [{
|
||||
'label': 'Packages',
|
||||
'submenu': [{
|
||||
'label': 'amWiki 文库',
|
||||
'submenu': [{
|
||||
'label': '通过 “config.json” 创建新amWiki文库',
|
||||
'command': 'amWiki:create'
|
||||
}, {
|
||||
'label': '提取h2、h3标题为页内目录',
|
||||
'command': 'amWiki:contents'
|
||||
}, {
|
||||
'label': '手动刷新 “_navigation_.md”',
|
||||
'command': 'amWiki:updateNav'
|
||||
}]
|
||||
}]
|
||||
}
|
||||
]
|
||||
}]
|
||||
|
|
|
|||
Loading…
Reference in New Issue