mirror of
https://github.com/nestjs/docs.nestjs.com.git
synced 2026-02-21 20:31:32 +00:00
31 lines
900 B
TypeScript
31 lines
900 B
TypeScript
import { Processor, DocCollection } from 'dgeni';
|
|
|
|
/**
|
|
* Extracts the title of a content file.
|
|
* This processor assumes that the first line of the
|
|
* content includes the title.
|
|
*/
|
|
export class ExtractContentTitleProcessor implements Processor {
|
|
$runAfter = ['renderDocsProcessor'];
|
|
$runBefore = ['convertToJsonProcessor'];
|
|
$process(docs: DocCollection) {
|
|
docs.forEach((doc) => {
|
|
if (doc.docType === 'content') {
|
|
try {
|
|
const firstLine: string = doc.content.split('\n')[0];
|
|
const title = firstLine.replace(/#/g, '').trim();
|
|
doc.title = title;
|
|
} catch {
|
|
// We do not care if the title does not exist here
|
|
// convertToJson will complain later in case the title
|
|
// does not exist
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export function extractContentTitleProcessor() {
|
|
return new ExtractContentTitleProcessor();
|
|
}
|