Skip to content

Commit

Permalink
Merge branch 'release/1.22.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed May 20, 2019
2 parents 75c4118 + 6fc6e03 commit fc40f86
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 20 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
+ `Ctrl + Alt + D` 插入当前日期
+ `Ctrl + Alt + T` 插入当前时间
+ `Ctrl + Alt + F` 插入文件附件
+ `Ctrl + Alt + I` 插入文档链接
+ `Ctrl + J` 连接行 join lines
+ `Ctrl + K, Ctrl + U` 转换大写
+ `Ctrl + K, Ctrl + L` 转换小写
+ `Ctrl + Alt + R` 在内置终端里面运行选中内容
+ `Ctrl + B + V` 粘贴 html 富文本

## 特色功能
+ 同步预览滚动,实现得较粗糙
Expand Down Expand Up @@ -119,6 +121,14 @@
## 更新日志
[最新发布](https://github.com/purocean/yn/releases)

### [v1.22.0](https://github.com/purocean/yn/releases/tag/v1.22.0) 2019-05-20
1. 增加粘贴 html 富文本功能 `Ctrl + B + V`
1. 增加插入文档快捷键 `Ctrl + Alt + I`
1. 修复 vue cli 3 打包错误
1. 修复图片链接转义
1. 搜索排除 node_modules
1. 上传文件目录优化

### [v1.21.0](https://github.com/purocean/yn/releases/tag/v1.21.0) 2019-05-03
1. 调整抓取图片到本地的逻辑
1. 优化目录树样式
Expand Down
2 changes: 1 addition & 1 deletion backend/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ exports.search = (repo, str) => {
return
}

const list = fs.readdirSync(location).filter(x => !x.startsWith('.'))
const list = fs.readdirSync(location).filter(x => !x.startsWith('.') && !ignorePath.test(x))

list.forEach(x => {
const p = path.join(location, x)
Expand Down
3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
"markdown-it-multimd-table": "^3.1.3",
"markdown-it-task-lists": "^2.1.1",
"mime-types": "^2.1.24",
"monaco-editor": "^0.13.1",
"normalize.css": "^8.0.1",
"socket.io-client": "^2.2.0",
"transliteration": "^2.1.3",
"turndown": "^5.0.3",
"vue": "^2.6.10",
"vue-bus": "^1.2.1",
"vue-router": "^3.0.3",
Expand Down
38 changes: 34 additions & 4 deletions frontend/src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

<script>
import dayjs from 'dayjs'
import TurndownService from 'turndown'
const keys = {}
export default {
name: 'editor',
Expand All @@ -27,16 +30,29 @@ export default {
this.onGotAmdLoader()
}
window.addEventListener('resize', this.resize)
window.addEventListener('keydown', this.recordKeys, true)
window.addEventListener('keyup', this.recordKeys, true)
this.$bus.on('editor-insert-value', this.insert)
this.$bus.on('editor-replace-value', this.replaceValue)
this.$bus.on('editor-toggle-wrap', this.toggleWrap)
},
beforeDestroy () {
window.removeEventListener('paste', this.paste)
window.removeEventListener('resize', this.resize)
window.removeEventListener('keydown', this.recordKeys)
window.removeEventListener('keyup', this.recordKeys)
this.$bus.off('editor-insert-value', this.insert)
this.$bus.off('editor-replace-value', this.replaceValue)
this.$bus.off('editor-toggle-wrap', this.toggleWrap)
},
methods: {
recordKeys (e) {
if (e.type === 'keydown') {
keys[e.key] = true
} else {
keys[e.key] = false
}
},
resize () {
if (this.editor) {
this.editor.layout()
Expand Down Expand Up @@ -83,7 +99,7 @@ export default {
})
this.keyBind()
window.addEventListener('paste', this.paste)
window.addEventListener('paste', this.paste, true)
setTimeout(() => {
this.$emit('ready')
Expand Down Expand Up @@ -172,9 +188,23 @@ export default {
paste (e) {
if (this.editor.isFocused()) {
const items = e.clipboardData.items
for (let i = 0; i < items.length; i++) {
if (items[i].type.match(/^image\/(png|jpg|jpeg|gif)$/i)) {
this.$emit('paste-img', items[i].getAsFile())
if (keys['b'] || keys['B']) { // 粘贴 HTML 转为 markdown
for (let i = 0; i < items.length; i++) {
if (items[i].type.match(/^text\/html$/i)) {
items[i].getAsString(str => {
const md = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced', bulletListMarker: '+' }).turndown(str)
this.insert(md)
})
}
}
e.preventDefault()
e.stopPropagation()
} else {
for (let i = 0; i < items.length; i++) {
if (items[i].type.match(/^image\/(png|jpg|jpeg|gif)$/i)) {
this.$emit('paste-img', items[i].getAsFile())
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Filter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export default {
const file = item || this.selected
if (file) {
this.$emit('choose-file', file)
this.$bus.emit('choose-file', file)
}
},
switchTab (tab = null) {
Expand Down Expand Up @@ -236,6 +235,7 @@ export default {
margin: 0;
border: 0;
font-size: 18px;
line-height: 1.4em;
padding: 6px;
box-sizing: border-box;
background: #333030;
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/components/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@delete="onDelete" />
<transition name="fade">
<div v-if="showFilter" class="filter-wrapper" @click="showFilter = false">
<XFilter @choose-file="f => { showFilter = false }" :repo="repo" :files="files" />
<XFilter @choose-file="showFilter" :repo="repo" :files="files" />
</div>
</transition>
</template>
Expand Down Expand Up @@ -105,8 +105,21 @@ export default {
this.init(null, path)
},
keydownHandler (e) {
if (e.key === 'p' && e.ctrlKey) {
this.showFilter = true
if (e.key === 'i' && e.ctrlKey && e.altKey) {
this.showFilter = f => {
if (this.file) {
const relativePath = f.path.replace(this.file.path.substr(0, this.file.path.lastIndexOf('/')), '.')
this.$bus.emit('editor-insert-value', `[${f.name.replace(/\.[^.]$/, '')}](${encodeURI(relativePath)})`)
}
this.showFilter = false
}
e.preventDefault()
e.stopPropagation()
} else if (e.key === 'p' && e.ctrlKey) {
this.showFilter = f => {
this.$bus.emit('choose-file', f)
this.showFilter = false
}
e.preventDefault()
e.stopPropagation()
} else if (e.key === 'Escape' && this.showFilter) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default {
const imgFile = new File([blob], 'file.' + mime.extension(r.headers.get('content-type')))
file.upload(this.fileRepo, this.filePath, imgFile, result => {
this.$bus.emit('tree-refresh')
this.$bus.emit('editor-replace-value', img.src, result.relativePath)
this.$bus.emit('editor-replace-value', img.src, encodeURI(result.relativePath))
})
})
})
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/file.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CryptoJS from 'crypto-js'
import { slugify } from 'transliteration'

const getCryptKey = () => {
const password = window.prompt('请输入密码:')
Expand Down Expand Up @@ -160,7 +161,9 @@ export default {
file.name.substr(file.name.lastIndexOf('.'))

const formData = new FormData()
const path = belongPath.replace(/\/([^/]*)$/, '/FILES/$1/' + filename)
const path = belongPath.replace(/\/([^/]*)$/, (match, capture) => {
return `/FILES/${slugify(capture)}/` + filename
})
formData.append('repo', repo)
formData.append('path', path)
formData.append('attachment', file)
Expand Down
7 changes: 7 additions & 0 deletions frontend/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ module.exports = {
ws: true
}
}
},
chainWebpack: config => {
config.plugin('copy').tap(args => {
args[0][0].from = 'node_modules/monaco-editor/min/vs'
args[0][0].to = 'vs'
return args
})
}
}
Loading

0 comments on commit fc40f86

Please sign in to comment.