diff options
author | Sarah German <sgerman@gitlab.com> | 2023-05-11 23:18:13 +0300 |
---|---|---|
committer | Sarah German <sgerman@gitlab.com> | 2023-05-11 23:18:13 +0300 |
commit | e3d58d577ad987eafffbd1197ad23552d3031d7d (patch) | |
tree | 3e650625460f239e579721677e83c2b5d0e32a4a | |
parent | 0194b2af58d17b392b07764a7fee3e2a54b4b1f5 (diff) |
Add version prefixes in frontend files
-rw-r--r-- | content/frontend/default/components/versions_menu.vue | 2 | ||||
-rw-r--r-- | content/frontend/default/environment.js | 6 | ||||
-rw-r--r-- | content/frontend/search/components/lunr_page.vue | 18 | ||||
-rwxr-xr-x | scripts/normalize-links.sh | 5 |
4 files changed, 25 insertions, 6 deletions
diff --git a/content/frontend/default/components/versions_menu.vue b/content/frontend/default/components/versions_menu.vue index be9884f1..80516e1a 100644 --- a/content/frontend/default/components/versions_menu.vue +++ b/content/frontend/default/components/versions_menu.vue @@ -81,6 +81,6 @@ export default { <gl-dropdown-divider /> </template> - <gl-dropdown-item href="/archives">Archives</gl-dropdown-item> + <gl-dropdown-item href="https://docs.gitlab.com/archives">Archives</gl-dropdown-item> </gl-dropdown> </template> 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_page.vue b/content/frontend/search/components/lunr_page.vue index 5edcb04c..a64906ed 100644 --- a/content/frontend/search/components/lunr_page.vue +++ b/content/frontend/search/components/lunr_page.vue @@ -1,6 +1,7 @@ <script> /* global lunr */ import { GlSearchBoxByClick, GlLink } from '@gitlab/ui'; +import { isArchivesSite } from '../../default/environment'; export default { components: { @@ -61,20 +62,33 @@ 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}`; }); // Add the search term to the URL to allow linking to result pages. const url = new URL(window.location); url.searchParams.set('query', this.query); window.history.pushState(null, '', url.toString()); + + // Rewrite links to include the version prefix if this is the archives site. + if (isArchivesSite()) { + this.rewriteResultLinks(); + } }, 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> @@ -87,7 +101,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' |