From 967d95e21afb91d136ee8a8446ea4de3349c242f Mon Sep 17 00:00:00 2001 From: purocean Date: Thu, 20 Jan 2022 21:01:11 +0800 Subject: [PATCH] feat: support custom pandoc reference document --- help/FEATURES.md | 2 +- help/FEATURES_ZH-CN.md | 2 +- src/main/constant.ts | 2 ++ .../resources/{tpl.docx => pandoc-reference.docx} | Bin src/main/server/convert.ts | 4 ++-- src/main/startup.ts | 8 +++++++- 6 files changed, 13 insertions(+), 5 deletions(-) rename src/main/resources/{tpl.docx => pandoc-reference.docx} (100%) diff --git a/help/FEATURES.md b/help/FEATURES.md index 4e95e930..d9047a32 100644 --- a/help/FEATURES.md +++ b/help/FEATURES.md @@ -20,7 +20,7 @@ The application generated data is stored in `/yank-note` dir, click the "O Directory description 1. configuration file `/yank-note/config.json` -1. recycle bin `/yank-note/trash` +1. export docx reference doc `/yank-note/pandoc-reference.docx` 1. plug-ins `/yank-note/plugins` 1. themes `/yank-note/themes` diff --git a/help/FEATURES_ZH-CN.md b/help/FEATURES_ZH-CN.md index 9d25c27b..caedf7a0 100644 --- a/help/FEATURES_ZH-CN.md +++ b/help/FEATURES_ZH-CN.md @@ -20,7 +20,7 @@ define: 目录说明: 1. 配置文件 `/yank-note/config.json` -1. 回收站 `/yank-note/trash` +1. 导出 docx 参考文档 `/yank-note/pandoc-reference.docx` 1. 插件 `/yank-note/plugins` 1. 主题 `/yank-note/themes` diff --git a/src/main/constant.ts b/src/main/constant.ts index aa43843f..2deb467e 100644 --- a/src/main/constant.ts +++ b/src/main/constant.ts @@ -22,6 +22,8 @@ export const RESOURCES_DIR = convertAppPath(path.join(__dirname, 'resources')) export const BUILD_IN_STYLES = ['github.css'] +export const PANDOC_REFERENCE_FILE = 'pandoc-reference.docx' + export const GITHUB_URL = 'https://github.com/purocean/yn' export const FLAG_DISABLE_SERVER = false diff --git a/src/main/resources/tpl.docx b/src/main/resources/pandoc-reference.docx similarity index 100% rename from src/main/resources/tpl.docx rename to src/main/resources/pandoc-reference.docx diff --git a/src/main/server/convert.ts b/src/main/server/convert.ts index 4c0e8cda..29887cd1 100644 --- a/src/main/server/convert.ts +++ b/src/main/server/convert.ts @@ -2,10 +2,10 @@ import * as os from 'os' import * as fs from 'fs-extra' import * as path from 'path' import { spawn } from 'child_process' -import { BIN_DIR, RESOURCES_DIR } from '../constant' +import { BIN_DIR, PANDOC_REFERENCE_FILE, RESOURCES_DIR, USER_DIR } from '../constant' const binPath = path.join(BIN_DIR, os.platform() + '-pandoc-2.7.3' + (os.platform() === 'win32' ? '.exe' : '')) -const docxTplPath = path.join(RESOURCES_DIR, './tpl.docx') +const docxTplPath = path.join(USER_DIR, PANDOC_REFERENCE_FILE) const filterPath = path.join(RESOURCES_DIR, './pandoc-filter.lua') const convert = async (source: string, fromType: string, toType: string, resourcePath: string) => { diff --git a/src/main/startup.ts b/src/main/startup.ts index f44c8f9a..0b682fb6 100644 --- a/src/main/startup.ts +++ b/src/main/startup.ts @@ -1,6 +1,6 @@ import * as fs from 'fs-extra' import * as path from 'path' -import { USER_DIR, USER_PLUGIN_DIR, USER_THEME_DIR, RESOURCES_DIR, BUILD_IN_STYLES } from './constant' +import { USER_DIR, USER_PLUGIN_DIR, USER_THEME_DIR, RESOURCES_DIR, BUILD_IN_STYLES, PANDOC_REFERENCE_FILE } from './constant' import './updater' export default function () { @@ -29,4 +29,10 @@ window.registerPlugin({ fs.readFileSync(path.join(RESOURCES_DIR, style)) ) }) + + const docxTplPath = path.join(USER_DIR, PANDOC_REFERENCE_FILE) + if (!fs.existsSync(docxTplPath)) { + fs.createReadStream(path.join(RESOURCES_DIR, PANDOC_REFERENCE_FILE)) + .pipe(fs.createWriteStream(docxTplPath)) + } }