mirror of
https://github.com/kennkyou/obsidian-kobo-note-sync.git
synced 2026-07-22 06:05:46 +00:00
fix: bundle sql.js wasm for Obsidian release
This commit is contained in:
parent
5b3078a72d
commit
88f7d2a7c1
9 changed files with 121 additions and 24 deletions
45
.github/workflows/release.yml
vendored
Normal file
45
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build plugin
|
||||
run: npm run build
|
||||
|
||||
- name: Attest build provenance
|
||||
uses: actions/attest-build-provenance@v3
|
||||
with:
|
||||
subject-path: |
|
||||
dist/main.js
|
||||
dist/manifest.json
|
||||
|
||||
- name: Create release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
dist/main.js
|
||||
dist/manifest.json
|
||||
14
README.md
14
README.md
|
|
@ -1,6 +1,6 @@
|
|||
# Kobo Note Sync
|
||||
|
||||
[繁體中文](README.zh-TW.md)
|
||||
[繁體中文](https://github.com/KennKyou/obsidian-kobo-note-sync/blob/main/README.zh-TW.md)
|
||||
|
||||
An Obsidian plugin that imports highlights and annotations from your Kobo e-reader into Obsidian notes.
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ The plugin reads the local `Kobo.sqlite` database created by the Kobo Desktop Ap
|
|||
|
||||
### Manual Installation
|
||||
|
||||
1. Download `main.js`, `manifest.json`, and `sql-wasm.wasm` from the [latest release](https://github.com/KennKyou/obsidian-kobo-note-sync/releases)
|
||||
1. Download `main.js` and `manifest.json` from the [latest release](https://github.com/KennKyou/obsidian-kobo-note-sync/releases)
|
||||
2. Create a folder `kobo-note-sync` in your vault's `.obsidian/plugins/` directory
|
||||
3. Copy the downloaded files into that folder
|
||||
4. Restart Obsidian and enable the plugin in Settings → Community Plugins
|
||||
|
|
@ -42,6 +42,14 @@ The plugin reads the local `Kobo.sqlite` database created by the Kobo Desktop Ap
|
|||
|
||||
Highlights will be created as Markdown files in the configured output folder (default: `Kobo Note Sync/`).
|
||||
|
||||
## Privacy
|
||||
|
||||
This plugin reads the local Kobo SQLite database selected in settings and creates or updates notes in your Obsidian vault. It does not send your reading data to any external server.
|
||||
|
||||
## Third Party Notices
|
||||
|
||||
This plugin includes `sql.js`, which is licensed under the MIT License. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
||||
|
||||
## Settings
|
||||
|
||||
| Setting | Description |
|
||||
|
|
@ -126,4 +134,4 @@ source: Kobo
|
|||
**Note:** <%= it.annotation %>
|
||||
<% } %>
|
||||
---
|
||||
```
|
||||
```
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ Kobo 閱讀器 / App → Kobo 雲端 → Kobo Desktop App → Kobo.sqlite →
|
|||
|
||||
### 手動安裝
|
||||
|
||||
1. 從 [最新版本](https://github.com/KennKyou/obsidian-kobo-note-sync/releases) 下載 `main.js`、`manifest.json` 和 `sql-wasm.wasm`
|
||||
1. 從 [最新版本](https://github.com/KennKyou/obsidian-kobo-note-sync/releases) 下載 `main.js` 和 `manifest.json`
|
||||
2. 在 Vault 的 `.obsidian/plugins/` 目錄下建立 `kobo-note-sync` 資料夾
|
||||
3. 將下載的檔案複製到該資料夾
|
||||
4. 重新啟動 Obsidian,在 設定 → 社群插件 中啟用
|
||||
|
|
@ -42,6 +42,14 @@ Kobo 閱讀器 / App → Kobo 雲端 → Kobo Desktop App → Kobo.sqlite →
|
|||
|
||||
畫線會以 Markdown 檔案儲存在設定的輸出資料夾中(預設:`Kobo Note Sync/`)。
|
||||
|
||||
## 隱私
|
||||
|
||||
本插件會讀取你在設定中指定的本機 Kobo SQLite 資料庫,並在你的 Obsidian Vault 中建立或更新筆記。插件不會將你的閱讀資料傳送到任何外部伺服器。
|
||||
|
||||
## 第三方授權聲明
|
||||
|
||||
本插件包含 `sql.js`,其授權條款為 MIT License。詳見 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
|
||||
|
||||
## 設定
|
||||
|
||||
| 設定項目 | 說明 |
|
||||
|
|
@ -126,4 +134,4 @@ source: Kobo
|
|||
**Note:** <%= it.annotation %>
|
||||
<% } %>
|
||||
---
|
||||
```
|
||||
```
|
||||
|
|
|
|||
31
THIRD_PARTY_NOTICES.md
Normal file
31
THIRD_PARTY_NOTICES.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Third Party Notices
|
||||
|
||||
This plugin includes sql.js.
|
||||
|
||||
sql.js is licensed under the MIT License.
|
||||
|
||||
Repository: https://github.com/sql-js/sql.js
|
||||
|
||||
## sql.js MIT License
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) sql.js authors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "kobo-note-sync",
|
||||
"name": "Kobo Note Sync",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"minAppVersion": "1.0.0",
|
||||
"description": "Import highlights and annotations from your Kobo e-reader into your notes.",
|
||||
"author": "KennKyou",
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "kobo-note-sync",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kobo-note-sync",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"dependencies": {
|
||||
"eta": "^4.5.1",
|
||||
"sql.js": "^1.14.1"
|
||||
|
|
|
|||
10
package.json
10
package.json
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"name": "kobo-note-sync",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "Import Kobo highlights and annotations into Obsidian notes",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"build": "esbuild src/main.ts --bundle --outfile=dist/main.js --external:obsidian --external:electron --format=cjs --platform=node --target=es2020 && npm run copy-assets",
|
||||
"dev": "esbuild src/main.ts --bundle --outfile=dist/main.js --external:obsidian --external:electron --format=cjs --platform=node --target=es2020 --watch",
|
||||
"copy-assets": "cp manifest.json node_modules/sql.js/dist/sql-wasm.wasm dist/",
|
||||
"deploy": "npm run build && cp dist/main.js dist/manifest.json dist/sql-wasm.wasm \"$OBSIDIAN_PLUGINS/kobo-note-sync/\""
|
||||
"build": "esbuild src/main.ts --bundle --outfile=dist/main.js --external:obsidian --external:electron --format=cjs --platform=node --target=es2020 --loader:.wasm=binary && npm run copy-assets",
|
||||
"dev": "esbuild src/main.ts --bundle --outfile=dist/main.js --external:obsidian --external:electron --format=cjs --platform=node --target=es2020 --loader:.wasm=binary --watch",
|
||||
"copy-assets": "cp manifest.json dist/",
|
||||
"deploy": "npm run build && cp dist/main.js dist/manifest.json \"$OBSIDIAN_PLUGINS/kobo-note-sync/\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
|
|
|
|||
23
src/main.ts
23
src/main.ts
|
|
@ -1,9 +1,10 @@
|
|||
import { App, Notice, Plugin, PluginSettingTab, Setting, normalizePath } from "obsidian";
|
||||
import { App, Notice, Plugin, PluginSettingTab, Setting, moment, normalizePath } from "obsidian";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as os from "os";
|
||||
import { Eta } from "eta";
|
||||
import initSqlJs from "sql.js";
|
||||
import sqlWasmBinary from "sql.js/dist/sql-wasm.wasm";
|
||||
|
||||
const eta = new Eta({ autoEscape: false, rmWhitespace: false, autoTrim: [false, false] });
|
||||
|
||||
|
|
@ -153,9 +154,13 @@ const locales: Record<string, LocaleStrings> = {
|
|||
},
|
||||
};
|
||||
|
||||
function getLocaleKey(): keyof typeof locales {
|
||||
const lang = moment.locale().toLowerCase();
|
||||
return lang.startsWith("zh") ? "zh-TW" : "en";
|
||||
}
|
||||
|
||||
function getLocale(): LocaleStrings {
|
||||
const lang = window.localStorage.getItem("language") || "en";
|
||||
return locales[lang] || locales["en"];
|
||||
return locales[getLocaleKey()];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -237,7 +242,7 @@ function numVal(v: unknown, fallback = 0): number {
|
|||
return isNaN(n) ? fallback : n;
|
||||
}
|
||||
|
||||
async function readKoboDb(dbPath: string, pluginDir: string): Promise<BookData[]> {
|
||||
async function readKoboDb(dbPath: string): Promise<BookData[]> {
|
||||
const resolvedPath = expandHome(dbPath);
|
||||
|
||||
if (!fs.existsSync(resolvedPath)) {
|
||||
|
|
@ -249,9 +254,7 @@ async function readKoboDb(dbPath: string, pluginDir: string): Promise<BookData[]
|
|||
const tmpPath = path.join(tmpDir, `kobo-highlighter-${Date.now()}.sqlite`);
|
||||
fs.copyFileSync(resolvedPath, tmpPath);
|
||||
|
||||
const wasmPath = path.join(pluginDir, "sql-wasm.wasm");
|
||||
const wasmBinary = fs.readFileSync(wasmPath);
|
||||
const SQL = await initSqlJs({ wasmBinary });
|
||||
const SQL = await initSqlJs({ wasmBinary: sqlWasmBinary });
|
||||
const buffer = fs.readFileSync(tmpPath);
|
||||
const db = new SQL.Database(buffer);
|
||||
|
||||
|
|
@ -416,9 +419,7 @@ export default class KoboHighlighterPlugin extends Plugin {
|
|||
try {
|
||||
new Notice(t.syncing);
|
||||
|
||||
const pluginDir = (this.app.vault.adapter as any).getBasePath()
|
||||
+ path.sep + this.manifest.dir;
|
||||
const books = await readKoboDb(this.settings.dbPath, pluginDir);
|
||||
const books = await readKoboDb(this.settings.dbPath);
|
||||
if (books.length === 0) {
|
||||
new Notice(t.noHighlights);
|
||||
return;
|
||||
|
|
@ -511,7 +512,7 @@ class KoboHighlighterSettingTab extends PluginSettingTab {
|
|||
display(): void {
|
||||
const { containerEl } = this;
|
||||
const t = getLocale();
|
||||
const isZh = (window.localStorage.getItem("language") || "").startsWith("zh");
|
||||
const isZh = getLocaleKey() === "zh-TW";
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl("h2", { text: t.settingsTitle });
|
||||
|
|
|
|||
4
src/types.d.ts
vendored
Normal file
4
src/types.d.ts
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
declare module "*.wasm" {
|
||||
const binary: Uint8Array;
|
||||
export default binary;
|
||||
}
|
||||
Loading…
Reference in a new issue