Skip to content

Commit

Permalink
feat: stripYamlFrontmatter option (#2387)
Browse files Browse the repository at this point in the history
* feat: `stripYamlFrontmatter` option
  • Loading branch information
hrueger committed Sep 4, 2023
1 parent 67ee6ac commit dc4a16d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features

- Added `stripYamlFrontmatter` config option, #2381.
- Navigation is now written to a JS file and built dynamically, which significantly decreases document generation time
with large projects and also provides large space benefits. Themes may now override `DefaultTheme.buildNavigation`
to customize the displayed navigation tree, #2287.
Expand Down
21 changes: 19 additions & 2 deletions src/lib/converter/plugins/PackagePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class PackagePlugin extends ConverterComponent {
@Option("readme")
accessor readme!: string;

@Option("stripYamlFrontmatter")
accessor stripYamlFrontmatter!: boolean;

@Option("entryPointStrategy")
accessor entryPointStrategy!: EntryPointStrategy;

Expand Down Expand Up @@ -99,7 +102,9 @@ export class PackagePlugin extends ConverterComponent {
if (this.readme) {
// Readme path provided, read only that file.
try {
this.readmeContents = readFile(this.readme);
this.readmeContents = this.processReadmeContents(
readFile(this.readme),
);
this.readmeFile = this.readme;
} catch {
this.application.logger.error(
Expand All @@ -118,11 +123,23 @@ export class PackagePlugin extends ConverterComponent {

if (result) {
this.readmeFile = result.file;
this.readmeContents = result.content;
this.readmeContents = this.processReadmeContents(
result.content,
);
}
}
}

private processReadmeContents(contents: string) {
if (this.stripYamlFrontmatter) {
return contents.replace(
/^\s*---\r?\n[\s\S]*?\r?\n---\s*?\r?\n\s*/,
"",
);
}
return contents;
}

private onBeginResolve(context: Context) {
this.addEntries(context.project);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface TypeDocOptionMap {
gitRevision: string;
gitRemote: string;
readme: string;
stripYamlFrontmatter: boolean;

// Output
out: string;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
help: "Path to the readme file that should be displayed on the index page. Pass `none` to disable the index page and start the documentation on the globals page.",
type: ParameterType.Path,
});
options.addDeclaration({
name: "stripYamlFrontmatter",
help: "Strip YAML frontmatter from markdown files.",
type: ParameterType.Boolean,
});
options.addDeclaration({
name: "cname",
help: "Set the CNAME file text, it's useful for custom domains on GitHub Pages.",
Expand Down

0 comments on commit dc4a16d

Please sign in to comment.