Skip to content

Commit

Permalink
Add redirects to route visitors from the ScalarDB Community docs site…
Browse files Browse the repository at this point in the history
… to the ScalarDB docs site (#149)

* Create index.tsx

* Customize error page message with redirect

Customize the error page message with a redirect that points to the ScalarDB docs site.

* Add redirects

Not sure if the redirects will work until the changes have been merged since redirects in Docusaurus only work in production environments.

* Change paragraph break syntax

* Add announcement banner about redirect

* Add announcement banner about redirect

* Refactor redirect

* Redirect to same page on ScalarDB docs site; remove timer

* Remove individual redirects

More user-friendly method for redirects exists in `static/redirect.js`.
  • Loading branch information
josh-wong authored Sep 24, 2024
1 parent 76a0729 commit bded19a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 22 deletions.
34 changes: 12 additions & 22 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ const config = {
}),
],
],
scripts: [
'/redirect.js', // Path to your custom JavaScript file
],

plugins: [
[
Expand All @@ -150,22 +153,9 @@ const config = {
redirects: [
// This redirect takes the user to the latest version of the English docs when they land on the English versions of the docs site.
{
to: '/docs/latest/',
to: 'https://scalardb.scalar-labs.com/docs/latest/',
from: ['/', '/docs'],
},
{
to: '/docs/latest/run-non-transactional-storage-operations-through-primitive-crud-interface',
from: '/docs/latest/storage-abstraction',
},
// Uncomment this line when the docs for 3.14 are released.
// {
// to: '/docs/3.13/run-non-transactional-storage-operations-through-primitive-crud-interface',
// from: '/docs/3.13/storage-abstraction',
// },
{
to: '/docs/3.12/run-non-transactional-storage-operations-through-primitive-crud-interface',
from: '/docs/3.12/storage-abstraction',
},
],
},
],
Expand Down Expand Up @@ -359,14 +349,14 @@ const config = {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
},
// announcementBar: {
// id: 'new_version',
// content:
// '<b>ScalarDB X.X is now available!🥳 For details on what\'s included in this new version, see the <a target="_self" rel="noopener noreferrer" href="/docs/latest/releases/release-notes">release notes</a>.<b>',
// backgroundColor: '#2673BB',
// textColor: '#FFFFFF',
// isCloseable: false,
// },
announcementBar: {
id: 'new_version',
content:
'<b>Important: The ScalarDB Community docs site has been merged with the <a target="_self" rel="noopener noreferrer" href="https://scalardb.scalar-labs.com/docs/latest/">ScalarDB docs site</a>.</b>',
backgroundColor: '#e00000',
textColor: '#ffffff',
isCloseable: false,
},
zoom: {
selector: '.markdown :not(em) > img',
background: {
Expand Down
46 changes: 46 additions & 0 deletions static/redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
document.addEventListener('DOMContentLoaded', function() {
const baseUrl = 'https://scalardb.scalar-labs.com'; // Base URL for redirection
// Redirect happens immediately. Otherwise, we can use the following to specify seconds.
// const redirectTime = 10000; // 10,000 milliseconds = 10 seconds

// Create and style the overlay element.
const overlay = document.createElement('div');
overlay.style.position = 'fixed';
overlay.style.top = '0';
overlay.style.left = '0';
overlay.style.width = '100%';
overlay.style.height = '100%';
overlay.style.backgroundColor = 'rgba(211, 211, 211, 0.8)'; // Light gray with opacity
overlay.style.zIndex = '1000';
overlay.style.display = 'flex';
overlay.style.justifyContent = 'center';
overlay.style.alignItems = 'center';

// Create and style the popup element.
const popup = document.createElement('div');
popup.style.backgroundColor = '#fff';
popup.style.color = '#000';
popup.style.padding = '20px';
popup.style.borderRadius = '8px';
popup.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
popup.style.position = 'relative';
popup.style.zIndex = '1001';
popup.style.textAlign = 'center';

// Add message to the popup.
popup.innerHTML = 'The ScalarDB Community docs site has been merged with the <a href="https://scalardb.scalar-labs.com/docs/latest/">ScalarDB docs site</a>.';

// Append popup to overlay.
overlay.appendChild(popup);

// Append overlay to body.
document.body.appendChild(overlay);

// Get current path.
const currentPath = window.location.pathname;

// Set timeout for redirect
setTimeout(function() {
window.location.href = `${baseUrl}${currentPath}`;
},); // Redirect happens immediately. Otherwise, we can specify `redirectTime);` at the end of this line.
});

0 comments on commit bded19a

Please sign in to comment.