Skip to content

Commit

Permalink
chore: Made redirecting .html links work. Tentatively
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobinstein committed Sep 9, 2024
1 parent 6804014 commit 62fd792
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dev": "vuepress dev src",
"build": "vuepress build src",
"build-gh": "cross-env BASE_URL=/docs/ vuepress build src",
"deploy": "permaweb-deploy --deploy-folder ./src/.vuepress/dist --ant-process $DEPLOY_ANT_PROCESS_ID"
"deploy": "permaweb-deploy --deploy-folder ./src/.vuepress/dist --ant-process $DEPLOY_ANT_PROCESS_ID",
"fire-test": "yarn build && firebase deploy"
},
"license": "MIT",
"devDependencies": {
Expand Down
67 changes: 36 additions & 31 deletions docs/src/.vuepress/enhanceApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* https://v1.vuepress.vuejs.org/guide/basic-config.html#app-level-enhancements
*/
import Vue from 'vue';
import store from './store';
import Vue from "vue";
import store from "./store";

export default ({
Vue, // the version of Vue being used in the VuePress app
Expand All @@ -19,41 +19,46 @@ export default ({
},
});

router.beforeEach((to, from, next) => {
// List of redirects (old path to new path)
const redirects = {
'/arcss': '/wayfinder', // Add more as needed
'/gateways/ar-io-node/arnsoip/observer.html': '/gateways/ar-io-node/arnsoip/observer'
};
if (typeof window !== "undefined") {
console.log("latest enhanced loaded");
router.beforeEach((to, from, next) => {
// List of redirects (old path to new path)
const redirects = {
"/arcss": "/wayfinder", // Add more as needed
"/gateways/ar-io-node/arnsoip/observer.html":
"/gateways/ar-io-node/arnsoip/observer",
};

// Normalize the path by removing any trailing slash for easier matching
const normalizedPath = to.path.replace(/\/$/, '');
// Normalize the path by removing any trailing slash for easier matching
const normalizedPath = to.path.replace(/\/$/, "");

let redirectPath = redirects[normalizedPath];
let redirectPath = redirects[normalizedPath];

// Only check for the staging environment in the browser
if (typeof window !== 'undefined') {
const isStaging = window.location.hostname === 'ar-io.github.io';
// Only check for the staging environment in the browser
if (typeof window !== "undefined") {
const isStaging = window.location.hostname === "ar-io.github.io";

// Adjust the redirect paths based on the base URL for staging
if (redirectPath && isStaging) {
redirectPath = `/docs${redirectPath}`;
// Adjust the redirect paths based on the base URL for staging
if (redirectPath && isStaging) {
redirectPath = `/docs${redirectPath}`;
}

// Specific handling for `.html` pages to force a reload
if (normalizedPath.endsWith(".html") && redirectPath) {
window.location.href = redirectPath + (to.hash || "");
window.location.reload()
// return; // Ensure further navigation is prevented after reload
}
}

// Specific handling for `.html` pages to force a reload
if (normalizedPath.endsWith('.html') && redirectPath) {
window.location.href = redirectPath + (to.hash || '');
return; // Ensure further navigation is prevented after reload
if (redirectPath) {
// For regular non-`.html` redirects
window.location.replace(redirectPath + (to.hash || ""));
} else {
next(); // Proceed to the requested page if no redirect is found
}
}

if (redirectPath) {
// For regular non-`.html` redirects
window.location.replace(redirectPath + (to.hash || ''));
} else {
next(); // Proceed to the requested page if no redirect is found
}
});
});
}

// ...apply other enhancements for the site.
}
};
2 changes: 1 addition & 1 deletion docs/src/.vuepress/theme/configs/default_sidebar_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = [
},
{
title: "Observation and Incentive Protocol",
path: "/gateways/ar-io-node/arnsoip/observer",
path: "/gateways/ar-io-node/arnsoip/observer.md",
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion docs/src/gateways/ar-io-node/arnsoip/observer.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
permalink: "/gateways/ar-io-node/arnsoip/observer"
permalink: "/gateways/ar-io-node/arnsoip/observer/"
next: false
---

Expand Down
7 changes: 7 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": [
{
"source": "/gateways/ar-io-node/arnsoip/observer.html",
"destination": "/gateways/ar-io-node/arnsoip/observer",
"type": 301
}
]
}
}

0 comments on commit 62fd792

Please sign in to comment.