diff --git a/packages/contented-pipeline/src/Pipeline.ts b/packages/contented-pipeline/src/Pipeline.ts index 08018c92..7be78bad 100644 --- a/packages/contented-pipeline/src/Pipeline.ts +++ b/packages/contented-pipeline/src/Pipeline.ts @@ -97,6 +97,7 @@ export abstract class ContentedPipeline { modifiedDate: await this.computeModifiedDate(filePath), sections, fields: {}, + headings: [], }; } diff --git a/packages/contented-pipeline/src/PipelineFile.ts b/packages/contented-pipeline/src/PipelineFile.ts index a6991c33..31e3ad23 100644 --- a/packages/contented-pipeline/src/PipelineFile.ts +++ b/packages/contented-pipeline/src/PipelineFile.ts @@ -14,6 +14,7 @@ export interface FileIndex extends PipelineFile { sections: string[]; modifiedDate: number; fields: Record; + headings: FileContentHeadings[]; } /** @@ -21,7 +22,6 @@ export interface FileIndex extends PipelineFile { */ export interface FileContent extends FileIndex { html: string; - headings: FileContentHeadings[]; } /** diff --git a/packages/contented-processor/src/ContentedProcessor.ts b/packages/contented-processor/src/ContentedProcessor.ts index b78affd2..6066a404 100644 --- a/packages/contented-processor/src/ContentedProcessor.ts +++ b/packages/contented-processor/src/ContentedProcessor.ts @@ -63,7 +63,7 @@ export class ContentedProcessor { for (const file of files) { for (const content of await this.process(file)) { - result.pipelines[content.type].push(cloneFileIndex(content)); + result.pipelines[content.type].push(toFileIndex(content)); } } @@ -169,7 +169,7 @@ function getPipelineUniqueKey(pipeline: Pipeline) { return `${pipeline.type}:${pipeline.dir ?? ''}:${pipeline.pattern.join(',')}`; } -function cloneFileIndex(index: FileIndex): FileIndex { +function toFileIndex(index: FileContent): FileIndex { return { fileId: index.fileId, fields: index.fields, @@ -177,5 +177,6 @@ function cloneFileIndex(index: FileIndex): FileIndex { path: index.path, sections: index.sections, type: index.type, + headings: index.headings, }; } diff --git a/packages/contented-processor/src/ContentedProcessor.unit.ts b/packages/contented-processor/src/ContentedProcessor.unit.ts index fd0bd7dd..83a96852 100644 --- a/packages/contented-processor/src/ContentedProcessor.unit.ts +++ b/packages/contented-processor/src/ContentedProcessor.unit.ts @@ -152,6 +152,7 @@ describe('build', () => { description: 'Title', }, fileId: expect.stringMatching(/[0-f]{64}/), + headings: [], modifiedDate: expect.any(Number), path: '/path-1', sections: [], @@ -163,6 +164,14 @@ describe('build', () => { description: 'Content', }, fileId: expect.stringMatching(/[0-f]{64}/), + headings: [ + { + children: [], + depth: 2, + headingId: 'header', + title: 'Header', + }, + ], modifiedDate: expect.any(Number), path: '/category/section/path', sections: ['Category', 'Section'], @@ -190,6 +199,7 @@ describe('build', () => { description: 'Title', }, fileId: expect.stringMatching(/[0-f]{64}/), + headings: [], modifiedDate: expect.any(Number), path: '/path-1', sections: [], @@ -201,6 +211,20 @@ describe('build', () => { description: 'Markdown for testing ContentedProcessor.unit.ts.', }, fileId: expect.stringMatching(/[0-f]{64}/), + headings: [ + { + children: [], + depth: 1, + headingId: 'what-is-going-on', + title: 'What is going on', + }, + { + children: [], + depth: 1, + headingId: 'multiple-title-but-take-the-first-one', + title: 'Multiple title but take the first one', + }, + ], modifiedDate: expect.any(Number), path: '/foo-bar', sections: [], @@ -212,6 +236,14 @@ describe('build', () => { description: 'Content', }, fileId: expect.stringMatching(/[0-f]{64}/), + headings: [ + { + children: [], + depth: 2, + headingId: 'header', + title: 'Header', + }, + ], modifiedDate: expect.any(Number), path: '/category/section/path', sections: ['Category', 'Section'], @@ -223,6 +255,14 @@ describe('build', () => { description: 'Content', }, fileId: expect.stringMatching(/[0-f]{64}/), + headings: [ + { + children: [], + depth: 2, + headingId: 'header', + title: 'Header', + }, + ], modifiedDate: expect.any(Number), path: '/category/slug', sections: ['Category'],