-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Migrate
link_sections
and links
to new objects setting type
This commit migrates the `link_sections` and `links` setting to a `sections` objects typed settting. Since discourse/discourse@a440e15, we have started to support objects typed theme setting so we are switching this theme component to use it instead as it provides a much better UX for configuring the settings required for the theme component.
- Loading branch information
Showing
7 changed files
with
558 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
export default function migrate(settings) { | ||
const oldLinkSections = settings.get("link_sections"); | ||
|
||
if (oldLinkSections) { | ||
const newLinkSections = oldLinkSections.split("|").map((linkSection) => { | ||
const [linkSectionName, linkSectionTitle] = linkSection | ||
.split(",") | ||
.map((value) => value.trim()); | ||
|
||
return { | ||
text: linkSectionName, | ||
title: linkSectionTitle, | ||
}; | ||
}); | ||
|
||
const oldLinkSectionLinks = settings.get("links"); | ||
|
||
if (oldLinkSectionLinks) { | ||
oldLinkSectionLinks.split("|").map((linkSectionLink) => { | ||
const [ | ||
linkSectionName, | ||
linkName, | ||
linkUrl, | ||
linkTarget, | ||
linkTitle, | ||
linkReferralPolicy, | ||
] = linkSectionLink.split(",").map((value) => value.trim()); | ||
|
||
const linkSection = newLinkSections.find( | ||
(section) => section.text === linkSectionName | ||
); | ||
|
||
if (linkSection) { | ||
if (!linkSection.links) { | ||
linkSection.links = []; | ||
} | ||
|
||
let target; | ||
|
||
switch (linkTarget) { | ||
case "blank": | ||
target = "_blank"; | ||
break; | ||
case "self": | ||
target = "_self"; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
const link = { | ||
text: linkName, | ||
url: linkUrl, | ||
title: linkTitle, | ||
}; | ||
|
||
if (target) { | ||
link.target = target; | ||
} | ||
|
||
if ( | ||
[ | ||
"no-referrer", | ||
"no-referrer-when-downgrade", | ||
"origin", | ||
"origin-when-cross-origin", | ||
"unsafe-url", | ||
].includes(linkReferralPolicy) | ||
) { | ||
link.referrer_policy = linkReferralPolicy; | ||
} | ||
|
||
linkSection.links.push(link); | ||
} | ||
}); | ||
} | ||
|
||
settings.set("sections", newLinkSections); | ||
} | ||
|
||
return settings; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.