Skip to content

Commit

Permalink
fix subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
jemikanegara committed Oct 31, 2024
1 parent 892b197 commit 47a0c09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions extractOptionsFromScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ function extractOptionsFromScript(window, optsArgs = {
const alternateLinkTag = window.document.createElement('link');
alternateLinkTag.setAttribute('rel', 'alternate');
alternateLinkTag.setAttribute('hreflang', originalLang);
// append prefix to the original lang because the subdomain will be accessed without the prefix
alternateLinkTag.href = `${window.location.protocol}//${domain}${getPrefixedPathname(window, domainSourcePrefix, window.location.pathname)}`;

const subdirectoryHref = `${window.location.protocol}//${domain}${getUnprefixedPathname(window, domainSourcePrefix, window.location.pathname)}`
// append prefix to the original lang because the subdomain will be accessed without the prefix (dont append if subdirectory mode)
alternateLinkTag.href = translationMode == "subdirectory" ? subdirectoryHref : `${window.location.protocol}//${domain}${getPrefixedPathname(window, domainSourcePrefix, window.location.pathname)}`;
window.document.head.appendChild(alternateLinkTag);

// Add alternate link tags for allowed languages
Expand Down
9 changes: 9 additions & 0 deletions utils/selector/createLanguageSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ async function createLanguageSelect(window, optsArgs = {}) {
}
}

if (prefix && options.translationMode == "subdirectory") {
newUrl.pathname = getUnprefixedPathname(window, prefix, newUrl.pathname);
// if (options.originalLanguage == language.lang) {
// newUrl.pathname = getUnprefixedPathname(window, prefix, newUrl.pathname);
// } else {
// newUrl.pathname = getUnprefixedPathname(window, prefix, newUrl.pathname);
// }
}

const url = isSelected ? "#" : addOrReplaceLangParam(window, newUrl.href, language.lang);

a.href = url;
Expand Down

0 comments on commit 47a0c09

Please sign in to comment.