Skip to content

Commit a7e9e04

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

2 files changed

Lines changed: 199 additions & 250 deletions

File tree

build/paginate-pieces.ts

Lines changed: 4 additions & 6 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');
@@ -22,14 +22,12 @@ const themeScale = theme?.font?.scale ?? 1;
2222
// Build pagination config
2323
const paginationConfig: PaginationConfig = {
2424
columns: config?.reader?.columns ?? 2,
25-
linesPerPage: config?.reader?.linesPerPage,
2625
pagination: config?.reader?.pagination,
2726
};
2827

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

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

3432
type PiecePage = {
3533
pieceSlug: string;
@@ -63,7 +61,7 @@ piecesIndex.forEach((piece: any) => {
6361
const parsed = fm(raw);
6462
const content = parsed.body;
6563

66-
const chunks = chunkContent(content, LINES_PER_PAGE, CHARS_PER_LINE);
64+
const chunks = chunkContent(content, CHARS_PER_PAGE);
6765
const totalPages = chunks.length;
6866

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

0 commit comments

Comments
 (0)