diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2023-05-12 11:21:25 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2023-05-12 11:21:25 +0300 |
commit | 5c8218d0466d4de465207cce5978408b79d3e624 (patch) | |
tree | e2db594054628da399257ced7fa659a20749f430 | |
parent | c12e5ccb9e1c0e16f8ad8564c6404d690782cf7d (diff) | |
parent | 8b2d7b463dc4eb31d71d41a4d52e5c9704904e34 (diff) |
Merge branch '1633-asset-pathfix-backport-158' into '15.8'
Backport version path fixes to 15.8
See merge request https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3834
Merged-by: Achilleas Pipinellis <axil@gitlab.com>
Approved-by: Achilleas Pipinellis <axil@gitlab.com>
Co-authored-by: Sarah German <sgerman@gitlab.com>
-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 | ||||
-rw-r--r-- | content/frontend/services/fetch_versions.js | 2 | ||||
-rwxr-xr-x | scripts/normalize-links.sh | 5 |
5 files changed, 26 insertions, 7 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/content/frontend/services/fetch_versions.js b/content/frontend/services/fetch_versions.js index 6edf3e45..74ae9696 100644 --- a/content/frontend/services/fetch_versions.js +++ b/content/frontend/services/fetch_versions.js @@ -3,7 +3,7 @@ import { compareVersions } from 'compare-versions'; const BASE_URL = `${window.location.protocol}//${window.location.host}`; -const DOCS_VERSIONS_ENDPOINT = `${BASE_URL}/versions.json`; +const DOCS_VERSIONS_ENDPOINT = 'https://docs.gitlab.com/versions.json'; const GITLAB_RELEASE_DATES_ENDPOINT = `${BASE_URL}/release_dates.json`; const DOCS_IMAGES_ENDPOINT = 'https://gitlab.com/api/v4/projects/1794617/registry/repositories/631635/tags?per_page=100'; 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' |