From bbc9b77bda3828336e997b81972e1951c5f800c1 Mon Sep 17 00:00:00 2001 From: Yuto Tanaka Date: Mon, 9 Sep 2024 22:13:54 +0900 Subject: [PATCH] feat: add skk dict generator --- README.md | 1 + scripts/build.ts | 13 ++++++++++++- scripts/lib/platform.ts | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2116d3b..6c57abf 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ https://github.com/kotofurumiya/genshin-dict/releases/latest | macOS追加辞書 | 原神辞書_macOS.txt | | | iPhoneユーザ辞書 | | mac経由で追加可能(後述) | | Google IME | 原神辞書_Windows.txt | macでもWindows用ファイルで追加可能 | +| SKK | SKK-JISYO.genshin | SKK辞書 | ## 利用方法(Windows) diff --git a/scripts/build.ts b/scripts/build.ts index f192f43..8e70da4 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -2,7 +2,14 @@ import fs from 'fs'; import url from 'url'; import path from 'path'; import { loadDictList } from '../worddata/index.js'; -import { toKotoeriDict, toMacUserDict, toWindowsImeDict, expandVuHiragana, toUtf16BOM } from './lib/platform.js'; +import { + toKotoeriDict, + toMacUserDict, + toWindowsImeDict, + expandVuHiragana, + toUtf16BOM, + toSkkDict, +} from './lib/platform.js'; import { generateDocs } from './lib/docgen.js'; import { DictItem } from '../worddata/dict.js'; @@ -14,6 +21,7 @@ const distDir = path.join(dirname, '..', 'genshin-dictionary'); const winDictFile = path.join(distDir, '原神辞書_Windows.txt'); const macDictFile = path.join(distDir, '原神辞書_macOS.txt'); const macUserDictFile = path.join(distDir, '原神辞書_macOS_ユーザ辞書.plist'); +const skkDictFile = path.join(distDir, 'SKK-JISYO.genshin'); console.log('辞書データを構築しています...'); @@ -28,6 +36,7 @@ console.log('辞書データを構築しています...'); const winIme = toWindowsImeDict(words); const kotoeri = toKotoeriDict(words); const plist = toMacUserDict(words); + const skk = toSkkDict(words); console.log('ドキュメントを生成しています...'); @@ -44,9 +53,11 @@ console.log('辞書データを構築しています...'); fs.writeFileSync(winDictFile, toUtf16BOM(winIme)); fs.writeFileSync(macDictFile, kotoeri, 'utf8'); fs.writeFileSync(macUserDictFile, plist, 'utf8'); + fs.writeFileSync(skkDictFile, skk, 'utf8'); console.log('完了しました'); console.log(winDictFile); console.log(macDictFile); console.log(macUserDictFile); + console.log(skkDictFile); })(); diff --git a/scripts/lib/platform.ts b/scripts/lib/platform.ts index df8e122..fd98126 100644 --- a/scripts/lib/platform.ts +++ b/scripts/lib/platform.ts @@ -69,3 +69,15 @@ export const toUtf16BOM = (str: string): Buffer => { const u16leBuf = Buffer.from(`\ufeff${str}`, 'utf16le'); return u16leBuf; }; + +export const toSkkDict = (items: DictItem[]) => { + const head = `;; -*- fundamental -*- ; coding: utf-8 -*- +;; okuri-ari entries. +;; okuri-nasi entries.`; + const dicts = items + .map(({ hiragana, word }) => { + return `${hiragana} /${word}/`; + }) + .join('\n'); + return [head, dicts].join('\n'); +};