恢复自动更新nav
This commit is contained in:
parent
6d04ec66a1
commit
d072ea12a9
10
README.md
10
README.md
|
|
@ -40,7 +40,7 @@ amWiki是一套非常简单基于atom编辑器markdown语法的轻量级wiki文
|
|||
|
||||
Packages -> amWiki文库 -> 通过“config.json”文件创建新amWiki文库
|
||||
|
||||
7. 此时项目中自动创建了许多内容,其中library目录即为您的文档库
|
||||
7. 此时项目中自动创建了许多内容,其中library文件夹即为您的文档库
|
||||
|
||||
8. 使用http访问刚刚自动创建的index.html
|
||||
|
||||
|
|
@ -53,10 +53,10 @@ amWiki是一套非常简单基于atom编辑器markdown语法的轻量级wiki文
|
|||
├ _navigation_.md //amWiki文库目录导航文件,可自动/手动更新
|
||||
├ 首页.md //内容区默认显示内容
|
||||
├ 01-关于amWiki文库/ //markdown文件夹01
|
||||
│ ├ 001-关于amWiki //一些markdown文档,不支持更深的目录
|
||||
│ ├ 001-关于amWiki //一些markdown文档,不支持更深的文件夹
|
||||
│ └ 002-...
|
||||
├ 02-学习markdown/ //markdown文件夹02
|
||||
│ ├ 001-md入门 //一些markdown文档,不支持更深的目录
|
||||
│ ├ 001-md入门 //一些markdown文档,不支持更深的文件夹
|
||||
│ └ 002-...
|
||||
└ 03-... //更多markdown文件夹
|
||||
(assetes/) //如果您粘帖截图,图片文件将自动创建在此处
|
||||
|
|
@ -71,13 +71,13 @@ amWiki是一套非常简单基于atom编辑器markdown语法的轻量级wiki文
|
|||
|
||||
4. library文件夹下`首页.md`为打开时默认的或url hash错误时的显示内容
|
||||
|
||||
5. `_navigation_.md`目录导航文件无需人工维护,创建新文件夹或文件时将自动更新,也可以在菜单栏
|
||||
5. `_navigation_.md`导航文件无需人工维护,创建新文件夹或文件时将自动更新,也可以在菜单栏
|
||||
|
||||
Packages -> amWiki文库 -> 手动刷新“\_navigation\_.md”
|
||||
6. 如果需要在markdown文档中插入图片,请先截图,然后在.md文档对应位置使用
|
||||
|
||||
Ctrl + Shift + V
|
||||
6. 对于较长文章,你可以使用
|
||||
6. 对于较长文章,可以使用页内目录
|
||||
|
||||
Packages -> amWiki文库 -> 提取h2、h3标题为页内目录
|
||||
即可在光标处插入。
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ module.exports =
|
|||
|
||||
activate: (state) ->
|
||||
@subscriptions = new CompositeDisposable()
|
||||
@updateNav('watchDir')
|
||||
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
'amWiki:updateNav': => @updateNav()
|
||||
'amWiki:updateNav': => @updateNav('updateNav')
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
'amWiki:create': => @createWiki()
|
||||
@subscriptions.add atom.commands.add 'atom-workspace',
|
||||
|
|
@ -22,13 +23,16 @@ module.exports =
|
|||
destroy: ->
|
||||
@subscriptions.dispose()
|
||||
|
||||
updateNav: ->
|
||||
updateNav: (type) ->
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
return unless editor
|
||||
grammar = editor.getGrammar()
|
||||
return unless grammar
|
||||
return unless grammar.scopeName is 'source.gfm'
|
||||
navUpdate.updateNav(editor.getPath())
|
||||
if type == 'updateNav'
|
||||
navUpdate.updateNav(editor.getPath())
|
||||
else if type == 'watchDir'
|
||||
navUpdate.watchDir(editor.getPath())
|
||||
|
||||
createWiki: ->
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
|
|
@ -66,9 +70,19 @@ module.exports =
|
|||
|
||||
thefile = new File(editor.getPath())
|
||||
|
||||
return unless thefile.getParent().getParent().getBaseName() is 'library'
|
||||
|
||||
assetsDirPath = thefile.getParent().getParent().getPath()+"/assets"
|
||||
if thefile.getParent().getParent().getBaseName() is 'library'
|
||||
assetsDirPath = thefile.getParent().getParent().getParent().getPath()+"/assets"
|
||||
creatDirPath = assetsDirPath+'/'+thefile.getParent().getBaseName()
|
||||
writePath = assetsDirPath+'/'+thefile.getParent().getBaseName()+'/'
|
||||
insertPath = thefile.getParent().getBaseName()+'/'
|
||||
else
|
||||
if thefile.getParent().getBaseName() is 'library'
|
||||
assetsDirPath = thefile.getParent().getParent().getPath()+"/assets"
|
||||
creatDirPath = assetsDirPath+'/'
|
||||
writePath = assetsDirPath+'/'
|
||||
insertPath = ''
|
||||
else
|
||||
return
|
||||
|
||||
crypto = require "crypto"
|
||||
md5 = crypto.createHash 'md5'
|
||||
|
|
@ -76,12 +90,12 @@ module.exports =
|
|||
|
||||
filename = "#{thefile.getBaseName().replace(/\.\w+$/, '').replace(/\s+/g,'')}-#{md5.digest('hex').slice(0,5)}.png"
|
||||
|
||||
@createDirectory assetsDirPath+'/'+thefile.getParent().getBaseName(), ()=>
|
||||
@writePng assetsDirPath+'/'+thefile.getParent().getBaseName()+'/', filename, imgbuffer, ()=>
|
||||
@createDirectory creatDirPath, ()=>
|
||||
@writePng writePath, filename, imgbuffer, ()=>
|
||||
# ascClip = "assets/#{filename}"
|
||||
# clipboard.writeText(ascClip)
|
||||
|
||||
@insertText ".getBaseName()}/#{filename})", editor
|
||||
@insertUrl "", editor
|
||||
|
||||
return false
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,25 @@ var readDir = function (path, callback) {
|
|||
});
|
||||
};
|
||||
|
||||
var createMD = function (data) {
|
||||
var markdown = '';
|
||||
markdown += '\n#### [首页](# "返回首页") ####\n';
|
||||
for (var dir in data) {
|
||||
if (data.hasOwnProperty(dir)) {
|
||||
if (dir == 'assets') {
|
||||
continue;
|
||||
}
|
||||
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=' +
|
||||
dir + '/' + name + ' "' + name.substring(4) + '")\n'
|
||||
}
|
||||
}
|
||||
}
|
||||
return markdown;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
updateNav: function (editorPath) {
|
||||
if (editorPath.indexOf('library') < 0) {
|
||||
|
|
@ -25,23 +44,27 @@ module.exports = {
|
|||
var path = editorPath.split('library')[0] + 'library/';
|
||||
readDir(path, function (err, data) {
|
||||
if (!err) {
|
||||
var markdown = '';
|
||||
markdown += '\n#### [首页](?file=首页 "返回首页")\n';
|
||||
for (var dir in data) {
|
||||
if (data.hasOwnProperty(dir)) {
|
||||
if (dir == 'assets') {
|
||||
continue;
|
||||
}
|
||||
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=' +
|
||||
dir + '/' + name + ' "' + name.substring(4) + '")\n'
|
||||
}
|
||||
}
|
||||
}
|
||||
var markdown = createMD(data);
|
||||
fs.writeFileSync(path + '_navigation_.md', markdown, 'utf-8');
|
||||
}
|
||||
});
|
||||
},
|
||||
watchDir: function (editorPath) {
|
||||
console.log(editorPath);
|
||||
if (editorPath.indexOf('library') < 0) {
|
||||
return;
|
||||
}
|
||||
var path = editorPath.split('library')[0] + 'library/';
|
||||
fs.watch(path, function (event, fileName) {
|
||||
if (fileName != '_navigation_.md') {
|
||||
console.log('change')
|
||||
readDir(path, function (err, data) {
|
||||
if (!err) {
|
||||
var markdown = createMD(data);
|
||||
fs.writeFileSync(path + '_navigation_.md', markdown, 'utf-8');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue