diff --git a/README.md b/README.md index 604e697..62f082a 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ npm i # 依存関係をインストール npx playwright-core install --with-deps chromium # Chromiumブラウザをインストール(PDF出力向け) npm run dev # 開発モードでプレビュー(Ctrl+Cで停止) npm run build # 本番モードでビルド(PDF出力) +npm run kdp # Kindle Direct Publishing(KDP)用の本文PDFを作成 ``` `npm run dev`を実行すると、Chromeブラウザが立ち上がってプレビューが表示されます。プレビューが表示されない場合は一度Ctrl+Cで停止して再度実行してください。 @@ -218,11 +219,13 @@ MITライセンスの下で公開されています。詳細については LICE [docs/99-1_samples.md](./docs/99-1_samples.md)を参照してください。 -## Print +## Print(kindle direct publishing) -プリント出力のための設定や注意事項を記載します。 +KDP(kindle direct publishing)によるプリント出力のための設定や注意事項を記載します。 -- 後日、KDPへの対応を予定しています。 +- `npm run kdp`でKDP用(kindle direct publishing)のPDFを作成できます。 +- 一部のコンテンツの長さによってはKDPでエラーになるので、その場合はIssueで報告いただくかCSSを修正してください。 +- KDP用のPDFはconfigのcoverのfront(表紙)とback(裏表紙)が除外され、start(中表紙)とend(裏中表紙)のimages指定が無視(テキストのみの表紙)になります。これはKDPは表紙と裏表紙を別途アップロードする必要があることと、ページ全体の画像がエラーになるためです。 ## Note @@ -259,9 +262,10 @@ npx browser-sync start --proxy 'localhost:3000' --files="dist/lockfile" --startP - [ ] デモサイトの作成をする - [ ] 変更されたファイルのみを上書き更新をする - [ ] Handlebarsで実装されたカスタムタグをRehype/Remarkプラグインとして実装する(Markdownとしての互換性の向上) -- [ ] 書面デザインをWCAG2.1(とくにコントラスト面)への対応 ## ChangeLog - v0.1 4/26 プロジェクト作成 - v0.2 7/10 Windowsで起動しない問題を修正 #7、Mermaid生成の内部処理を公式のものに変更 +- v0.3 7/14 新書版サイズへの対応 +- v0.4 11/2 kindle direct publishing(KDP)への対応 diff --git a/package-lock.json b/package-lock.json index e76d124..e0b1b46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,11 @@ { "name": "techbook-template", + "version": "0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { + "version": "0.4", "dependencies": { "@akebifiky/remark-simple-plantuml": "^1.0.2", "@mermaid-js/mermaid-cli": "^10.9.1", @@ -31,7 +33,8 @@ "shiki": "^1.1.7", "unified": "^11.0.4", "vfile-matter": "^5.0.0", - "vite-node": "^1.3.1" + "vite-node": "^2.1.4", + "yargs": "^17.7.2" }, "devDependencies": { "@biomejs/biome": "1.5.3", @@ -1213,19 +1216,6 @@ "node": ">=8" } }, - "node_modules/@puppeteer/browsers/node_modules/cliui": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", - "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.1", - "wrap-ansi": "^7.0.0" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/@puppeteer/browsers/node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -1255,30 +1245,6 @@ "node": ">=8" } }, - "node_modules/@puppeteer/browsers/node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, - "node_modules/@puppeteer/browsers/node_modules/y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "engines": { - "node": ">=10" - } - }, "node_modules/@puppeteer/browsers/node_modules/yargs": { "version": "17.7.1", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.1.tgz", @@ -3240,13 +3206,16 @@ } }, "node_modules/cliui": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", - "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", "dependencies": { "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^6.2.0" + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" } }, "node_modules/cliui/node_modules/ansi-regex": { @@ -3287,16 +3256,19 @@ } }, "node_modules/cliui/node_modules/wrap-ansi": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", - "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" }, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, "node_modules/clone": { @@ -3439,56 +3411,6 @@ "url": "https://github.com/open-cli-tools/concurrently?sponsor=1" } }, - "node_modules/concurrently/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/concurrently/node_modules/cliui": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", - "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.1", - "wrap-ansi": "^7.0.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/concurrently/node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" - }, - "node_modules/concurrently/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/concurrently/node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/concurrently/node_modules/supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", @@ -3503,55 +3425,6 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, - "node_modules/concurrently/node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, - "node_modules/concurrently/node_modules/y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "engines": { - "node": ">=10" - } - }, - "node_modules/concurrently/node_modules/yargs": { - "version": "17.7.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", - "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", - "dependencies": { - "cliui": "^8.0.1", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.3", - "y18n": "^5.0.5", - "yargs-parser": "^21.1.1" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/concurrently/node_modules/yargs-parser": { - "version": "21.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", - "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", - "engines": { - "node": ">=12" - } - }, "node_modules/consola": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/consola/-/consola-3.2.3.tgz", @@ -9928,6 +9801,37 @@ "press-ready": "lib/cli.js" } }, + "node_modules/press-ready/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/press-ready/node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "node_modules/press-ready/node_modules/decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/press-ready/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, "node_modules/press-ready/node_modules/execa": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/execa/-/execa-4.1.0.tgz", @@ -9972,6 +9876,81 @@ "node": ">=8.12.0" } }, + "node_modules/press-ready/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/press-ready/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/press-ready/node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/press-ready/node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + }, + "node_modules/press-ready/node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dependencies": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/press-ready/node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dependencies": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/prettier": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", @@ -10165,6 +10144,112 @@ "node": ">=10.13.0" } }, + "node_modules/qrcode/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "node_modules/qrcode/node_modules/decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/qrcode/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/qrcode/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + }, + "node_modules/qrcode/node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dependencies": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dependencies": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/querystringify": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", @@ -13222,14 +13307,13 @@ } }, "node_modules/vite-node": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-1.3.1.tgz", - "integrity": "sha512-azbRrqRxlWTJEVbzInZCTchx0X69M/XPTCz4H+TLvlTcR/xH/3hkRqhOakT41fMJCMzXTu4UvegkZiEoJAWvng==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-2.1.4.tgz", + "integrity": "sha512-kqa9v+oi4HwkG6g8ufRnb5AeplcRw8jUF6/7/Qz1qRQOXHImG8YnLbB+LLszENwFnoBl9xIf9nVdCFzNd7GQEg==", "dependencies": { "cac": "^6.7.14", - "debug": "^4.3.4", - "pathe": "^1.1.1", - "picocolors": "^1.0.0", + "debug": "^4.3.7", + "pathe": "^1.1.2", "vite": "^5.0.0" }, "bin": { @@ -13242,6 +13326,27 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/vite-node/node_modules/debug": { + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/vite-node/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, "node_modules/w3c-xmlserializer": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-4.0.0.tgz", @@ -13539,9 +13644,12 @@ } }, "node_modules/y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "engines": { + "node": ">=10" + } }, "node_modules/yallist": { "version": "4.0.0", @@ -13557,24 +13665,20 @@ } }, "node_modules/yargs": { - "version": "15.4.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", - "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", "dependencies": { - "cliui": "^6.0.0", - "decamelize": "^1.2.0", - "find-up": "^4.1.0", - "get-caller-file": "^2.0.1", + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^4.2.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^18.1.2" + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" }, "engines": { - "node": ">=8" + "node": ">=12" } }, "node_modules/yargs-parser": { @@ -13593,14 +13697,6 @@ "node": ">=8" } }, - "node_modules/yargs/node_modules/decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/yargs/node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -13631,15 +13727,11 @@ } }, "node_modules/yargs/node_modules/yargs-parser": { - "version": "18.1.3", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", - "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", - "dependencies": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - }, + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", "engines": { - "node": ">=6" + "node": ">=12" } }, "node_modules/yauzl": { diff --git a/package.json b/package.json index 985eb1c..5fe3490 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,9 @@ { + "version": "0.4", "scripts": { "build": "npx vite-node src/cli.ts build", "dev": "npx vite-node src/cli.ts dev", + "kdp": "npx vite-node src/cli.ts kdp", "clean": "npx --yes clear-npx-cache", "check": "npx --yes @biomejs/biome check --apply-unsafe ./src" }, @@ -32,7 +34,8 @@ "shiki": "^1.1.7", "unified": "^11.0.4", "vfile-matter": "^5.0.0", - "vite-node": "^1.3.1" + "vite-node": "^2.1.4", + "yargs": "^17.7.2" }, "devDependencies": { "@biomejs/biome": "1.5.3", diff --git a/src/cli.ts b/src/cli.ts index 98bfd2d..3d042ca 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,46 +1,106 @@ -import { Command } from 'commander'; -import concurrently from 'concurrently'; +import { version } from "../package.json"; +import { Command } from "commander"; +import concurrently from "concurrently"; import config from "../techbook.config"; const program = new Command(); -const cssSrcFileName = config.size === "JIS-B5" ? "global.css" : config.size === "105mm 173mm" ? "global-105x173.css" : "global.css"; +const CSS_FILE_MAP = { + 'JIS-B5': 'global.css', + '105mm 173mm': 'global-105x173.css' +}; +const cssSrcFileName = CSS_FILE_MAP[config.size] || 'global.css'; program - .name('techbook-cli') - .description('TechBook CLI utilities.') - .version('0.0.1'); + .name("techbook-cli") + .description("TechBook CLI utilities.") + .version(version); -program.command('dev') - .description('techbook dev server') - .option('-ph, --h3-port ', 'h3 server port number', '3000') - .option('-ps, --sync-port ', 'sync port number', '3001') - .action(async ({ h3Port, syncPort }: { h3Port: string, syncPort: string }) => { +program + .command("dev") + .description("techbook dev server") + .option("-ph, --h3-port ", "h3 server port number", "3000") + .option("-ps, --sync-port ", "sync port number", "3001") + .action( + async ({ h3Port, syncPort }: { h3Port: string; syncPort: string }) => { + const { result } = concurrently( + [ + { command: "npx --yes vite-node src/main.ts", name: "init" }, + { + command: + 'npx --yes chokidar-cli "src/**/*.ts" "src/**/*.html" "docs/**/*.md" -c "npx --yes vite-node src/main.ts"', + name: "main", + }, + { + command: `npx --yes listhen --host 0.0.0.0 --port ${h3Port} --watch ./src/viewer.ts`, + name: "h3", + }, + { + command: `npx --yes wait-on --interval 500 ./dist/lockfile && npx --yes tailwindcss@latest -i ./src/${cssSrcFileName} -o ./dist/global.css --watch --no-autoprefixer --postcss ./postcss.config.cjs`, + name: "tailwind", + }, + { + command: `npx --yes wait-on --interval 500 ./dist/global.css ./dist/lockfile && npx --yes browser-sync start --no-ui --port ${syncPort} --config 'bs-config.js' --files="dist/lockfile,dist/global.css,images/*" --reload-delay=4000 --reload-throttle=4000 --startPath="/index.html#src=/dist/publication.json&bookMode=true&renderAllPages=true&style=/dist/global.css" --browser "google chrome"`, + name: "browser-sync", + }, + // { command: `npx --yes wait-on --interval 500 ./dist/global.css ./dist/lockfile && npx --yes browser-sync start --no-ui --port ${syncPort} --config 'bs-config.js' --files="dist/*" --reload-delay=4000 --reload-throttle=4000 --startPath="/index.html#src=/dist/publication.json&bookMode=true&renderAllPages=true&style=/dist/global.css" --browser "google chrome"`, name: "browser-sync" }, + ], + { + killOthers: "failure", + prefixColors: "auto", + }, + ); + const closeEvents = await result; + console.log("closed!!!"); + }, + ); + +program + .command("build") + .description("techbook build pdf") + .action(async () => { const { result } = concurrently( [ - { command: "npx --yes vite-node src/main.ts", name: "init" }, - { command: "npx --yes chokidar-cli \"src/**/*.ts\" \"src/**/*.html\" \"docs/**/*.md\" -c \"npx --yes vite-node src/main.ts\"", name: "main" }, - { command: `npx --yes listhen --host 0.0.0.0 --port ${h3Port} --watch ./src/viewer.ts`, name: "h3" }, - { command: `npx --yes wait-on --interval 500 ./dist/lockfile && npx --yes tailwindcss@latest -i ./src/${cssSrcFileName} -o ./dist/global.css --watch --no-autoprefixer --postcss ./postcss.config.cjs`, name: "tailwind" }, - { command: `npx --yes wait-on --interval 500 ./dist/global.css ./dist/lockfile && npx --yes browser-sync start --no-ui --port ${syncPort} --config 'bs-config.js' --files="dist/lockfile,dist/global.css,images/*" --reload-delay=4000 --reload-throttle=4000 --startPath="/index.html#src=/dist/publication.json&bookMode=true&renderAllPages=true&style=/dist/global.css" --browser "google chrome"`, name: "browser-sync" }, - // { command: `npx --yes wait-on --interval 500 ./dist/global.css ./dist/lockfile && npx --yes browser-sync start --no-ui --port ${syncPort} --config 'bs-config.js' --files="dist/*" --reload-delay=4000 --reload-throttle=4000 --startPath="/index.html#src=/dist/publication.json&bookMode=true&renderAllPages=true&style=/dist/global.css" --browser "google chrome"`, name: "browser-sync" }, + { + command: "npx --yes vite-node src/main.ts", + name: "main", + }, + { + command: `npx --yes tailwindcss@latest -i ./src/${cssSrcFileName} -o ./dist/global.css --no-autoprefixer --postcss ./postcss.config.cjs`, + name: "tailwind", + }, + { + command: "npx --yes @vivliostyle/cli build --style ./dist/global.css", + name: "vivliostyle", + }, ], { killOthers: "failure", prefixColors: "auto", + maxProcesses: 1, }, ); const closeEvents = await result; console.log("closed!!!"); }); -program.command('build') - .description('techbook build pdf') +program + .command("kdp") + .description("techbook build pdf for kindle direct publishing") .action(async () => { const { result } = concurrently( [ - { command: "npx --yes vite-node src/main.ts", name: "main" }, - { command: `npx --yes tailwindcss@latest -i ./src/${cssSrcFileName} -o ./dist/global.css --no-autoprefixer --postcss ./postcss.config.cjs`, name: "tailwind" }, - { command: "npx --yes @vivliostyle/cli build --style ./dist/global.css", name: "vivliostyle" }, + { + command: "npx --yes vite-node src/main.ts -kdp", + name: "main", + }, + { + command: `npx --yes tailwindcss@latest -i ./src/${cssSrcFileName} -o ./dist/global.css --no-autoprefixer --postcss ./postcss.config.cjs`, + name: "tailwind", + }, + { + command: "npx --yes @vivliostyle/cli build --style ./dist/global.css", + name: "vivliostyle", + }, ], { killOthers: "failure", diff --git a/src/cover-template.html b/src/cover-template.html index 79a5691..bc8094d 100644 --- a/src/cover-template.html +++ b/src/cover-template.html @@ -16,7 +16,7 @@ {{#switch kind}} {{#case "start"}}
-
{{title}}
+
{{title}}
{{publisher}} 編 著
{{lastEdition.datetimeView}} {{lastEdition.version}} {{lastEdition.name}}
diff --git a/src/cover.ts b/src/cover.ts index 7102f3d..0c34997 100644 --- a/src/cover.ts +++ b/src/cover.ts @@ -1,14 +1,14 @@ import fs from "fs"; import Handlebars from "handlebars"; +import config from "../techbook.config"; import { + backCoverDistPath, coverTemplateHtmlPath, - handlebarCompileOptions, + endCoverDistPath, frontCoverDistPath, - backCoverDistPath, + handlebarCompileOptions, startCoverDistPath, - endCoverDistPath, } from "./constants"; -import config from "../techbook.config"; // HTMLのテンプレートをHandlebarsで読み込む const templateHtml = Handlebars.compile( @@ -16,42 +16,45 @@ const templateHtml = Handlebars.compile( handlebarCompileOptions, ); -export const coverCompile = () => { +export const coverCompile = (isKDP: { isKDP: boolean }) => { const edition = config.editions[config.editions.length - 1]; { const html = templateHtml({ kind: "front", - coverImage: config.cover.front, + coverImage: isKDP ? undefined : config.cover.front, title: config.title, publisher: config.publisher, author: config.author, lastEdition: edition, }); fs.writeFileSync(frontCoverDistPath, html); - }{ + } + { const html = templateHtml({ kind: "back", - coverImage: config.cover.back, + coverImage: isKDP ? undefined : config.cover.back, title: config.title, publisher: config.publisher, author: config.author, lastEdition: edition, }); fs.writeFileSync(backCoverDistPath, html); - }{ + } + { const html = templateHtml({ kind: "start", - coverImage: config.cover.start, + coverImage: isKDP ? undefined : config.cover.start, title: config.title, publisher: config.publisher, author: config.author, lastEdition: edition, }); fs.writeFileSync(startCoverDistPath, html); - }{ + } + { const html = templateHtml({ kind: "end", - coverImage: config.cover.end, + coverImage: isKDP ? undefined : config.cover.end, title: config.title, publisher: config.publisher, author: config.author, diff --git a/src/generateVivlioStyleConfig.ts b/src/generateVivlioStyleConfig.ts index aa5d79c..5363dd6 100644 --- a/src/generateVivlioStyleConfig.ts +++ b/src/generateVivlioStyleConfig.ts @@ -15,7 +15,9 @@ import { } from "./constants"; import { docsHeadingList } from "./toc"; -export default function generateVivlioStyleConfig() { +export default function generateVivlioStyleConfig({ + isKDP, +}: { isKDP: boolean }) { const { title, author, size } = config; // MEMO: build(PDF生成)用にvivliostyle.config.cjsを生成する const docsEntryList = docsHeadingList.map(({ headings, dist }) => ({ @@ -29,7 +31,7 @@ export default function generateVivlioStyleConfig() { size: size, entryContext: ".", entry: [ - frontCoverDistPath, + isKDP ? undefined : frontCoverDistPath, startCoverDistPath, tocDistPath, introductionDistPath, @@ -39,7 +41,7 @@ export default function generateVivlioStyleConfig() { profileDistPath, colophonDistPath, endCoverDistPath, - backCoverDistPath, + isKDP ? undefined : backCoverDistPath, ].filter((v) => !!v), workspaceDir: ".vivliostyle", toc: false, @@ -65,7 +67,7 @@ export default function generateVivlioStyleConfig() { inLanguage: "ja", dateModified: new Date().toISOString(), readingOrder: [ - { url: frontCoverDistPath }, + isKDP ? undefined : { url: frontCoverDistPath }, { url: startCoverDistPath }, { url: tocDistPath }, { url: introductionDistPath }, @@ -75,7 +77,7 @@ export default function generateVivlioStyleConfig() { { url: profileDistPath }, { url: colophonDistPath }, { url: endCoverDistPath }, - { url: backCoverDistPath }, + isKDP ? undefined : { url: backCoverDistPath }, ].filter((v) => !!v), resources: [], links: [], diff --git a/src/global-105x173.css b/src/global-105x173.css index 3bf252c..0cc96b5 100644 --- a/src/global-105x173.css +++ b/src/global-105x173.css @@ -72,6 +72,7 @@ } @top-right { content: "第" counter(chapter) "章 " env(doc-title); + width: 350px; } @top-left-corner { content: element(topRightCorner); diff --git a/src/main.ts b/src/main.ts index b8b3f67..5abed32 100644 --- a/src/main.ts +++ b/src/main.ts @@ -24,6 +24,9 @@ import "./split"; import "./switch"; import { docsHeadingList, rightPillarChapterList, tocCompile } from "./toc"; +// 引数に"-kdp"がある場合はtrueにする +const isKDP = process.argv.indexOf("-kdp") >= 0; + // Handlebarsにヘルパーを登録する chatRegisterHelper(); docrefRegisterHelper(); @@ -31,8 +34,6 @@ appendixRegisterHelper(); footnoteRegisterHelper(); pageBreakRegisterHelper(); -// const args = process.argv.slice(1); - // HTMLのテンプレートをHandlebarsで読み込む const chapterTemplateHtml = Handlebars.compile( fs @@ -42,11 +43,11 @@ const chapterTemplateHtml = Handlebars.compile( : chapterTemplateHtmlPath, ) .toString(), - handlebarCompileOptions, + handlebarCompileOptions, ); // configの作成 -generateVivlioStyleConfig(); +generateVivlioStyleConfig({ isKDP }); // プレコンパイルする const preCompile = ( @@ -89,7 +90,7 @@ const preCompile = ( console.log("start preCompile."); -coverCompile(); +coverCompile({ isKDP }); tocCompile(); introductionCompile(); finallyCompile(); diff --git a/tsconfig.json b/tsconfig.json index a8be2a7..32f757a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,8 @@ "lib": [ "es2021", "ESNext", - ] + ], + "resolveJsonModule": true, + "esModuleInterop": true, } } \ No newline at end of file