Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link to latest #1087

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ module.exports = {
],
customFields: {},
plugins: [
[
'./src/plugins/plugin-latest-api-doc',
{
latestBaseUrl: '/cloud-sdk/api/latest',
versions: '../static/api/versions.json'
}
],
[
'@docusaurus/plugin-content-docs',
{
Expand Down
13 changes: 13 additions & 0 deletions src/components/LatestApiDoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { useLocation } from '@docusaurus/router';
import BrowserOnly from '@docusaurus/BrowserOnly';

export default function LatestApiDoc({ latestBaseUrl, versions }) {
const explicitLatestBaseUrl = [
...latestBaseUrl.split('/').slice(0, -1),
versions[0]
].join('/');
const loc = useLocation();
const newPath = loc.pathname.replace(latestBaseUrl, explicitLatestBaseUrl);
return <BrowserOnly>{() => (window.location.href = newPath)}</BrowserOnly>;
}
8 changes: 0 additions & 8 deletions src/pages/api/index.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/pages/api/latest.mdx

This file was deleted.

29 changes: 29 additions & 0 deletions src/plugins/plugin-latest-api-doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @prop latestBaseUrl - Base URL for the latest version. Must not have a trailing slash.
* @prop versions - Reference to the `versions.json` file relative to the `.docusaurus` directory.
*/
async function apiDocPlugin(context, { latestBaseUrl, versions }) {
return {
name: 'sap-cloud-sdk-api-doc-plugin',

async contentLoaded({ content, actions }) {
const { createData, addRoute } = actions;
const baseUrlJson = await createData(
'latestBaseUrl.json',
`"${latestBaseUrl}"`
);

addRoute({
path: `${latestBaseUrl}*`,
component: '@site/src/components/LatestApiDoc.js',
modules: {
latestBaseUrl: baseUrlJson,
versions
},
exact: false
});
}
};
}

module.exports = apiDocPlugin;