Skip to content

Commit f281491

Browse files
feat: infer toc and positions from network instead of scrolling through them
1 parent f2c8f0b commit f281491

13 files changed

+585
-782
lines changed

eslint.config.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import { config } from '@fisch0920/config/eslint'
2+
import { globalIgnores } from 'eslint/config'
23

3-
export default [
4-
...config,
5-
{
6-
ignores: ['**/out/**', '**/dist/**']
7-
}
8-
]
4+
export default [...config, globalIgnores(['out', 'dist', 'examples'])]

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
"playwright": "^1.56.1",
3838
"playwright-core": "^1.56.1",
3939
"sharp": "^0.34.4",
40+
"sort-keys": "^6.0.0",
4041
"tar": "^7.5.1",
4142
"tempy": "^3.1.0",
4243
"type-fest": "^5.1.0",
4344
"unrealspeech-api": "^1.0.2"
4445
},
4546
"devDependencies": {
46-
"@fisch0920/config": "^1.3.3",
47+
"@fisch0920/config": "^1.3.4",
4748
"@types/fluent-ffmpeg": "^2.1.26",
4849
"@types/hh-mm-ss": "^1.2.3",
4950
"@types/node": "^24.9.1",

pnpm-lock.yaml

Lines changed: 199 additions & 580 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ enablePrePostScripts: true
22

33
minimumReleaseAge: 1440
44

5+
minimumReleaseAgeExclude:
6+
- '@fisch0920/config'
7+
58
onlyBuiltDependencies:
69
- esbuild
710
- sharp

src/export-book-audio.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
ffmpegOnProgress,
1717
fileExists,
1818
getEnv,
19-
hashObject
19+
hashObject,
20+
readJsonFile
2021
} from './utils'
2122

2223
type TTSEngine = 'openai' | 'unrealspeech'
@@ -35,11 +36,10 @@ async function main() {
3536
const audioOutDir = path.join(outDir, isPreview ? 'audio-previews' : 'audio')
3637
await fs.mkdir(audioOutDir, { recursive: true })
3738

38-
const content = (
39-
JSON.parse(
40-
await fs.readFile(path.join(outDir, 'content.json'), 'utf8')
41-
) as ContentChunk[]
39+
const rawContent = await readJsonFile<ContentChunk[]>(
40+
path.join(outDir, 'content.json')
4241
)
42+
const content = rawContent
4343
.filter((c) => !isPreview || c.page === 1)
4444
.concat(
4545
isPreview
@@ -53,11 +53,11 @@ async function main() {
5353
]
5454
: []
5555
)
56-
57-
const metadata = JSON.parse(
58-
await fs.readFile(path.join(outDir, 'metadata.json'), 'utf8')
59-
) as BookMetadata
6056
assert(content.length, 'no book content found')
57+
58+
const metadata = await readJsonFile<BookMetadata>(
59+
path.join(outDir, 'metadata.json')
60+
)
6161
assert(metadata.meta, 'invalid book metadata: missing meta')
6262
assert(metadata.toc?.length, 'invalid book metadata: missing toc')
6363

src/export-book-markdown.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import fs from 'node:fs/promises'
44
import path from 'node:path'
55

66
import type { BookMetadata, ContentChunk } from './types'
7-
import { assert, getEnv } from './utils'
7+
import { assert, getEnv, readJsonFile } from './utils'
88

99
async function main() {
1010
const asin = getEnv('ASIN')
1111
assert(asin, 'ASIN is required')
1212

1313
const outDir = path.join('out', asin)
1414

15-
const content = JSON.parse(
16-
await fs.readFile(path.join(outDir, 'content.json'), 'utf8')
17-
) as ContentChunk[]
18-
const metadata = JSON.parse(
19-
await fs.readFile(path.join(outDir, 'metadata.json'), 'utf8')
20-
) as BookMetadata
15+
const content = await readJsonFile<ContentChunk[]>(
16+
path.join(outDir, 'content.json')
17+
)
18+
const metadata = await readJsonFile<BookMetadata>(
19+
path.join(outDir, 'metadata.json')
20+
)
2121
assert(content.length, 'no book content found')
2222
assert(metadata.meta, 'invalid book metadata: missing meta')
2323
assert(metadata.toc?.length, 'invalid book metadata: missing toc')

0 commit comments

Comments
 (0)