diff --git a/src/components/Layout/LayoutHeader.vue b/src/components/Layout/LayoutHeader.vue index 9fdb59a..3329f7a 100644 --- a/src/components/Layout/LayoutHeader.vue +++ b/src/components/Layout/LayoutHeader.vue @@ -57,17 +57,16 @@ diff --git a/src/plugins/markdown/relativeToRouter.js b/src/plugins/markdown/relativeToRouter.js index cbd1a93..1b262f1 100644 --- a/src/plugins/markdown/relativeToRouter.js +++ b/src/plugins/markdown/relativeToRouter.js @@ -1,3 +1,5 @@ +import { getBaseUrl } from "../../utils/url" + export function relativeToRouterPlugin(md, configuration) { const isStaticAsset = (url) => { const regex = /\.\w+$/ @@ -5,11 +7,8 @@ export function relativeToRouterPlugin(md, configuration) { return regex.test(url) } - const makeUrlToStaticAsset = (url) => { - const baseUrl = configuration.base_url || '' - - return (baseUrl + url).replaceAll('//', '/') - } + const makeUrlToStaticAsset = (url) => + (getBaseUrl(configuration) + url).replaceAll('//', '/') const scan = (state) => { state.tokens.forEach((tokens) => { diff --git a/src/plugins/schemaOrg/nodes/Taxon.js b/src/plugins/schemaOrg/nodes/Taxon.js index 0ce7f41..718d832 100644 --- a/src/plugins/schemaOrg/nodes/Taxon.js +++ b/src/plugins/schemaOrg/nodes/Taxon.js @@ -1,3 +1,5 @@ +import { getBaseUrl } from "@/utils/url" + function removeEmptyProperties(obj) { const copyObj = { ...obj } @@ -13,8 +15,8 @@ function removeEmptyProperties(obj) { } function makeUrlPath(host, path) { - const { hash_mode, base_url = '' } = __APP_ENV__ - const fullPath = (base_url + (hash_mode ? '/#' + path : path)).replaceAll( + const { hash_mode } = __APP_ENV__ + const fullPath = (getBaseUrl() + (hash_mode ? '/#' + path : path)).replaceAll( '//', '/' ) diff --git a/src/router/index.js b/src/router/index.js index 9e2d8d8..eb30e8d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -6,6 +6,7 @@ import { } from 'vue-router' import dynamicRoutes from '~pages' +import { getBaseUrl } from "@/utils/url" const coreModuleRoutes = import.meta.glob('@/modules/**/router/*.js', { import: 'default', @@ -16,7 +17,8 @@ const userModuleRoutes = import.meta.glob('#/modules/**/router/*.js', { eager: true }) -const { base_url, hash_mode } = __APP_ENV__ +const { hash_mode } = __APP_ENV__ +const base_url = getBaseUrl() const moduleRoutes = [].concat( ...Object.values(coreModuleRoutes), diff --git a/src/utils/index.js b/src/utils/index.js index 5087657..da4ddad 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,3 +1,4 @@ export * from './color' export * from './request' export * from './strings' +export * from './url' diff --git a/src/utils/url.js b/src/utils/url.js index ce665d3..c17afb4 100644 --- a/src/utils/url.js +++ b/src/utils/url.js @@ -6,3 +6,13 @@ export function isValidUrl(string) { return false } } + +// Allow base_url to be different on Github Pages than when deployed elsewhere, for example to Cascade. +// GithubPages requires the base_url to be the repository name, while Cascade needs the page to +// fit into its own directory structure. +export const getBaseUrl = (configuration = __APP_ENV__) => { + const baseUrl = configuration?.base_url || '' + const githubPagesBaseUrl = configuration?.github_pages_base_url || '' + const isGithubPages = window.location.origin.indexOf('.github.io/') > 0 + return isGithubPages ? githubPagesBaseUrl : baseUrl +} \ No newline at end of file