Skip to content

Commit

Permalink
feat: add redirects to new docs site
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcontracts committed Dec 13, 2023
1 parent 1409de2 commit 4257b2d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ dist
config.local.js
basement_dist
yarn.lock

src/.vuepress/redirects.js
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 13 additions & 0 deletions scripts/redirects.js
Original file line number Diff line number Diff line change
@@ -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)}`)
31 changes: 26 additions & 5 deletions src/.vuepress/enhanceApp.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
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
// refresh the page, so that users do not need to manually click
// 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);
}
)
})
}
60 changes: 60 additions & 0 deletions src/.vuepress/public/_redirects
Original file line number Diff line number Diff line change
@@ -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!

0 comments on commit 4257b2d

Please sign in to comment.