Add a locale filter to links (#30)
* Add a locale attribute to custom header links This attribute is to be set to a language code like 'fr', 'en' or 'de'. * Filter out links which locale is different from the html document's * prettier * more syntax --------- Co-authored-by: Lena Montenot <lena.montenot@commown.coop> Co-authored-by: Jordan Vidrine <jordan@jordanvidrine.com>
This commit is contained in:
parent
be4c69f8bb
commit
0661c627cb
|
@ -24,8 +24,15 @@ export default {
|
||||||
.split("|")
|
.split("|")
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((customHeaderLinksArray) => {
|
.map((customHeaderLinksArray) => {
|
||||||
const [linkText, linkTitle, linkHref, device, target, keepOnScroll] =
|
const [
|
||||||
customHeaderLinksArray
|
linkText,
|
||||||
|
linkTitle,
|
||||||
|
linkHref,
|
||||||
|
device,
|
||||||
|
target,
|
||||||
|
keepOnScroll,
|
||||||
|
locale,
|
||||||
|
] = customHeaderLinksArray
|
||||||
.split(",")
|
.split(",")
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((x) => x.trim());
|
.map((x) => x.trim());
|
||||||
|
@ -37,6 +44,8 @@ export default {
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/\s/gi, "-")}-custom-header-links`;
|
.replace(/\s/gi, "-")}-custom-header-links`;
|
||||||
|
|
||||||
|
const localeClass = locale === "" ? "" : `.${locale}`;
|
||||||
|
|
||||||
const anchorAttributes = {
|
const anchorAttributes = {
|
||||||
title: linkTitle,
|
title: linkTitle,
|
||||||
href: linkHref,
|
href: linkHref,
|
||||||
|
@ -45,9 +54,17 @@ export default {
|
||||||
anchorAttributes.target = linkTarget;
|
anchorAttributes.target = linkTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
locale !== "" &&
|
||||||
|
document.documentElement.lang &&
|
||||||
|
document.documentElement.lang !== locale
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
headerLinks.push(
|
headerLinks.push(
|
||||||
h(
|
h(
|
||||||
`li.headerLink${deviceClass}${keepOnScrollClass}${linkClass}`,
|
`li.headerLink${deviceClass}${keepOnScrollClass}${localeClass}${linkClass}`,
|
||||||
h("a", anchorAttributes, linkText)
|
h("a", anchorAttributes, linkText)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
Custom_header_links:
|
Custom_header_links:
|
||||||
type: list
|
type: list
|
||||||
list_type: simple
|
list_type: simple
|
||||||
default: "External link, this link will open in a new tab, https://meta.discourse.org, vdo, blank, remove|Most Liked, Posts with the most amount of likes, /latest/?order=op_likes, vdo, self, keep|Privacy, Our Privacy Policy, /privacy, vdm, self, keep"
|
default: "External link, this link will open in a new tab, https://meta.discourse.org, vdo, blank, remove, en|Most Liked, Posts with the most amount of likes, /latest/?order=op_likes, vdo, self, keep, en|Privacy, Our Privacy Policy, /privacy, vdm, self, keep, en"
|
||||||
description:
|
description:
|
||||||
en: "Comma delimited in this order: link text, link title, URL, view, target, hide on scroll<br><b>Link text:</b> The text for the link<br><b>Link title:</b> the text that shows when the link is hovered<br><b>URL:</b> The path for the link (can be relative)<br><b>View:</b> vdm = desktop and mobile, vdo = desktop only, vmo = mobile only<br><b>Target:</b> blank = opens in a new tab, self = opens in the same tab<br><b>Hide on scroll:</b> remove = hides the link when the title is expanded on topic pages keep = keeps the link visible even when the title is visible on topic pages"
|
en: "Comma delimited in this order: link text, link title, URL, view, target, hide on scroll<br><b>Link text:</b> The text for the link<br><b>Link title:</b> the text that shows when the link is hovered<br><b>URL:</b> The path for the link (can be relative)<br><b>View:</b> vdm = desktop and mobile, vdo = desktop only, vmo = mobile only<br><b>Target:</b> blank = opens in a new tab, self = opens in the same tab<br><b>Hide on scroll:</b> remove = hides the link when the title is expanded on topic pages keep = keeps the link visible even when the title is visible on topic pages<br><b>Language:</b> blank = no locale assoaciated to the link, else insert a locale code (en, fr, de, ...)"
|
||||||
|
|
||||||
links_position:
|
links_position:
|
||||||
default: right
|
default: right
|
||||||
|
|
Loading…
Reference in New Issue