Skip to content

Commit

Permalink
支持文章文件夹路径自定义
Browse files Browse the repository at this point in the history
  • Loading branch information
jecshcier committed Aug 9, 2019
1 parent 090a2bb commit dbf5200
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 5 additions & 4 deletions dev/index.js
Expand Up @@ -22,6 +22,7 @@ class Main extends React.Component {
componentDidMount() {
app.once('getSystemCodeCallback', function (event, data) {
window.os = data
window.localStorage.postPath = window.localStorage.postPath ? window.localStorage.postPath : "content/post"
if(window.os === 'darwin'){
window.localStorage.cliPath = window.localStorage.cliPath ? window.localStorage.cliPath : "/usr/local/bin/hugo"
}else if(window.os === 'win32'){
Expand Down Expand Up @@ -57,17 +58,17 @@ class Main extends React.Component {
let fileNameArr = data[i].split('.')
if (fileNameArr[fileNameArr.length - 1] === 'md' && data[i] !== '_index.md') {
articleArr.push({
path: hexoRoot + '/content/post/' + data[i],
path: `${hexoRoot}/${window.localStorage.postPath}/${data[i]}`,
fileName: data[i],
})
}
}
this.setState({
articleArr: articleArr,
current: activeArticleName ? hexoRoot + '/content/post/' + activeArticleName : articleArr[0].path,
current: activeArticleName ? `${hexoRoot}/${window.localStorage.postPath}/${activeArticleName}` : articleArr[0].path,
currentName: activeArticleName ? activeArticleName : articleArr[0].fileName
}, () => {
let currentPath = activeArticleName ? hexoRoot + '/content/post/' + activeArticleName : articleArr[0].path
let currentPath = activeArticleName ? `${hexoRoot}/${window.localStorage.postPath}/${activeArticleName}` : articleArr[0].path
let currentName = activeArticleName ? activeArticleName : articleArr[0].fileName
console.log(currentName)
console.log(currentPath)
Expand All @@ -83,7 +84,7 @@ class Main extends React.Component {
})
app.send('getFolder', {
callback: 'getFolderCallback',
url: hexoRoot + '/content/post'
url: `${hexoRoot}/${window.localStorage.postPath}`
})
}

Expand Down
16 changes: 14 additions & 2 deletions dev/react/Config.js
Expand Up @@ -9,6 +9,7 @@ class ConfigItem extends React.Component {
domain: window.localStorage.domain ? window.localStorage.domain : '',
cliPath: window.localStorage.cliPath ? window.localStorage.cliPath : '',
blogPath: window.localStorage.hexoRoot ? window.localStorage.hexoRoot : '',
postPath: window.localStorage.postPath ? window.localStorage.postPath : '',
}
console.log(this.state)
}
Expand All @@ -33,7 +34,7 @@ class ConfigItem extends React.Component {
}
})
app.send('urlIsExist', {
url: `${hugoRoot}/content/post`,
url: `${hugoRoot}/content`,
callback: 'urlIsExistCallback'
})
})
Expand All @@ -57,7 +58,8 @@ class ConfigItem extends React.Component {
this.setState({
domain: window.localStorage.domain || '',
cliPath: window.localStorage.cliPath || '',
blogPath: window.localStorage.hexoRoot || ''
blogPath: window.localStorage.hexoRoot || '',
postPath: window.localStorage.postPath || ''
})
}
}
Expand Down Expand Up @@ -105,6 +107,10 @@ class ConfigItem extends React.Component {
window.localStorage.hexoRoot = this.state.blogPath
this.initHugoPath(this.state.blogPath)
}
if(this.state.postPath !== window.localStorage.postPath){
window.localStorage.postPath = this.state.postPath
this.initHugoPath(this.state.blogPath)
}
message.success('设置已保存')
this.props.closeModal()
}
Expand All @@ -124,6 +130,12 @@ class ConfigItem extends React.Component {
<span>&nbsp;{this.state.blogPath ? this.state.blogPath : ''}&nbsp;</span>
<Button type="default" onClick={this.chooseHexoRoot} size={'small'}>设置</Button>
</div>
<div>
<span>文章目录:</span>
<Input type="text" onChange={(e) => {
this.inputOnchange(e, 'postPath')
}} value={this.state.postPath}/>
</div>
<div>
<span>配置域名:</span>
<Input type="text" onChange={(e) => {
Expand Down
2 changes: 1 addition & 1 deletion dev/react/ToolBar.js
Expand Up @@ -86,7 +86,7 @@ class ToolBar extends React.Component {
}
})
app.send('createFile', {
url: this.props.rootDir + '/content/post/' + articleName,
url: `${this.props.rootDir}/${window.localStorage.postPath}/${articleName}`,
content: articleContent,
base64: false,
callback: 'createFileCallback'
Expand Down

0 comments on commit dbf5200

Please sign in to comment.