diff --git a/.gitignore b/.gitignore index 026d6fb0f..dc87bec9b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ dist config.local.js basement_dist yarn.lock - +src/.vuepress/redirects.js diff --git a/package.json b/package.json index cf66fff0d..2797dd0ff 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "description": "The Optimism Community Hub", "main": "index.js", "scripts": { - "dev": "vuepress dev src", - "build": "vuepress build src", - "preview": "yarn build && serve -s src/.vuepress/dist -p 8080" + "dev": "yarn redirects && vuepress dev src", + "build": "yarn redirects && vuepress build src", + "preview": "yarn build && serve -s src/.vuepress/dist -p 8080", + "redirects": "node scripts/redirects.js" }, "license": "MIT", "devDependencies": { diff --git a/scripts/redirects.js b/scripts/redirects.js new file mode 100644 index 000000000..026bf4735 --- /dev/null +++ b/scripts/redirects.js @@ -0,0 +1,13 @@ +const fs = require('fs') + +const redirectsFilePath = 'src/.vuepress/public/_redirects' +const outputFilePath = 'src/.vuepress/redirects.js' + +const lines = fs.readFileSync(redirectsFilePath, 'utf-8').split('\n') +const routes = {} +lines.forEach(line => { + const [source, destination] = line.split(/\s+/) + routes[source] = destination +}) + +fs.writeFileSync(outputFilePath, `export default ${JSON.stringify(routes, null, 2)}`) diff --git a/src/.vuepress/enhanceApp.js b/src/.vuepress/enhanceApp.js index d46afef51..3e3095ddf 100644 --- a/src/.vuepress/enhanceApp.js +++ b/src/.vuepress/enhanceApp.js @@ -1,12 +1,28 @@ import event from '@vuepress/plugin-pwa/lib/event' +import redirects from './redirects' export default ({ router }) => { registerAutoReload(); router.addRoutes([ - { path: '/docs/', redirect: '/' }, - { path: '/docs/governance/attestation-station/', redirect: '/docs/identity' } + { path: '/docs/', redirect: '/' } ]) + + // Custom redirect hack. + if (typeof window !== 'undefined') { + router.beforeEach((to, from, next) => { + const target = redirects[to.path] || redirects[to.path.replace(/\/$/, '')] + if (target) { + if (target.startsWith('http://') || target.startsWith('https://')) { + window.location.href = target + } else { + next(target) + } + } else { + next() + } + }) + } } // When new content is detected by the app, this will automatically @@ -14,7 +30,12 @@ export default ({ router }) => { // the refresh button. For more details see: // https://linear.app/optimism/issue/FE-1003/investigate-archive-issue-on-docs const registerAutoReload = () => { - event.$on('sw-updated', e => e.skipWaiting().then(() => { - location.reload(true); - })) + event.$on('sw-updated', e => { + e.skipWaiting().then(() => + { + if (typeof location !== 'undefined') + location.reload(true); + } + ) + }) } diff --git a/src/.vuepress/public/_redirects b/src/.vuepress/public/_redirects new file mode 100644 index 000000000..e2857e49a --- /dev/null +++ b/src/.vuepress/public/_redirects @@ -0,0 +1,60 @@ +/docs/identity/atst-v1 https://docs.optimism.io/chain/identity/contracts-eas 301! +/docs/identity/app https://docs.optimism.io/chain/identity/applications 301! +/docs/identity/atst-v0 https://docs.optimism.io/chain/identity/about-attestations 301! +/docs/identity/schemas https://docs.optimism.io/chain/identity/schemas 301! +/docs/identity/glossary https://docs.optimism.io/connect/resources/glossary#op-profile--identity 301! +/docs/identity/intro https://docs.optimism.io/chain/identity/overview 301! +/docs/identity https://docs.optimism.io/chain/identity/overview 301! +/docs/identity/build https://docs.optimism.io/chain/identity/about-attestations 301! +/docs/identity/profile https://docs.optimism.io/chain/identity/optimist-profile 301! +/docs/useful-tools/networks https://docs.optimism.io/chain/networks 301! +/docs/useful-tools/providers https://docs.optimism.io/builders/tools/rpc-providers 301! +/docs/useful-tools/faucets https://docs.optimism.io/builders/tools/faucets 301! +/docs/useful-tools/meta-tx https://docs.optimism.io/builders/tools/account-abstraction 301! +/docs/useful-tools/account-abstraction https://docs.optimism.io/builders/tools/account-abstraction 301! +/docs/useful-tools https://docs.optimism.io/builders/tools/overview 301! +/docs/useful-tools/oracles https://docs.optimism.io/builders/tools/oracles 301! +/docs/useful-tools/debugging https://docs.optimism.io/builders/tools/overview 301! +/docs/useful-tools/monitoring https://docs.optimism.io/builders/tools/monitoring/analytics-tools 301! +/docs/useful-tools/explorers https://docs.optimism.io/builders/tools/block-explorers 301! +/docs/protocol/txn-flow https://docs.optimism.io/stack/protocol/transaction-flow 301! +/docs/protocol/withdrawal-flow https://docs.optimism.io/stack/protocol/withdrawal-flow 301! +/docs/protocol https://docs.optimism.io/stack/protocol/overview 301! +/docs/protocol/2-rollup-protocol https://docs.optimism.io/stack/protocol/overview 301! +/docs/protocol/1-design-philosophy https://docs.optimism.io/stack/protocol/design-principles 301! +/docs/protocol/deposit-flow https://docs.optimism.io/stack/protocol/deposit-flow 301! +/docs/protocol/protocol-2.0 https://docs.optimism.io/stack/protocol/overview 301! +/docs/sdk/js-client https://docs.optimism.io/builders/tools/javascript/sdk 301! +/docs/sdk/alchemy-sdk https://docs.optimism.io/builders/tools/javascript/sdk 301! +/docs/sdk https://docs.optimism.io/builders/tools/javascript/sdk 301! +/docs/guides/wallet-dev https://docs.optimism.io/builders/cex-wallet-developers/wallet-support 301! +/docs/guides/cex-dev https://docs.optimism.io/builders/cex-wallet-developers/cex-support 301! +/docs/guides/testing https://docs.optimism.io/chain/testing/testing-dapps 301! +/docs/guides https://docs.optimism.io 301! +/docs/guides/nft https://docs.optimism.io 301! +/docs/guides/bridge-dev https://docs.optimism.io/builders/dapp-developers/bridging/basics 301! +/docs/security-model https://docs.optimism.io/chain/security/faq 301! +/docs/security-model/priv-roles https://docs.optimism.io/chain/security/privileged-roles 301! +/docs/security-model/bounties https://docs.optimism.io/chain/security/security-policy 301! +/docs/developers/bridge/basics https://docs.optimism.io/builders/dapp-developers/bridging/basics 301! +/docs/developers/bridge/messaging https://docs.optimism.io/builders/dapp-developers/bridging/messaging 301! +/docs/developers/bridge/comm-strategies https://docs.optimism.io/builders/dapp-developers/bridging/messaging 301! +/docs/developers/bridge/standard-bridge https://docs.optimism.io/builders/dapp-developers/bridging/standard-bridge 301! +/docs/developers/known-issues https://docs.optimism.io/chain/differences 301! +/docs/developers/bedrock/node-operator-guide https://docs.optimism.io/builders/node-operators/overview 301! +/docs/developers/bedrock/explainer https://docs.optimism.io/stack/protocol/overview 301! +/docs/developers/bedrock/metrics https://docs.optimism.io/builders/node-operators/metrics 301! +/docs/developers/bedrock/wallet-upgrade https://docs.optimism.io 301! +/docs/developers/bedrock/differences https://docs.optimism.io 301! +/docs/developers https://docs.optimism.io 301! +/docs/developers/media https://docs.optimism.io 301! +/docs/developers/build/dev-node https://docs.optimism.io/chain/testing/dev-node 301! +/docs/developers/build/json-rpc https://docs.optimism.io/builders/node-operators/json-rpc 301! +/docs/developers/build/system-contracts https://docs.optimism.io/builders/dapp-developers/contracts/system-contracts 301! +/docs/developers/build/testing-dapps https://docs.optimism.io/builders/dapp-developers/contracts/testing 301! +/docs/developers/build/transaction-fees https://docs.optimism.io/stack/transactions/transaction-fees 301! +/docs/developers/build/cheap-dapp https://docs.optimism.io/builders/dapp-developers/contracts/optimization 301! +/docs/developers/build/differences https://docs.optimism.io/chain/differences 301! +/docs/developers/nodes/intro https://docs.optimism.io/builders/node-operators/overview 301! +/docs/developers/nodes/mainnet https://docs.optimism.io/builders/node-operators/overview 301! +/docs/developers/nodes/testnet https://docs.optimism.io/builders/node-operators/overview 301!