Skip to content

Commit

Permalink
docs - add manual redirects scripts (#2178)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukegalbraithrussell authored Jul 31, 2024
1 parent 9b444ae commit f636d75
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 116 deletions.
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ docs/
│ ├── pages/ (stuff that isn't docs content. This is empty for every repo but homepage)
│ └── theme (only contains the 404 page)
├── docusaurus.config.js (main config file. also where to set navbar/footer)
└── redirects.js (a redirects script because the old site used # as pages which docusaurus can't handle)
├── redirects-hashes.js (a # to / redirects script because the old site used # as pages)
└── redirects-pages.js (a redirects script for regular pages -- redirects plugin doesn't work with above script)
└── sidebar.js (manually set where the content docs are in the sidebar.)
```

Expand Down
14 changes: 2 additions & 12 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,12 @@ const config = {
],

clientModules: [
require.resolve('./redirects.js'),
require.resolve('./redirects-hashes.js'),
require.resolve('./redirects-pages.js'),
],

plugins:
['docusaurus-theme-github-codeblock',

['@docusaurus/plugin-client-redirects',
{
redirects: [
{
to: '/getting-started',
from: ['/tutorial/getting-started','/', '/concepts/basic', '/concepts/advanced'],
},
],
},
],
],

themeConfig:
Expand Down
106 changes: 106 additions & 0 deletions docs/redirects-hashes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";

if (ExecutionEnvironment.canUseDOM) {
(function () {
// List of specific URLs to handle
const urlsToHandle = [
"/bolt-js/concepts#basic",
"/bolt-js/concepts#advanced",
"/bolt-js/concepts#message-listening",
"/bolt-js/concepts#message-sending",
"/bolt-js/concepts#event-listening",
"/bolt-js/concepts#web-api",
"/bolt-js/concepts#action-listening",
"/bolt-js/concepts#action-respond",
"/bolt-js/concepts#acknowledge",
"/bolt-js/concepts#shortcuts",
"/bolt-js/concepts#commands",
"/bolt-js/concepts#creating-modals",
"/bolt-js/concepts#updating-pushing-views",
"/bolt-js/concepts#view-submissions",
"/bolt-js/concepts#publishing-views",
"/bolt-js/concepts#options",
"/bolt-js/concepts#authenticating-oauth",
"/bolt-js/concepts#socket-mode",
"/bolt-js/concepts#error-handling",
"/bolt-js/concepts#authorization",
"/bolt-js/concepts#token-rotation",
"/bolt-js/concepts#conversation-store",
"/bolt-js/concepts#global-middleware",
"/bolt-js/concepts#listener-middleware",
"/bolt-js/concepts#context",
"/bolt-js/concepts#deferring-initialization",
"/bolt-js/concepts#logging",
"/bolt-js/concepts#custom-routes",
"/bolt-js/concepts#receiver",
"/bolt-js/concepts#creating-custom-functions",
"/bolt-js/concepts#defining-custom-functions",
"/bolt-js/concepts#listening-to-custom-functions",
"/bolt-js/concepts#responding-to-interactivity",
"/bolt-js/concepts#steps",
"/bolt-js/concepts#creating-steps",
"/bolt-js/concepts#adding-editing-steps",
"/bolt-js/concepts#saving-steps",
"/bolt-js/concepts#executing-steps",
"/bolt-js/ja-jp/concepts#message-listening",
"/bolt-js/ja-jp/concepts#message-sending",
"/bolt-js/ja-jp/concepts#event-listening",
"/bolt-js/ja-jp/concepts#web-api",
"/bolt-js/ja-jp/concepts#action-listening",
"/bolt-js/ja-jp/concepts#action-respond",
"/bolt-js/ja-jp/concepts#acknowledge",
"/bolt-js/ja-jp/concepts#shortcuts",
"/bolt-js/ja-jp/concepts#commands",
"/bolt-js/ja-jp/concepts#creating-modals",
"/bolt-js/ja-jp/concepts#updating-pushing-views",
"/bolt-js/ja-jp/concepts#view-submissions",
"/bolt-js/ja-jp/concepts#publishing-views",
"/bolt-js/ja-jp/concepts#options",
"/bolt-js/ja-jp/concepts#authenticating-oauth",
"/bolt-js/ja-jp/concepts#socket-mode",
"/bolt-js/ja-jp/concepts#error-handling",
"/bolt-js/ja-jp/concepts#authorization",
"/bolt-js/ja-jp/concepts#token-rotation",
"/bolt-js/ja-jp/concepts#conversation-store",
"/bolt-js/ja-jp/concepts#global-middleware",
"/bolt-js/ja-jp/concepts#listener-middleware",
"/bolt-js/ja-jp/concepts#context",
"/bolt-js/ja-jp/concepts#deferring-initialization",
"/bolt-js/ja-jp/concepts#logging",
"/bolt-js/ja-jp/concepts#custom-routes",
"/bolt-js/ja-jp/concepts#receiver",
"/bolt-js/ja-jp/concepts#creating-custom-functions",
"/bolt-js/ja-jp/concepts#defining-custom-functions",
"/bolt-js/ja-jp/concepts#listening-to-custom-functions",
"/bolt-js/ja-jp/concepts#responding-to-interactivity",
"/bolt-js/ja-jp/concepts#steps",
"/bolt-js/ja-jp/concepts#creating-steps",
"/bolt-js/ja-jp/concepts#adding-editing-steps",
"/bolt-js/ja-jp/concepts#saving-steps",
"/bolt-js/ja-jp/concepts#executing-steps",
];

// Get the current path and hash
const currentPath = window.location.pathname;
const currentHash = window.location.hash;

// If there is a hash fragment
if (currentHash && currentHash.includes("#")) {
// Create the full URL with hash replaced by '/'
const newPath = currentPath + currentHash.replace("#", "/");

// Loop through the list of URLs to handle
for (const url of urlsToHandle) {
// Check if the current path matches the URL to handle
if (
currentPath === url.split("#")[0] &&
window.location.hash === `#${url.split("#")[1]}`
) {
// Redirect to the new path
window.location.replace(newPath);
return; // Exit after the first match
}
}
}
})();
}
26 changes: 26 additions & 0 deletions docs/redirects-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";

if (ExecutionEnvironment.canUseDOM) {
(function () {
// List of specific paths to redirect
const redirects = {
"/bolt-js/": "/bolt-js/getting-started",
"/bolt-js/concepts/basic": "/bolt-js/getting-started",
"/bolt-js/concepts/advanced": "/bolt-js/getting-started",
"/bolt-js/tutorial/getting-started": "/bolt-js/getting-started",
"/bolt-js/ja-jp/": "/bolt-js/ja-jp/getting-started",
"/bolt-js/ja-jp/concepts/basic": "/bolt-js/ja-jp/getting-started",
"/bolt-js/ja-jp/concepts/advanced": "/bolt-js/ja-jp/getting-started",
"/bolt-js/ja-jp/tutorial/getting-started": "/bolt-js/ja-jp/getting-started",
};

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

// Check if the current path matches any in the redirects list
if (redirects[currentPath]) {
// Redirect to the new path
window.location.replace(redirects[currentPath]);
}
})();
}
103 changes: 0 additions & 103 deletions docs/redirects.js

This file was deleted.

0 comments on commit f636d75

Please sign in to comment.