Revert "增加文件监视与自动更新nav"

This reverts commit 3ac22111d9.
This commit is contained in:
TevinLi 2016-04-03 19:18:32 +08:00
parent 7301a2da16
commit c0b5756a0a
3 changed files with 26 additions and 61 deletions

View File

@ -8,10 +8,9 @@ module.exports =
activate: (state) ->
@subscriptions = new CompositeDisposable()
@updateNav('watchDir')
@subscriptions.add atom.commands.add 'atom-workspace',
'amWiki:updateNav': => @updateNav('updateNav')
'amWiki:updateNav': => @updateNav()
@subscriptions.add atom.commands.add 'atom-workspace',
'amWiki:create': => @createWiki()
@ -21,16 +20,13 @@ module.exports =
destroy: ->
@subscriptions.dispose()
updateNav: (type) ->
updateNav: ->
editor = atom.workspace.getActiveTextEditor()
return unless editor
grammar = editor.getGrammar()
return unless grammar
return unless grammar.scopeName is 'source.gfm'
if type == 'updateNav'
navUpdate.updateNav(editor.getPath())
else if type == 'watchDir'
navUpdate.watchDir(editor.getPath())
navUpdate.updateNav(editor.getPath())
createWiki: ->
editor = atom.workspace.getActiveTextEditor()
@ -59,19 +55,9 @@ module.exports =
thefile = new File(editor.getPath())
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
return unless thefile.getParent().getParent().getBaseName() is 'library'
assetsDirPath = thefile.getParent().getParent().getPath()+"/assets"
crypto = require "crypto"
md5 = crypto.createHash 'md5'
@ -79,12 +65,12 @@ module.exports =
filename = "#{thefile.getBaseName().replace(/\.\w+$/, '').replace(/\s+/g,'')}-#{md5.digest('hex').slice(0,5)}.png"
@createDirectory creatDirPath, ()=>
@writePng writePath, filename, imgbuffer, ()=>
@createDirectory assetsDirPath+'/'+thefile.getParent().getBaseName(), ()=>
@writePng assetsDirPath+'/'+thefile.getParent().getBaseName()+'/', filename, imgbuffer, ()=>
# ascClip = "assets/#{filename}"
# clipboard.writeText(ascClip)
@insertUrl "![](assets/#{insertPath}#{filename})", editor
@insertUrl "![](library/assets/#{thefile.getParent().getBaseName()}/#{filename})",editor
return false

View File

@ -15,24 +15,6 @@ 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) {
@ -43,26 +25,23 @@ module.exports = {
var path = editorPath.split('library')[0] + 'library/';
readDir(path, function (err, data) {
if (!err) {
var markdown = createMD(data);
fs.writeFileSync(path + '_navigation_.md', markdown, 'utf-8');
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'
}
}
}
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') {
readDir(path, function (err, data) {
if (!err) {
var markdown = createMD(data);
fs.writeFileSync(path + '_navigation_.md', markdown, 'utf-8');
}
});
}
});
}
}

View File

@ -4,7 +4,7 @@
'submenu': [{
'label': 'amWiki 文库',
'submenu': [{
'label': '手动刷新 “_navigation_.md”',
'label': '刷新 “_navigation_.md”',
'command': 'amWiki:updateNav'
},{
'label': '通过 “config.json” 文件创建新amWiki文库',