bugfix: #406 relative image path not display (#411)

This commit is contained in:
Ran Luo 2018-07-03 10:49:46 +08:00 committed by GitHub
parent 82d82e6ac3
commit c902f6b76b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -180,7 +180,7 @@ export const getImageInfo = src => {
const imageExtension = EXT_REG.test(src) const imageExtension = EXT_REG.test(src)
const isUrl = URL_REG.test(src) const isUrl = URL_REG.test(src)
if (imageExtension) { if (imageExtension) {
if (isUrl || !window.__dirname) { if (isUrl || !window.DIRNAME) {
return { return {
isUnknownType: false, isUnknownType: false,
src src
@ -188,7 +188,7 @@ export const getImageInfo = src => {
} else { } else {
return { return {
isUnknownType: false, isUnknownType: false,
src: 'file://' + path.resolve(window.__dirname, src) src: 'file://' + path.resolve(window.DIRNAME, src)
} }
} }
} else if (isUrl && !imageExtension) { } else if (isUrl && !imageExtension) {

View File

@ -6,7 +6,6 @@ import { getOptionsFromState, getSingleFileState, getBlankFileState } from './he
import notice from '../services/notification' import notice from '../services/notification'
const toc = require('markdown-toc') const toc = require('markdown-toc')
const state = { const state = {
lineEnding: 'lf', lineEnding: 'lf',
currentFile: {}, currentFile: {},
@ -28,7 +27,8 @@ const mutations = {
SET_CURRENT_FILE (state, currentFile) { SET_CURRENT_FILE (state, currentFile) {
const oldCurrentFile = state.currentFile const oldCurrentFile = state.currentFile
if (!oldCurrentFile.id || oldCurrentFile.id !== currentFile.id) { if (!oldCurrentFile.id || oldCurrentFile.id !== currentFile.id) {
const { markdown, cursor, history } = currentFile const { markdown, cursor, history, pathname } = currentFile
window.DIRNAME = pathname ? path.dirname(pathname) : ''
// set state first, then emit file changed event // set state first, then emit file changed event
state.currentFile = currentFile state.currentFile = currentFile
bus.$emit('file-changed', { markdown, cursor, renderCursor: true, history }) bus.$emit('file-changed', { markdown, cursor, renderCursor: true, history })
@ -53,8 +53,8 @@ const mutations = {
}, },
SET_PATHNAME (state, file) { SET_PATHNAME (state, file) {
const { filename, pathname, id } = file const { filename, pathname, id } = file
if (id === state.currentFile.id) { if (id === state.currentFile.id && pathname) {
window.__dirname = path.dirname(pathname) window.DIRNAME = path.dirname(pathname)
} }
const targetFile = state.tabs.filter(f => f.id === id)[0] const targetFile = state.tabs.filter(f => f.id === id)[0]