diff options
author | Sarah German <sgerman@gitlab.com> | 2023-03-23 18:01:03 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2023-03-23 18:01:03 +0300 |
commit | 8b535ce008bf8f40ae5ed715779e183ffd374349 (patch) | |
tree | 498ae023b31759d2b259a80a526abfc4d60a4e7f | |
parent | f08e69d57ee3cc43b44e8caa1d11849a6f560903 (diff) |
Add version prefixes in frontend files
-rw-r--r-- | content/frontend/default/environment.js | 6 | ||||
-rw-r--r-- | content/frontend/search/components/lunr_results.vue | 18 | ||||
-rwxr-xr-x | scripts/normalize-links.sh | 5 |
3 files changed, 24 insertions, 5 deletions
diff --git a/content/frontend/default/environment.js b/content/frontend/default/environment.js index e09a83c4..e403cdfc 100644 --- a/content/frontend/default/environment.js +++ b/content/frontend/default/environment.js @@ -22,13 +22,13 @@ export const GlHosts = [ ]; export function isGitLabHosted() { - return GlHosts.some((e) => window.location.host.includes(e.host)); + return GlHosts.some((e) => window.location.hostname.includes(e.host)); } export function isArchivesSite() { - return window.location.host === GlHosts.find((x) => x.environment === 'archives').host; + return window.location.hostname === GlHosts.find((x) => x.environment === 'archives').host; } export function isProduction() { - return window.location.host === GlHosts.find((x) => x.environment === 'production').host; + return window.location.hostname === GlHosts.find((x) => x.environment === 'production').host; } diff --git a/content/frontend/search/components/lunr_results.vue b/content/frontend/search/components/lunr_results.vue index 0cef1b3d..e7559b5d 100644 --- a/content/frontend/search/components/lunr_results.vue +++ b/content/frontend/search/components/lunr_results.vue @@ -2,6 +2,7 @@ /* global lunr */ import { GlSearchBoxByClick, GlLink } from '@gitlab/ui'; import { getSearchQueryFromURL, updateURLParams } from '../search_helpers'; +import { isArchivesSite } from '../../default/environment'; export default { components: { @@ -62,17 +63,30 @@ export default { // Limit the results by relevancy score. this.results = this.results.filter((key) => key.score > this.relevancy_threshold); - // Add page titles to the result set. + // Add page titles and link paths to the result set. Object.keys(this.results).forEach((key) => { const contentItem = this.contentMap.find(({ id }) => id === this.results[key].ref); this.results[key].title = contentItem.h1; + this.results[key].link = `/${this.results[key].ref}`; }); + // Rewrite links to include the version prefix if this is the archives site. + if (isArchivesSite()) { + this.rewriteResultLinks(); + } + updateURLParams(this.query); }, handleError() { this.error = true; }, + rewriteResultLinks() { + const pathPrefix = document.querySelector('meta[name="gitlab-docs-version"]').content; + this.results = this.results.map((obj) => ({ + ...obj, + link: `https://archives.docs.gitlab.com/${pathPrefix}/${obj.ref}`, + })); + }, }, }; </script> @@ -85,7 +99,7 @@ export default { <ul v-if="results.length"> <li v-for="result in results" :key="result.ref"> - <gl-link :href="`/${result.ref}`">{{ result.title }}</gl-link> + <gl-link :href="result.link">{{ result.title }}</gl-link> </li> </ul> diff --git a/scripts/normalize-links.sh b/scripts/normalize-links.sh index fd534f83..e67e3167 100755 --- a/scripts/normalize-links.sh +++ b/scripts/normalize-links.sh @@ -50,10 +50,15 @@ find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/ope echo "Replace relative URLs in $TARGET/$VER for /assets/" find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/assets/#="/'"$VER"'/assets/#g' +find "${TARGET}/$VER" -type f -name '*.css' -print0 | xargs -0 sed -i 's#/assets/#/'"$VER"'/assets/#g' +find "${TARGET}/$VER" -type f -name '*.js' -print0 | xargs -0 sed -i 's#/assets/#/'"$VER"'/assets/#g' echo "Replace relative URLs in $TARGET/$VER for /frontend/" find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/frontend/#="/'"$VER"'/frontend/#g' +echo "Replace relative URLs in $TARGET/$VER for /search/" +find "${TARGET}/$VER" -type f -name '*.js' -print0 | xargs -0 sed -i 's#/search/#/'"$VER"'/search/#g' + echo "Replace relative URLs in $TARGET/$VER for /" find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 sed -i 's#<a href="/">#<a href="/'"$VER"'/">#g' |