Skip to content

Commit b98c134

Browse files
refactor: improve paragraph chunking logic in content chunker
1 parent 91ae5bb commit b98c134

File tree

2 files changed

+197
-253
lines changed

2 files changed

+197
-253
lines changed

build/paginate-pieces.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import fm from "front-matter";
44
import yaml from 'js-yaml';
5-
import { chunkContent, getLinesPerPage, getCharsPerLine, PaginationConfig } from './utils/markdown-chunker';
5+
import { chunkContent, getCharsPerPage, PaginationConfig } from './utils/markdown-chunker';
66
import { loadTheme } from './utils/theme-loader';
77

88
const publicDir = path.join(__dirname, '..', 'public');
@@ -14,22 +14,18 @@ const configPath = path.join(publicDir, 'config.yaml');
1414
const configRaw = fs.readFileSync(configPath, 'utf-8');
1515
const config = yaml.load(configRaw) as any;
1616

17-
// Load theme scale
1817
const themeName = config?.theme || 'journal';
1918
const theme = loadTheme(themeName);
2019
const themeScale = theme?.font?.scale ?? 1;
2120

22-
// Build pagination config
2321
const paginationConfig: PaginationConfig = {
2422
columns: config?.reader?.columns ?? 2,
25-
linesPerPage: config?.reader?.linesPerPage,
2623
pagination: config?.reader?.pagination,
2724
};
2825

29-
const LINES_PER_PAGE = getLinesPerPage(paginationConfig, themeScale);
30-
const CHARS_PER_LINE = getCharsPerLine(paginationConfig, themeScale);
26+
const CHARS_PER_PAGE = getCharsPerPage(paginationConfig, themeScale);
3127

32-
console.log(`[pagination]: theme=${themeName}, scale=${themeScale}, linesPerPage=${LINES_PER_PAGE}, charsPerLine=${CHARS_PER_LINE}`);
28+
console.log(`[pagination]: theme=${themeName}, scale=${themeScale}, charsPerPage=${CHARS_PER_PAGE}`);
3329

3430
type PiecePage = {
3531
pieceSlug: string;
@@ -63,7 +59,7 @@ piecesIndex.forEach((piece: any) => {
6359
const parsed = fm(raw);
6460
const content = parsed.body;
6561

66-
const chunks = chunkContent(content, LINES_PER_PAGE, CHARS_PER_LINE);
62+
const chunks = chunkContent(content, CHARS_PER_PAGE);
6763
const totalPages = chunks.length;
6864

6965
const pages: PiecePage[] = chunks.map((chunk, index) => ({

0 commit comments

Comments
 (0)