Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit bed8a1f

Browse files
casthewizseungpark
andauthored
DOP-3500: Account for aliases and gitBranchName in merged ToC links (#765)
* DOP-3500: Add alias handling logic to urlify * DOP-3500: Handle originalBranchName and nullish alias case * fixup lint * null safety --------- Co-authored-by: Seung Park <[email protected]>
1 parent 7658965 commit bed8a1f

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

modules/persistence/src/services/metadata/ToC/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ export const traverseAndMerge = (
119119

120120
// Create a deep copy of a ToC, converting all slugs present to absolute urls if project, prefix and url is provided.
121121
// Copy logic should be tightly coupled to the urlification logic here - we DON'T want to mutate the base ToC objects.
122-
export const copyToCTree = (toBeCopied: ToC, prefix?: string, url?: string): ToC => {
122+
export const copyToCTree = (toBeCopied: ToC, prefix?: string, url?: string, alias?: string): ToC => {
123123
const toctree = JSON.parse(JSON.stringify(toBeCopied));
124124
if (!prefix || !url) return toctree;
125125
let queue = [toctree];
126126
while (queue?.length) {
127127
const next = queue.shift();
128128
if (next && next.slug) {
129-
next.url = convertSlugToUrl(next.slug, prefix, url);
129+
next.url = convertSlugToUrl(next.slug, prefix, url, alias);
130130
delete next.slug;
131131
}
132132
if (next?.children) queue = [...queue, ...next.children];

modules/persistence/src/services/metadata/ToC/utils/convertSlugToUrl.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
export const convertSlugToUrl = (slug, prefix, url) => {
2-
return ensureTrailingSlash(url) + prefix + ensureLeadingSlash(slug);
1+
export const convertSlugToUrl = (slug, prefix, url, alias) => {
2+
const leading = ensureTrailingSlash(url) + prefix;
3+
const trailing = alias ? ensureLeadingSlash(alias) + ensureLeadingSlash(slug) : ensureLeadingSlash(slug);
4+
return leading + trailing;
35
};
46

57
const ensureTrailingSlash = (subpath: string) => {

modules/persistence/src/services/metadata/associated_products/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ const shapeToCsCursor = async (
114114
// TODO: If we want staging builds with embedded versions, it needs to be added here
115115
if (repoBranchesEntry) {
116116
const { url, prefix } = prefixFromEnvironment(branches);
117+
const { urlSlug, urlAliases = [], gitBranchName, publishOriginalBranchName } = repoBranchesEntry;
118+
const alias = urlSlug || urlAliases[0] || (publishOriginalBranchName && gitBranchName);
117119
tocInsertions[project][branch] = {
118120
original: copyToCTree(metadata.toctree),
119-
urlified: copyToCTree(metadata.toctree, prefix, url),
121+
urlified: copyToCTree(metadata.toctree, prefix, url, alias),
120122
};
121123
// TODO: Can we urlify the order? SHOUD we urlify the order?
122124
tocOrderInsertions[project][branch] = metadata.toctreeOrder;
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { convertSlugToUrl } from '../../../src/services/metadata/ToC/utils/convertSlugToUrl';
22

33
describe('convertSlugToUrl', () => {
4-
it("accepts a project's prefix, slug, and base url, and returns an absolute url for href usage", () => {
5-
expect(convertSlugToUrl('get-started', 'docs/atlas/cli', 'www.mongodb.com')).toEqual(
6-
'www.mongodb.com/docs/atlas/cli/get-started'
4+
it("accepts a project's prefix, slug, alias and base url, and returns an absolute url for href usage", () => {
5+
expect(convertSlugToUrl('get-started', 'docs/atlas/cli', 'www.mongodb.com', 'current')).toEqual(
6+
'www.mongodb.com/docs/atlas/cli/current/get-started'
7+
);
8+
});
9+
10+
it('still returns a valid absolute url for href usage when alias is falsey', () => {
11+
expect(convertSlugToUrl('get-started', 'docs/charts', 'www.mongodb.com', '')).toEqual(
12+
'www.mongodb.com/docs/charts/get-started'
713
);
814
});
915
});

0 commit comments

Comments
 (0)