Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stripYamlFrontmatter option #2387

Merged
merged 5 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

### Features

- Added `stripYamlFrontmatter` config option, #2381.

### Bug Fixes

- `@property` now works as expected if used to override a method's documentation.
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 {
@BindOption("readme")
readme!: string;

@BindOption("stripYamlFrontmatter")
stripYamlFrontmatter!: boolean;

@BindOption("entryPointStrategy")
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(
/^[\r\n\s]*---\r?\n[\s\S]*?\r?\n---[\r\n\s]+/,
hrueger marked this conversation as resolved.
Show resolved Hide resolved
"",
);
}
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