this repo has no description

Reformat combined output title

Changed files
+17 -11
src
+1 -1
src/index.ts
···
log(`completed page ${idx + 1} of ${pages.length}`);
}
const output = await concatMarkdown(contents);
-
const formatted = await formatMarkdown(output);
+
const formatted = await formatMarkdown(site.name, output);
const file = path.join(outputPath, `llms-full-${site.name}.txt`);
await fs.writeFile(file, formatted, 'utf-8');
}
+15 -9
src/prettier.ts
···
import remarkStringify from 'remark-stringify';
import remarkGfm from 'remark-gfm';
-
async function reformat(content: string): Promise<string> {
+
import { remarkTitle } from './unified';
+
+
async function reformat(content: string, title: string): Promise<string> {
// NOTE: We reformat with remark again to get rid of prettier's
// table formatting mostly. This doesn't work well as LLM input
const md = await unified()
···
tablePipeAlign: false,
tableCellPadding: false,
})
+
.use(remarkTitle, { title })
.use(remarkStringify, {
bullet: '-',
incrementListMarker: false,
···
return md.toString();
}
-
export async function formatMarkdown(input: string) {
-
return reformat(await format(input, {
-
semi: false,
-
singleQuote: false,
-
trailingComma: 'es5',
-
proseWrap: 'never',
-
parser: 'markdown',
-
}));
+
export async function formatMarkdown(title: string, input: string) {
+
return reformat(
+
await format(input, {
+
semi: false,
+
singleQuote: false,
+
trailingComma: 'es5',
+
proseWrap: 'never',
+
parser: 'markdown',
+
}),
+
title
+
);
}
+1 -1
src/unified.ts
···
}
}
-
function remarkTitle(opts: { title: string }) {
+
export function remarkTitle(opts: { title: string }) {
return function checkTitleTransformer(root: Root) {
const node = root.children[0]!;
const replacement: Heading = {