Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2023-03-23 18:01:05 +0300
committerSarah German <sgerman@gitlab.com>2023-05-11 19:12:11 +0300
commit03c52945dc5646cff31da399ecd8b685e89433f2 (patch)
tree0879797539e778b8bdca647fc818b281ede93b85
parent7008e1893a8b0e7889f4f354b5c2d2f6a1563a19 (diff)
Merge branch 'sarahg-fe-asset-paths' into 'main'cherry-pick-3adfdb39
Add version prefixes in frontend files See merge request https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3683 Merged-by: Achilleas Pipinellis <axil@gitlab.com> Approved-by: Achilleas Pipinellis <axil@gitlab.com> Reviewed-by: Achilleas Pipinellis <axil@gitlab.com> Co-authored-by: Sarah German <sgerman@gitlab.com> (cherry picked from commit 3adfdb39611c8ee46508dd263dbd72e2409bc771) d427d0cf Add version prefixes in frontend files 05d3a2a1 Add version prefixes to Lunr search results
-rw-r--r--content/frontend/default/environment.js6
-rw-r--r--content/frontend/search/components/lunr_results.vue18
-rwxr-xr-xscripts/normalize-links.sh5
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'