Feat(tag): Can modify tags and save it into config.yml

This commit is contained in:
2019-01-28 12:34:23 +01:00
parent 342b2efd1c
commit f5bbf195f3
3 changed files with 53 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
import { readFile } from 'fs'
import { readFile, writeFile } from 'fs'
import Vue from 'vue'
import path from 'path'
import yaml from 'js-yaml'
@@ -50,6 +50,7 @@ export default {
},
actions: {
load (context) {
// load config file
readFile(path.join(context.getters.config_dir, context.getters.config_filename), 'utf8', (err, content) => {
if (err) {
console.log(err)
@@ -63,8 +64,22 @@ export default {
}
})
},
save (context) {
// save config file
var config = {
categories: context.state.categories,
tags: context.state.tags,
}
var yamlConfig = yaml.safeDump(config)
writeFile(path.join(context.getters.config_dir, context.getters.config_filename), yamlConfig, (err) => {
if (err) throw err
console.log('The file has been saved!')
})
},
edit_tag (context, tag) {
context.commit('APPEND_TAG', { tag: tag })
}
context.dispatch('save')
},
}
}