diff --git a/docs/README.md b/docs/README.md index 225a37582..060580c8e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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.) ``` diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 5d455400f..ea1f7c6a9 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -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: diff --git a/docs/redirects-hashes.js b/docs/redirects-hashes.js new file mode 100644 index 000000000..c5e5f4091 --- /dev/null +++ b/docs/redirects-hashes.js @@ -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 + } + } + } + })(); +} diff --git a/docs/redirects-pages.js b/docs/redirects-pages.js new file mode 100644 index 000000000..16b0cf443 --- /dev/null +++ b/docs/redirects-pages.js @@ -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]); + } + })(); +} diff --git a/docs/redirects.js b/docs/redirects.js deleted file mode 100644 index ef193a515..000000000 --- a/docs/redirects.js +++ /dev/null @@ -1,103 +0,0 @@ -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 - } - } - } -})(); -}