From 4d61fa7edd3627440ee6d2c855b78813c08ec711 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Tue, 3 Jan 2023 15:12:02 +0100 Subject: [PATCH] Docs(feat): add generated rust SDK doc (replacing the link) --- website/docusaurus.config.js | 50 ++++++++++++++++++++++++++++++++++++ website/sidebars.js | 6 +---- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index e7678fe0eb..61685d2eb1 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -1,3 +1,27 @@ +// all SDK repos and what they map to for the sidebar. +// +// Each key should return an object that contains *at least* the +// `sidebarSdkName` property. This is the name that is placed before "SDK" in +// the sidebar. An object can also optionally define a `slugName`. This will be +// used to construct the slug. If no "slugName" is defined, the `sidebarSdkName` +// should be used to create the slug. +const readmeRepos = { + 'unleash-client-rust': { + sidebarSdkName: 'Rust', + }, + // as an example of when you'd use both + // 'unleash-android-proxy-sdk': { + // sidebarSdkName: 'Android', + // slugName: 'android-proxy', + // }, +}; + +function getReadmeRepoData(filename) { + const repoName = filename.split('/')[0]; + + return readmeRepos[repoName] ?? { sdkName: repoName }; +} + /** @type {import('@docusaurus/types').DocusaurusConfig} */ module.exports = { title: 'Unleash', @@ -557,6 +581,32 @@ module.exports = { }, }, ], + [ + 'docusaurus-plugin-remote-content', + { + // more info at https://github.com/rdilweb/docusaurus-plugin-remote-content#options + name: 'content-sdks', + sourceBaseUrl: 'https://raw.githubusercontent.com/Unleash/', // gets prepended to all of the documents when fetching + outDir: 'docs/reference/sdks', // the base directory to output to. + documents: Object.keys(readmeRepos).map( + (repo) => `${repo}/main/README.md`, + ), // the file names to download + modifyContent: (filename, content) => { + const data = getReadmeRepoData(filename); + return { + filename: `${( + data.slugName ?? data.sidebarSdkName + ).toLowerCase()}.md`, + content: `--- +title: ${data.sidebarSdkName} SDK +--- + +${content} +`, + }; + }, + }, + ], ], themes: ['docusaurus-theme-openapi-docs'], // Allows use of @theme/ApiItem and other components }; diff --git a/website/sidebars.js b/website/sidebars.js index 21f7bb5286..88a71695cd 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -237,11 +237,7 @@ module.exports = { 'reference/sdks/php', 'reference/sdks/python', 'reference/sdks/ruby', - { - type: 'link', - href: 'https://github.com/unleash/unleash-client-rust', - label: 'Rust SDK', - }, + 'reference/sdks/rust', 'reference/sdks/dotnet', ], },