diff --git a/website/package.json b/website/package.json index 735d34df64..50a1094ff4 100644 --- a/website/package.json +++ b/website/package.json @@ -16,7 +16,8 @@ "clear": "docusaurus clear", "serve": "docusaurus serve", "write-translations": "docusaurus write-translations", - "write-heading-ids": "docusaurus write-heading-ids" + "write-heading-ids": "docusaurus write-heading-ids", + "test": "NODE_ENV=test node --trace-warnings ../node_modules/.bin/jest remote-content" }, "dependencies": { "@docusaurus/core": "2.3.1", diff --git a/website/remote-content/edge-proxy.js b/website/remote-content/edge-proxy.js index 78e50c6991..df21dbce8c 100644 --- a/website/remote-content/edge-proxy.js +++ b/website/remote-content/edge-proxy.js @@ -14,6 +14,16 @@ const DOCS = mapObject(enrich)({ 'unleash-edge': { sidebarName: 'Unleash Edge', slugName: 'unleash-edge', + subPages: { + 'docs/concepts.md': { + sidebarName: 'Concepts', + slugName: 'concepts', + }, + 'docs/deploying.md': { + sidebarName: 'Deploying', + slugName: 'deploying', + }, + }, }, }); diff --git a/website/remote-content/sdks.test.js b/website/remote-content/sdks.test.js new file mode 100644 index 0000000000..8140cfc823 --- /dev/null +++ b/website/remote-content/sdks.test.js @@ -0,0 +1,36 @@ +const { docs } = require('./edge-proxy'); + +test('Should get all sub pages', () => { + expect(docs.urls).toStrictEqual([ + 'unleash-proxy/main/README.md', + 'unleash-edge/main/README.md', + 'unleash-edge/main/docs/concepts.md', + 'unleash-edge/main/docs/deploying.md', + ]); +}); + +test('Modifies filenames and content properly', () => { + const proxyContent = docs.modifyContent(docs.urls[0], ''); + const edgeMainContent = docs.modifyContent(docs.urls[1], ''); + const firstSubpage = docs.modifyContent(docs.urls[2], ''); + const secondSubpage = docs.modifyContent(docs.urls[3], ''); + + expect(proxyContent.filename).toBe('unleash-proxy.md'); + expect(edgeMainContent.filename).toBe('unleash-edge.md'); + expect(firstSubpage.filename).toBe('unleash-edge/concepts.md'); + expect(secondSubpage.filename).toBe('unleash-edge/deploying.md'); + + expect(edgeMainContent.content).toContain('title: Unleash Edge'); + expect(edgeMainContent.content).toContain('slug: /reference/unleash-edge'); + expect(edgeMainContent.content).toContain( + 'custom_edit_url: https://github.com/Unleash/unleash-edge/edit/main/README.md', + ); + + expect(firstSubpage.content).toContain('title: Concepts'); + expect(firstSubpage.content).toContain( + 'slug: /reference/unleash-edge/concepts', + ); + expect(firstSubpage.content).toContain( + 'custom_edit_url: https://github.com/Unleash/unleash-edge/edit/main/docs/concepts.md', + ); +}); diff --git a/website/remote-content/shared.js b/website/remote-content/shared.js index 8fde63880c..184ceb9ff0 100644 --- a/website/remote-content/shared.js +++ b/website/remote-content/shared.js @@ -89,6 +89,8 @@ module.exports.modifyContent = }) => (filename, content) => { const data = getRepoDataFn(filename); + const subpageKey = filename.replace(`${data.name}/${data.branch}/`, ''); + const subpage = data.subPages?.[subpageKey]; const generationTime = new Date(); @@ -96,6 +98,7 @@ module.exports.modifyContent = const constructed = `${path.join( filePath(data) ?? '', data.slugName, + subpage?.slugName ?? '', )}.md`; // ensure the file path does *not* start with a leading / @@ -105,7 +108,11 @@ module.exports.modifyContent = })(); const processedSlug = (() => { - const constructed = path.join(urlPath ?? '', data.slugName); + const constructed = path.join( + urlPath ?? '', + data.slugName, + subpage?.slugName ?? '', + ); // ensure the slug *does* start with a leading / const prefix = constructed.charAt(0) === '/' ? '' : '/'; @@ -119,15 +126,13 @@ module.exports.modifyContent = return { filename: processedFilename, content: `--- -title: ${data.sidebarName} +title: ${subpage?.sidebarName ?? data.sidebarName} slug: ${processedSlug} -custom_edit_url: ${data.repoUrl}/edit/${data.branch}/README.md +custom_edit_url: ${data.repoUrl}/edit/${data.branch}/${subpage ? subpageKey : 'README.md'} --- :::info Generated content -This document was generated from the README in the [${ - data.sidebarName - } GitHub repository](${data.repoUrl}). +This document was generated from ${subpage ? subpageKey : 'README.md'} in the [${data.sidebarName} GitHub repository](${data.repoUrl}). ::: ${additionalAdmonitions} @@ -148,6 +153,9 @@ This content was generated on