Home link to versioned URL #10724
-
Current StateWe are currently migrating our documentation from Sphinx to Docusaurus. We've deployed our test site, e.g. https://docs-site-test.com, on S3 served via CloudFront as described here (CloudFront Function and all). Our current documentation is served at https://docs-site.com/latest/ (with versioning served at https://docs-site.com/<version-number>/) and uses S3 and CloudFront as hosting. Linking to https://docs-site.com redirects to https://docs-site.com/latest/. This isn't done via CloudFront but is by default with Sphinx. When deploying our Docusaurus test site, everything works as if on localhost but if I enter the base url https://docs-site-test.com I get a blank page with the navbar and footer only. This also happens when running locally, i.e. if I point my browser to http://localhost:3000 I have the same blank page. If I directly point to http://localhost:3000/latest/ I get the docs as desired. We are using Docs Only mode and have a Wanted OutcomeWe would like to have the site serve http://localhost:3000/latest/ when calling http://localhost:3000. We tried changing the
QuestionWhat's the correct configuration to do this (assuming this is possible)? Below are snippets of our ...
import { globalVariables, versions } from './constants'
...
const config: Config = {
url: 'https://docs.kasten.io',
baseUrl: '/',
...
presets: [
[
'classic',
{
docs: {
sidebarPath: './sidebars.ts',
routeBasePath: '/',
versions: versions,
lastVersion: '1.0.1',
includeCurrentVersion: false
},
...
} satisfies Preset.Options,
],
],
markdown: {
preprocessor: ({filePath, fileContent}) => {
var key = '';
var found = false;
for (key in globalVariables) {
let folderName = (key == 'current' ? 'current' : `version-${key}`);
if (filePath.includes(`/${folderName}/`)) {
found = true;
break;
}
}
if (key == '' || !found) {
key = 'current';
}
let content = fileContent;
for (const variable in globalVariables[key]) {
content = content.replaceAll('@'+variable+'@', globalVariables[key][variable]);
}
return content
},
},
themeConfig: {
...
navbar: {
title: 'Our Docs',
logo: {
alt: 'Our Docs',
href: '/latest/',
},
items: [
...
{
type: 'docsVersionDropdown',
position: 'right',
dropdownActiveClassDisabled: true,
},
...
},
footer: {
links: [
{
title: 'Docs',
items: [
{
label: 'Docs',
to: '/latest/',
},
],
},
...
},
...
} satisfies Preset.ThemeConfig,
}; with the following files: export const globalVariables = {
'1.0.1': {
'version': '1.0.1',
'displayVersion': '1.0.1',
...
},
'1.0.0': {
'version': '1.0.0',
'displayVersion': '1.0.0',
}
}
export const versions = {
'1.0.1': {
label: '1.0.1',
path: 'latest'
},
'1.0.0': {
label: '1.0.0',
},
} and [
"1.0.1",
"1.0.0"
] |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It's impossible to help you without a runnable repro. If your site contains sensitive data, you can still remove that data and create a similar setup. Also if you choose to use CloudFront (which is not the ideal host for static sites) it's your responsibility to make it work. I'm not a CloudFront expert and can't troubleshoot it for you. Assume that the community blog posts you read may be wrong. That being said, if you only have the docs plugin enabled, with Docusaurus responsibility is only to build a static site. If your site's setup makes it so that there is no What happens when you access Docusaurus has no "server runtime". It can only emit files at build time. It can't "redirect" a request. At best it could emit a TLDR: to help you more than that, we need a runnable minimal repro We'll only troubleshoot using |
Beta Was this translation helpful? Give feedback.
-
Hi @slorber, thanks for the reply. If I could, I would have shared the repo, but unfortunately the documentation is in a private repo. At times you have to work with what you are given, like deploying on S3 and CloudFront (which has been used to serve static sites for a fair few years now, even more so with the introduction of CloudFront Functions/Lamda@Edge). The community blog post linked is correct (the vast community Docusaurus has was one of the reasons we chose to use it). Though your explanation did trigger me to look into what was being built (as I was creating a dummy minimal repo as suggested), and obviously there was no This though didn't do exactly what I wanted. I managed to achieve what I wanted by adding the following tag in the <head>
<meta http-equiv="Refresh" content="0; url='/latest/'" />
</head> Wanted to comment should anyone find this useful. I've closed the Discussion as I've solved my problem. |
Beta Was this translation helpful? Give feedback.
Hi @slorber, thanks for the reply. If I could, I would have shared the repo, but unfortunately the documentation is in a private repo. At times you have to work with what you are given, like deploying on S3 and CloudFront (which has been used to serve static sites for a fair few years now, even more so with the introduction of CloudFront Functions/Lamda@Edge). The community blog post linked is correct (the vast community Docusaurus has was one of the reasons we chose to use it).
Though your explanation did trigger me to look into what was being built (as I was creating a dummy minimal repo as suggested), and obviously there was no
/index.html
file in the build director as I had removed it…