Skip to content

Commit

Permalink
fix subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
jemikanegara committed Jan 17, 2025
1 parent f8e84d2 commit 6f80543
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (isBrowser()) {
function initTranslation() {
// replace links with lang (for SEO purposes)
if (translationMode != 'subdomain' && translationMode != 'subdirectory' && shouldReplaceLinks && paramsLang && (paramsLang != originalLanguage)) {
replaceLinks(window, {langParam, lang: paramsLang, translationMode: options.translationMode});
replaceLinks(window, {langParam, lang: paramsLang, translationMode: options.translationMode, sourceOrigin: options.sourceOrigin});
}
getTranslations(window, apiKey, options)
}
Expand Down
4 changes: 2 additions & 2 deletions replaceLinks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const getUnprefixedPathname = require("./utils/translation-mode/getUnprefixedPathname");

function replaceLinks(window, {langParam, lang, translationMode, prefix, sourceOriginHostname}) {
function replaceLinks(window, {langParam, lang, translationMode, prefix, sourceOriginHostname, sourceOrigin}) {
// Select all anchor tags
const anchors = window.document.querySelectorAll('a:not(.globalseo-ignore-link)');

Expand All @@ -26,7 +26,7 @@ function replaceLinks(window, {langParam, lang, translationMode, prefix, sourceO

// assign full url if it's relative path
if (!anchor.href.startsWith("http") && !anchor.href.startsWith("tel:") && !anchor.href.startsWith("mailto:")) {
const currentUrl = new URL(window.location.href);
const currentUrl = new URL(sourceOrigin || window.location.href);
const fullHref = `${currentUrl.protocol}//${currentUrl.hostname}${anchor.href}`;
anchor.href = fullHref;
}
Expand Down

0 comments on commit 6f80543

Please sign in to comment.