Skip to content

Commit

Permalink
fix: 文档导出支持直接定位到目标位置
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiuChen committed Jun 24, 2023
1 parent b858d62 commit e6b078c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/common/plugins/exportPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BytemdPlugin } from 'bytemd'
import { Message } from '@arco-design/web-vue'
import { useArticleStore } from '@/store'
import { markdownImages, imageCache } from './instance'
import { Buffer, resolve, mkdirSync, writeFileSync } from '@/preload'
Expand Down Expand Up @@ -38,7 +39,13 @@ export function exportPlugin(): BytemdPlugin {

// 为文章创建新的文件夹
const folder = resolve(utools.getPath('downloads'), title)
mkdirSync(folder)
const file = resolve(folder, `${title}.md`)
try {
mkdirSync(folder)
} catch (error) {
Message.error('导出失败: ' + error)
utools.shellShowItemInFolder(file)
}

// 将内联的图片保存到本地
for (const { url } of markdownImages) {
Expand All @@ -60,7 +67,10 @@ export function exportPlugin(): BytemdPlugin {
)

// 保存到本地
writeFileSync(resolve(folder, `${title}.md`), dataWithRelativePath)
writeFileSync(file, dataWithRelativePath)

// 定位到目标文件
utools.shellShowItemInFolder(file)
}
}
}
Expand Down

0 comments on commit e6b078c

Please sign in to comment.