Skip to content

Commit a99cfc6

Browse files
committed
Update api-documenter for devsite changes.
1 parent 1703bb3 commit a99cfc6

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

repo-scripts/api-documenter/src/cli/BaseAction.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ export interface IBuildApiModelResult {
4141
inputFolder: string;
4242
outputFolder: string;
4343
addFileNameSuffix: boolean;
44+
projectName?: string;
4445
}
4546

4647
export abstract class BaseAction extends CommandLineAction {
4748
private _inputFolderParameter!: CommandLineStringParameter;
4849
private _outputFolderParameter!: CommandLineStringParameter;
4950
private _fileNameSuffixParameter!: CommandLineFlagParameter;
51+
private _projectNameParameter!: CommandLineStringParameter;
5052

5153
protected onDefineParameters(): void {
5254
// override
@@ -79,6 +81,15 @@ export abstract class BaseAction extends CommandLineAction {
7981
`This is to avoid name conflict in case packageA also has, for example, an entry point with the same name in lowercase.` +
8082
`This option is specifically designed for the Admin SDK where such case occurs.`
8183
});
84+
85+
this._projectNameParameter = this.defineStringParameter({
86+
parameterLongName: '--project',
87+
parameterShortName: '-p',
88+
argumentName: 'PROJECT',
89+
description:
90+
`Name of the project (js, admin, functions, etc.). This will be ` +
91+
`used in the devsite header path to the _project.yaml file.`
92+
});
8293
}
8394

8495
protected buildApiModel(): IBuildApiModelResult {
@@ -105,7 +116,7 @@ export abstract class BaseAction extends CommandLineAction {
105116

106117
this._applyInheritDoc(apiModel, apiModel);
107118

108-
return { apiModel, inputFolder, outputFolder, addFileNameSuffix };
119+
return { apiModel, inputFolder, outputFolder, addFileNameSuffix, projectName: this._projectNameParameter.value };
109120
}
110121

111122
// TODO: This is a temporary workaround. The long term plan is for API Extractor's DocCommentEnhancer

repo-scripts/api-documenter/src/cli/MarkdownAction.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ export class MarkdownAction extends BaseAction {
3535

3636
protected async onExecute(): Promise<void> {
3737
// override
38-
const { apiModel, outputFolder, addFileNameSuffix } = this.buildApiModel();
38+
const { apiModel, outputFolder, addFileNameSuffix, projectName } = this.buildApiModel();
39+
40+
if (!projectName) {
41+
throw new Error('No project name provided. Use --project.');
42+
}
3943

4044
const markdownDocumenter: MarkdownDocumenter = new MarkdownDocumenter({
4145
apiModel,
4246
documenterConfig: undefined,
4347
outputFolder,
44-
addFileNameSuffix
48+
addFileNameSuffix,
49+
projectName
4550
});
4651
markdownDocumenter.generateFiles();
4752
}

repo-scripts/api-documenter/src/documenters/MarkdownDocumenter.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface IMarkdownDocumenterOptions {
9292
documenterConfig: DocumenterConfig | undefined;
9393
outputFolder: string;
9494
addFileNameSuffix: boolean;
95+
projectName: string;
9596
}
9697

9798
/**
@@ -106,12 +107,14 @@ export class MarkdownDocumenter {
106107
private readonly _outputFolder: string;
107108
private readonly _pluginLoader: PluginLoader;
108109
private readonly _addFileNameSuffix: boolean;
110+
private readonly _projectName: string;
109111

110112
public constructor(options: IMarkdownDocumenterOptions) {
111113
this._apiModel = options.apiModel;
112114
this._documenterConfig = options.documenterConfig;
113115
this._outputFolder = options.outputFolder;
114116
this._addFileNameSuffix = options.addFileNameSuffix;
117+
this._projectName = options.projectName;
115118
this._tsdocConfiguration = CustomDocNodes.configuration;
116119
this._markdownEmitter = new CustomMarkdownEmitter(this._apiModel);
117120

@@ -165,12 +168,14 @@ export class MarkdownDocumenter {
165168

166169
// devsite headers
167170
stringBuilder.append(
168-
'{% extends "_internal/templates/reference.html" %}\n'
169-
);
171+
`Project: /docs/reference/${this._projectName}/_project.yaml
172+
Book: /docs/reference/_book.yaml
173+
page_type: reference
174+
`);
175+
170176
stringBuilder.append(
171-
`{% block title %}${headingNode.title}{% endblock title %}\n`
177+
`# ${headingNode.title}\n`
172178
);
173-
stringBuilder.append('{% block body %}\n');
174179

175180
this._markdownEmitter.emit(stringBuilder, output, {
176181
contextApiItem: apiItem,
@@ -179,8 +184,6 @@ export class MarkdownDocumenter {
179184
}
180185
});
181186

182-
stringBuilder.append('{% endblock body %}\n');
183-
184187
let pageContent: string = stringBuilder.toString();
185188

186189
if (this._pluginLoader.markdownDocumenterFeature) {
@@ -253,9 +256,8 @@ export class MarkdownDocumenter {
253256
output.push(
254257
new DocHeading({
255258
configuration,
256-
title: `${packageName}${
257-
apiItem.displayName && '/' + apiItem.displayName
258-
}`
259+
title: `${packageName}${apiItem.displayName && '/' + apiItem.displayName
260+
}`
259261
})
260262
);
261263
break;

0 commit comments

Comments
 (0)