/**
* LoaderContext Factory - 로더에 전달되는 컨텍스트 생성
*
* 각 컬렉션의 load() 함수에 필요한 모든 유틸리티 제공
*/
import type {
LoaderContext,
DataStore,
MetaStore,
ContentLogger,
ManduContentConfig,
ContentWatcher,
ParseDataOptions,
RenderedContent,
} from "./types";
import { ValidationError } from "./types";
import { generateDigest } from "./digest";
import type { ZodSchema } from "zod";
/**
* LoaderContext 생성 옵션
*/
export interface CreateLoaderContextOptions {
/** 컬렉션 이름 */
collection: string;
/** 데이터 스토어 */
store: DataStore;
/** 메타 스토어 */
meta: MetaStore;
/** Mandu 설정 */
config: ManduContentConfig;
/** Zod 스키마 (검증용) */
schema?: ZodSchema;
/** Markdown 렌더러 */
markdownRenderer?: (content: string) => Promise$1
")
.replace(/^## (.*$)/gim, "$1
")
.replace(/^# (.*$)/gim, "$1
")
// 볼드/이탤릭
.replace(/\*\*(.+?)\*\*/g, "$1")
.replace(/\*(.+?)\*/g, "$1")
// 링크
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1')
// 코드 블록
.replace(/```([^`]+)```/g, "
")
.replace(/`([^`]+)`/g, "$1$1")
// 줄바꿈
.replace(/\n\n/g, "
")
.replace(/\n/g, "
");
// 헤딩 추출
const headings: Array<{ depth: 1 | 2 | 3 | 4 | 5 | 6; slug: string; text: string }> = [];
const headingRegex = /^(#{1,6})\s+(.+)$/gm;
let match;
while ((match = headingRegex.exec(content)) !== null) {
const depth = match[1].length as 1 | 2 | 3 | 4 | 5 | 6;
const text = match[2].trim();
const slug = text
.toLowerCase()
.replace(/[^a-z0-9가-힣]+/g, "-")
.replace(/^-|-$/g, "");
headings.push({ depth, slug, text });
}
return {
html: `
${html}
`, headings, }; }; }