Skip to content

Commit a901b49

Browse files
authored
feat: support versionInTitle input in assemble-docs action (#52)
Adds support for specifying `versionInTitle` parameter in the `versions.json` file
1 parent 0fbebe4 commit a901b49

5 files changed

Lines changed: 37 additions & 14 deletions

File tree

actions/assemble-docs/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ This action:
99

1010
## Action inputs
1111

12-
| Input | Description | Default |
13-
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
14-
| `assets_dir` | Path to the directory containing the documentation assets to be assembled. | _required_ |
15-
| `version` | The subpath at which the assembled docs will be published. Allowed values: `vX` , `vX.Y` , `vX.Y.Z` , `latest` , `beta` , `dev` , `next` , `nightly` , `canary`. | _required_ |
16-
| `version_label` | Optional label value to set for this version's option in the website sidebar version dropdown. | `{inputs.version}` |
17-
| `target_dir` | The folder where the assembled docs must be saved. | _required_ |
12+
| Input | Description | Default |
13+
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
14+
| `assets_dir` | Path to the directory containing the documentation assets to be assembled. | _required_ |
15+
| `version` | The subpath at which the assembled docs will be published. Allowed values: `vX` , `vX.Y` , `vX.Y.Z` , `latest` , `beta` , `dev` , `next` , `nightly` , `canary`. | _required_ |
16+
| `version_label` | Optional label value to set for this version's option in the website sidebar version dropdown. | `{inputs.version}` |
17+
| `version_in_title` | Optional version label to show on top of the website sidebar version dropdown. | `''` |
18+
| `target_dir` | The folder where the assembled docs must be saved. | _required_ |
1819

1920
## Example usage
2021

actions/assemble-docs/action.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
version_label:
1212
description: "Optional label value to set for this version's option in the website sidebar version dropdown. Defaults to the value of the `version` input."
1313
required: false
14+
version_in_title:
15+
description: 'Optional version label to show on top of the website sidebar version dropdown.'
16+
required: false
1417
target_dir:
1518
description: 'The folder where the assembled docs must be saved.'
1619
required: true

actions/assemble-docs/dist/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19190,13 +19190,20 @@ function isValidVersion(version2) {
1919019190

1919119191
// src/upsert-versions-json.ts
1919219192
async function upsertVersionsJson(params) {
19193-
const { versionsJsonPath, version: version2, versionLabel } = params;
19193+
const { versionsJsonPath, version: version2, versionLabel, versionInTitle } = params;
1919419194
let versions = (0, import_action_utils.readJsonFile)(versionsJsonPath) || [];
1919519195
const versionEntryIndex = versions.findIndex((v) => v.path === version2);
1919619196
if (versionEntryIndex !== -1) {
19197-
versions[versionEntryIndex].label = versionLabel;
19197+
const versionEntry = versions[versionEntryIndex];
19198+
versionEntry.label = versionLabel;
19199+
if (versionInTitle) {
19200+
versionEntry.versionInTitle = versionInTitle;
19201+
} else {
19202+
delete versionEntry.versionInTitle;
19203+
}
19204+
versions[versionEntryIndex] = versionEntry;
1919819205
} else {
19199-
versions.push({ path: version2, label: versionLabel });
19206+
versions.push({ path: version2, label: versionLabel, versionInTitle });
1920019207
}
1920119208
versions = versions.sort((a, b) => {
1920219209
if (a.path === LATEST_VERSION_NAME && b.path !== LATEST_VERSION_NAME) {
@@ -19217,6 +19224,7 @@ async function run() {
1921719224
const assetsDir = (0, import_action_utils2.getInput)("assets_dir");
1921819225
const version2 = (0, import_action_utils2.getInput)("version");
1921919226
const versionLabel = (0, import_action_utils2.getOptInput)("version_label", version2);
19227+
const versionInTitle = (0, import_action_utils2.getOptInput)("version_in_title", "");
1922019228
const targetDir = (0, import_action_utils2.getInput)("target_dir");
1922119229
const targetZipFile = import_node_path.default.join(process.cwd(), targetDir, `${version2}.zip`);
1922219230
const targetVersionsJsonFile = import_node_path.default.join(
@@ -19241,7 +19249,8 @@ async function run() {
1924119249
await upsertVersionsJson({
1924219250
versionsJsonPath: targetVersionsJsonFile,
1924319251
version: version2,
19244-
versionLabel
19252+
versionLabel,
19253+
versionInTitle
1924519254
});
1924619255
}
1924719256
core.info(`Docs assembled for version ${version2}.`);

actions/assemble-docs/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export async function run(): Promise<void> {
1515
const assetsDir = getInput('assets_dir');
1616
const version = getInput('version');
1717
const versionLabel = getOptInput('version_label', version);
18+
const versionInTitle = getOptInput('version_in_title', '');
1819
const targetDir = getInput('target_dir');
1920
const targetZipFile = path.join(process.cwd(), targetDir, `${version}.zip`);
2021
const targetVersionsJsonFile = path.join(
@@ -44,6 +45,7 @@ export async function run(): Promise<void> {
4445
versionsJsonPath: targetVersionsJsonFile,
4546
version,
4647
versionLabel,
48+
versionInTitle,
4749
});
4850
}
4951

actions/assemble-docs/src/upsert-versions-json.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import { writeJsonFile, readJsonFile } from '@dfinity/action-utils';
22
import { LATEST_VERSION_NAME } from './versions';
33

4-
type VersionEntry = { path: string; label: string };
4+
type VersionEntry = { path: string; label: string; versionInTitle?: string };
55

66
export async function upsertVersionsJson(params: {
77
versionsJsonPath: string;
88
version: string;
99
versionLabel: string;
10+
versionInTitle?: string;
1011
}): Promise<void> {
11-
const { versionsJsonPath, version, versionLabel } = params;
12+
const { versionsJsonPath, version, versionLabel, versionInTitle } = params;
1213

1314
let versions = readJsonFile<VersionEntry[]>(versionsJsonPath) || [];
1415

1516
const versionEntryIndex = versions.findIndex(v => v.path === version);
1617
if (versionEntryIndex !== -1) {
17-
versions[versionEntryIndex].label = versionLabel;
18+
const versionEntry = versions[versionEntryIndex];
19+
versionEntry.label = versionLabel;
20+
if (versionInTitle) {
21+
versionEntry.versionInTitle = versionInTitle;
22+
} else {
23+
delete versionEntry.versionInTitle;
24+
}
25+
versions[versionEntryIndex] = versionEntry;
1826
} else {
19-
versions.push({ path: version, label: versionLabel });
27+
versions.push({ path: version, label: versionLabel, versionInTitle });
2028
}
2129

2230
// Sort versions: latest first, then reverse alphabetically by path

0 commit comments

Comments
 (0)