2024-04-22 23:50:20 -04:00
|
|
|
export default function migrate(settings) {
|
|
|
|
const oldSetting = settings.get("custom_header_links");
|
|
|
|
|
2024-04-26 00:57:46 -04:00
|
|
|
// Do nothing if setting is already an array which means user has saved the setting in the new format
|
|
|
|
// This is required because there was a bug in core where this migration would fail but the theme was still updated
|
|
|
|
// allowing the users to save the setting in the new format.
|
|
|
|
if (Array.isArray(oldSetting)) {
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2024-08-26 02:39:05 -04:00
|
|
|
if (typeof oldSetting === "string") {
|
2024-04-26 00:57:46 -04:00
|
|
|
const newLinks = [];
|
|
|
|
|
|
|
|
oldSetting.split("|").forEach((link) => {
|
|
|
|
const [text, title, url, view, target, hideOnScroll, locale] = link
|
2024-04-22 23:50:20 -04:00
|
|
|
.split(",")
|
|
|
|
.map((s) => s.trim());
|
|
|
|
|
2024-04-26 03:46:20 -04:00
|
|
|
if (text && url) {
|
2024-04-26 00:57:46 -04:00
|
|
|
const newLink = {
|
|
|
|
text,
|
|
|
|
url,
|
|
|
|
};
|
|
|
|
|
2024-04-26 03:46:20 -04:00
|
|
|
if (title) {
|
|
|
|
newLink.title = title;
|
|
|
|
}
|
|
|
|
|
2024-04-26 00:57:46 -04:00
|
|
|
if (["vdm", "vdo", "vmo"].includes(view)) {
|
|
|
|
newLink.view = view;
|
|
|
|
} else {
|
|
|
|
newLink.view = "vdm";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (["blank", "self"].includes(target)) {
|
|
|
|
newLink.target = target;
|
|
|
|
} else {
|
|
|
|
newLink.target = "blank";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (["remove", "keep"].includes(hideOnScroll)) {
|
|
|
|
newLink.hide_on_scroll = hideOnScroll;
|
|
|
|
} else {
|
|
|
|
newLink.hide_on_scroll = "keep";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (locale) {
|
|
|
|
newLink.locale = locale;
|
2024-04-22 23:50:20 -04:00
|
|
|
}
|
|
|
|
|
2024-04-26 00:57:46 -04:00
|
|
|
newLinks.push(newLink);
|
|
|
|
}
|
2024-04-22 23:50:20 -04:00
|
|
|
});
|
|
|
|
|
2024-04-26 00:57:46 -04:00
|
|
|
settings.set("custom_header_links", newLinks);
|
2024-04-22 23:50:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|