Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cyy committed Oct 9, 2017
1 parent b50e396 commit 34d6cf4
Show file tree
Hide file tree
Showing 6 changed files with 8,391 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -35,6 +35,7 @@
"files": [
"dist/electron/**/*"
],
"extraResources": "static",
"dmg": {
"contents": [
{
Expand Down
12 changes: 12 additions & 0 deletions src/data/static.js
@@ -0,0 +1,12 @@
const fs = require('fs')
const Path = require('path')
let yml = fs.readFileSync(Path.join(__static, '_config.yml'), 'utf8')
let def = fs.readFileSync(Path.join(__static, 'default.md'), 'utf8')
let hello = fs.readFileSync(Path.join(__static, 'hello_ceditor.md'), 'utf8')
let css = fs.readFileSync(Path.join(__static, 'md.css'), 'utf8')
export {
yml,
def,
hello,
css
}
14 changes: 9 additions & 5 deletions src/lib/blog.js
@@ -1,8 +1,8 @@
'use strict'
import axios from 'axios'
import { ipcRenderer } from 'electron'
// const { app } = require('electron').remote
import {PostDB} from '../renderer/store/db'
import {yml, hello} from '../data/static'
const Shell = require('shelljs')
const Path = require('path')
Shell.env.PATH += Path.delimiter + '/usr/local/bin' // 添加环境变量
Expand Down Expand Up @@ -74,12 +74,13 @@ function Exec (cmd, errmsg) {

// 修改blog配置文件
function UpdateConfig (path, user) {
let configPath = Path.join(__static, '_config.yml')
// let configPath = Path.join(__static, '_config.yml')
let file = path + '/_config.yml'
let blog = user.blog || 'http://' + user.githubAccount + '.github.io'
let repo = `https://github.com/${user.githubAccount}/${user.githubAccount}.github.io.git`
return new Promise(async (resolve, reject) => {
await Exec(`cp ${configPath} ${path}`)
// await Exec(`cp ${configPath} ${path}`)
fs.writeFileSync(file, yml)
Shell.sed('-i', /__title__/, user.name, file)
Shell.sed('-i', /__subtitle__/, user.bio, file)
Shell.sed('-i', /__author__/, user.name, file)
Expand Down Expand Up @@ -128,9 +129,11 @@ export default class {
Shell.cd(path)
await Exec('hexo init && npm install --registry=https://registry.npm.taobao.org')
await Exec('npm install hexo-deployer-git -S --registry=https://registry.npm.taobao.org')
let defaultMd = Path.join(__static, 'hello_ceditor.md')
// let defaultMd = Path.join(__static, 'hello_ceditor.md')
await Exec('rm source/_posts/hello-world.md')
await Exec(`cp ${defaultMd} source/_posts/`)
// await Exec(`cp ${defaultMd} source/_posts/`)
fs.writeFileSync(Path.join(path, 'source/_posts/hello_ceditor.md'), hello)
await ImportPosts(path, user)
await UpdateConfig(path, user)
await initGithubRepos(user)
await Exec(`hexo generate --deploy`, '尝试发布部署失败')
Expand All @@ -142,6 +145,7 @@ export default class {
}
return
} catch (e) {
console.log(e)
let err = String(e)
if (err.includes('please run `hexo init` on an empty ')) {
return '请选择为空的目录'
Expand Down
8 changes: 1 addition & 7 deletions src/lib/io.js
@@ -1,5 +1,6 @@
'use strict'
import Blog from './blog'
import {css} from '../data/static'
const { dialog, BrowserWindow, app } = require('electron').remote
const fs = require('fs')
const path = require('path')
Expand All @@ -19,14 +20,7 @@ function selectPathForWrite (filters, filename = '未命名') {
return filePath
}

// 读取文本内容
function getFileText (filePath) {
filePath = path.join(__static, filePath)
return fs.readFileSync(filePath, 'utf8')
}

function getHtml (title, body) {
let css = getFileText('md.css')
return `
<!DOCTYPE html>
<html>
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/store/modules/post.js
Expand Up @@ -2,11 +2,13 @@
import {PostDB} from '../db'
import UploadAPI from '../../../lib/upload'
import Io from '../../../lib/io'
import {def as defaultContent} from '../../../data/static'

const moment = require('moment')
const fs = require('fs')
const path = require('path')
// const fs = require('fs')
// const path = require('path')
const Reg = /!\[[^[]*?\]\(\s*([^)|^\s]+)(?=\s*\))/g
const defaultContent = fs.readFileSync(path.join(__static, 'default.md')).toString()
// const defaultContent = fs.readFileSync(path.join(__static, 'default.md')).toString()
const state = {
list: [],
post: {},
Expand Down

0 comments on commit 34d6cf4

Please sign in to comment.