Skip to content

Commit

Permalink
feat: 晚上国际化以及项目说明
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 17, 2023
1 parent 1d671b6 commit 07a2099
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 28 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,29 @@

# siyuan-plugin-importer

Import from epub, docx, html etc. to siyuan-note
Import epub, docx, html, etc. into Siyuan notes. Currently supported formats: .epub, .docx, .html, .opml.

## 核心特色

- **Select Notes**: Support for selecting a notebook, the next time you open it, you can automatically remember the notebook you selected last time
- **One-click import**: Select a file, one-click import, zero configuration

## Donate

If you approve of this project, invite me to have a cup of coffee, which will encourage me to keep updating and create
more useful tools~

### Wechat

<div>
<img src="https://static-rs-terwer.oss-cn-beijing.aliyuncs.com/donate/wechat.jpg" alt="wechat" style="width:280px;height:375px;" />
</div>

### Alipay

<div>
<img src="https://static-rs-terwer.oss-cn-beijing.aliyuncs.com/donate/alipay.jpg" alt="alipay" style="width:280px;height:375px;" />
</div>

## Thanks

Expand Down
25 changes: 24 additions & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,30 @@

# 导入工具

导入 epub, docx, html 等格式到思源笔记
![](https://raw.githubusercontent.com/terwer/siyuan-plugin-importer/main/public/icon.png)

导入 epub, docx, html 等导入到思源笔记。目前支持的格式:.epub, .docx, .html, .opml。

## 核心特色

- **选择笔记**:支持选择笔记本,下次打开可自动记忆上次选择的笔记本
- **一键导入**:选择文件,一键导入即可,零配置

## 捐赠

如果您认可这个项目,请我喝一杯咖啡吧,这将鼓励我持续更新,并创作出更多好用的工具~

### 微信

<div>
<img src="https://static-rs-terwer.oss-cn-beijing.aliyuncs.com/donate/wechat.jpg" alt="wechat" style="width:280px;height:375px;" />
</div>

### 支付宝

<div>
<img src="https://static-rs-terwer.oss-cn-beijing.aliyuncs.com/donate/alipay.jpg" alt="alipay" style="width:280px;height:375px;" />
</div>

## 感谢

Expand Down
21 changes: 20 additions & 1 deletion public/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,24 @@
"importer": "Importer",
"selectFile": "Select file",
"cancel": "Cancel",
"startImport": "Start import"
"startImport": "Start import",
"importerLoaded": "Importer loaded",
"importerUnloaded": "Importer unloaded",
"msgFileNotEmpty": "File cannot be empty",
"msgConverting": "File conversion, please wait",
"msgFileUploadError": "The file upload failed, the error message is as follows",
"msgFileConvertError": "The file conversion failed, the error message is as follows",
"msgFileConvertEmpty": "File conversion failed with empty content",
"msgDocCreateFailed": "Document creation failed, please check the converted markdown file",
"msgDocAlreadyImported": "This document has already been imported, if the document has been deleted, you can ignore this prompt, the current document",
"msgTempFileCleaned": "Temp files cleaned up",
"msgImportSuccess": "file imported successfully",
"notebookConfigUpdated": "The notebook configuration has been updated",
"selected": "选中",
"targetNotebook": "Target notebook",
"selectNotebookTip": "Imported target notebook, selected",
"loading": "Loading",
"importFile": "Importing files",
"importTip": "Convert epub, docx and other formats into Markdown temporary files, and then create documents",
"supportedTypes": "Currently supported formats: .epub, .docx, .html, .opml"
}
Binary file added public/i18n/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,24 @@
"importer": "导入插件",
"selectFile": "选择文件",
"cancel": "取消",
"startImport": "开始导入"
"startImport": "开始导入",
"importerLoaded": "导入工具已加载",
"importerUnloaded": "导入工具已卸载",
"msgFileNotEmpty": "文件不能为空",
"msgConverting": "文件转换中,请稍后",
"msgFileUploadError": "文件上传失败,错误信息如下",
"msgFileConvertError": "文件转换失败,错误信息如下",
"msgFileConvertEmpty": "文件转换失败,内容为空",
"msgDocCreateFailed": "文档创建失败,请检查转换后的markdown文件",
"msgDocAlreadyImported": "此文档已导入过,如果文档已删除,可忽略此提示,当前文档",
"msgTempFileCleaned": "临时文件已清理",
"msgImportSuccess": "文件导入成功",
"notebookConfigUpdated": "笔记本配置已更新",
"selected": "选中",
"targetNotebook": "目标笔记本",
"selectNotebookTip": "导入的目标笔记本,已选",
"loading": "加载中",
"importFile": "导入文件",
"importTip": "将 epub, docx 等格式转换成Markdown临时文件,然后创建文档",
"supportedTypes": "目前支持的格式:.epub, .docx, .html, .opml"
}
4 changes: 2 additions & 2 deletions public/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"zh_CN": "导入工具"
},
"description": {
"default": "Import from epub, docx, html etc. to siyuan-note",
"zh_CN": "导入 epub, docx, html 等格式到思源笔记"
"default": "Import epub, docx, html, etc. into Siyuan notes. Currently supported formats: .epub, .docx, .html, .opml.",
"zh_CN": "导入 epub, docx, html 等导入到思源笔记。目前支持的格式:.epub, .docx, .html, .opml。"
},
"readme": {
"default": "README.md",
Expand Down
18 changes: 17 additions & 1 deletion src/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,20 @@
* Please contact Terwer, Shenzhen, Guangdong, China, [email protected]
* or visit www.terwer.space if you need additional information or have any
* questions.
*/
*/

// 图标
// 建议使用 iconfont ,可以调色,可以调整大小
// https://fontawesome.com/search?q=yuque&o=r&m=free
// https://www.iconfont.cn/search/index?searchType=icon&q=cnblogs&page=1&tag=&fromCollection=1&fills=
.importer-topbar-icon{
width 12px
height 12px
}

.importer-menu-icon{
width 12px
height 12px
margin-right 10px
margin-top 3px
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export default class ImporterPlugin extends Plugin {

// 初始化顶栏按钮
await initTopbar(this)
this.logger.info("Importer loaded")
this.logger.info(this.i18n.importerLoaded)
}

async onunload() {
// 卸载删除配置
await removeImporterConfig(this)
this.logger.info("Importer unloaded")
this.logger.info(this.i18n.importerUnloaded)
}
}
38 changes: 20 additions & 18 deletions src/lib/ImportForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
target: HTMLInputElement
}
) => {
pluginInstance.logger.debug("开始导入...")
pluginInstance.logger.debug(`${pluginInstance.i18n.startImport}...`)
dialog.destroy()
// showMessage(`文件上传中,请稍后...`, 1000, "info")
const files = event.target.files ?? []
if (files.length === 0) {
showMessage(`文件不能为空`, 7000, "error")
showMessage(`${pluginInstance.i18n.msgFileNotEmpty}`, 7000, "error")
return
}
Expand All @@ -59,7 +59,7 @@
const doImport = async function (file: any) {
// 给个提示,免得任务是卡主了
showMessage(`文件转换中,请稍后...`, 1000, "info")
showMessage(`${pluginInstance.i18n.msgConverting}...`, 1000, "info")
const fromFilename = file.name
let filename = fromFilename.substring(0, fromFilename.lastIndexOf("."))
Expand All @@ -69,7 +69,7 @@
const fromFilePath = `/temp/convert/pandoc/${fromFilename}`
const uploadResult = await pluginInstance.kernelApi.putFile(fromFilePath, file)
if (uploadResult.code !== 0) {
showMessage(`文件上传失败,错误信息如下:${uploadResult.msg}`, 7000, "error")
showMessage(`${pluginInstance.i18n.msgFileUploadError}:${uploadResult.msg}`, 7000, "error")
return
}
Expand All @@ -82,14 +82,14 @@
toFilename
)
if (convertResult.code !== 0) {
showMessage(`文件转换失败,错误信息如下:${convertResult.msg}`, 7000, "error")
showMessage(`${pluginInstance.i18n.msgFileConvertError}:${convertResult.msg}`, 7000, "error")
return
}
// 读取文件
let mdText = (await pluginInstance.kernelApi.getFile(toFilePath, "text")) ?? ""
if (mdText === "") {
showMessage("文件转换失败,内容为空", 7000, "error")
showMessage(pluginInstance.i18n.msgFileConvertEmpty, 7000, "error")
return
}
Expand All @@ -99,14 +99,14 @@
// 创建 MD 文档
const mdResult = await pluginInstance.kernelApi.createDocWithMd(toNotebookId, `/${filename}`, mdText)
if (mdResult.code !== 0) {
showMessage(`文档创建失败,请检查转换后的markdown文件=>${toFilePath}`, 7000, "error")
showMessage(`${pluginInstance.i18n.msgDocCreateFailed}=>${toFilePath}`, 7000, "error")
}
const pageId = mdResult.data as string
let docIds = importerConfig.docIds ?? []
// 检测重复导入
if (docIds.includes(pageId)) {
showMessage(`此文档已导入过,如果文档已删除,可忽略此提示,当前文档 [${filename}]`, 7000, "info")
showMessage(`${pluginInstance.i18n.msgDocAlreadyImported} [${filename}]`, 7000, "info")
} else {
docIds.push(pageId)
}
Expand All @@ -118,13 +118,13 @@
if (!isDev) {
await pluginInstance.kernelApi.removeFile(fromFilePath)
await pluginInstance.kernelApi.removeFile(toFilePath)
await pluginInstance.logger.info("临时文件已清理")
await pluginInstance.logger.info(pluginInstance.i18n.msgTempFileCleaned)
}
// 打开笔记本
await pluginInstance.kernelApi.openNotebook(toNotebookId)
showMessage("文件导入成功", 5000, "info")
showMessage(pluginInstance.i18n.msgImportSuccess, 5000, "info")
}
const notebookChange = async function () {
Expand All @@ -136,7 +136,7 @@
importerConfig.notebook = toNotebookId
await saveImporterConfig(pluginInstance, importerConfig)
pluginInstance.logger.info("笔记本配置已更新=>", toNotebookId)
pluginInstance.logger.info(`${pluginInstance.i18n.notebookConfigUpdated}=>`, toNotebookId)
}
onMount(async () => {
Expand All @@ -151,16 +151,18 @@
const currentNotebook = notebooks.find((n) => n.id === toNotebookId)
toNotebookName = currentNotebook.name
pluginInstance.logger.info(`选中 [${toNotebookName}] toNotebookId=>`, toNotebookId)
pluginInstance.logger.info(`${pluginInstance.i18n.selected} [${toNotebookName}] toNotebookId=>`, toNotebookId)
})
</script>

<div class="b3-dialog__content importer-form-container">
<div class="config__tab-container">
<label class="fn__flex b3-label config__item">
<div class="fn__flex-1">
目标笔记本
<div class="b3-label__text">导入的目标笔记本,已选 <span class="selected">[{toNotebookName}]</span></div>
{pluginInstance.i18n.targetNotebook}
<div class="b3-label__text">
{pluginInstance.i18n.selectNotebookTip} <span class="selected">[{toNotebookName}]</span>
</div>
</div>
<span class="fn__space" />
<select
Expand All @@ -173,15 +175,15 @@
<option value={notebook.id}>{notebook.name}</option>
{:else}
<!-- this block renders when photos.length === 0 -->
<option value="0">loading...</option>
<option value="0">{pluginInstance.i18n.loading}...</option>
{/each}
</select>
</label>

<div class="fn__flex b3-label config__item">
<div class="fn__flex-1 fn__flex-center">
导入文件
<div class="b3-label__text">将 epub, docx 等格式转换成Markdown临时文件,然后创建文档</div>
{pluginInstance.i18n.importFile}
<div class="b3-label__text">{pluginInstance.i18n.importTip}</div>
</div>
<span class="fn__space" />
<button class="b3-button b3-button--outline fn__flex-center fn__size200" style="position: relative">
Expand All @@ -198,7 +200,7 @@
</button>
</div>

<div class="fn__flex b3-label config__item">目前支持的格式:.epub, .docx, .html, .opml</div>
<div class="fn__flex b3-label config__item">{pluginInstance.i18n.supportedTypes}</div>
</div>
</div>

Expand Down
3 changes: 2 additions & 1 deletion src/topbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import ImporterPlugin from "./index"
import { Dialog, isMobile } from "siyuan"
import ImportForm from "./lib/ImportForm.svelte"
import {iconImporter} from "./utils/svg";

/**
* 顶栏按钮
Expand All @@ -37,7 +38,7 @@ import ImportForm from "./lib/ImportForm.svelte"
*/
export async function initTopbar(pluginInstance: ImporterPlugin) {
const topBarElement = pluginInstance.addTopBar({
icon: "iconEmoji",
icon: iconImporter.iconImporter,
title: pluginInstance.i18n.importer,
position: "right",
callback: () => {
Expand Down
28 changes: 28 additions & 0 deletions src/utils/svg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, [email protected]
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

export const iconImporter = {
iconImporter: `<span class="importer-topbar-icon"><svg t="1684307075455" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2348" width="16" height="16"><path d="M558.933333 1024c-10.666667 0-21.333333-4.266667-25.6-14.933333l-352-512c-6.4-10.666667-8.533333-23.466667-2.133333-32 6.4-10.666667 17.066667-17.066667 29.866667-17.066667h189.866666c-12.8-168.533333-132.266667-317.866667-296.533333-366.933333-12.8-4.266667-21.333333-17.066667-21.333333-29.866667S89.6 25.6 104.533333 21.333333c42.666667-14.933333 89.6-21.333333 134.4-21.333333 253.866667 0 462.933333 198.4 480 448h192c12.8 0 23.466667 6.4 27.733334 17.066667 6.4 10.666667 4.266667 23.466667-2.133334 32l-352 512c-4.266667 10.666667-14.933333 14.933333-25.6 14.933333zM268.8 512l290.133333 424.533333L851.2 512h-162.133333c-17.066667 0-32-14.933333-32-32C657.066667 249.6 469.333333 64 238.933333 64h-17.066666c145.066667 85.333333 241.066667 243.2 241.066666 416 0 17.066667-14.933333 32-32 32h-162.133333z m452.266667-32z" fill="#cdcdcd" p-id="2349"></path></svg></span>`,
}

0 comments on commit 07a2099

Please sign in to comment.