From a422d57ca80cebcec75baae62cde5de191ebe63a Mon Sep 17 00:00:00 2001 From: Kelvin Tan Date: Mon, 23 Dec 2024 10:38:11 +0800 Subject: [PATCH] DEV: add migration of deprecated icon names to svg_icons site setting, also rename setting to lowercase of svg_icons --- ...0002-migrate-from-deprecated-icon-names.js | 30 ++++++++++++------- settings.yml | 2 +- ...migrate-from-deprecated-icon-names-test.js | 2 ++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/migrations/settings/0002-migrate-from-deprecated-icon-names.js b/migrations/settings/0002-migrate-from-deprecated-icon-names.js index 73138c3..b25a4db 100644 --- a/migrations/settings/0002-migrate-from-deprecated-icon-names.js +++ b/migrations/settings/0002-migrate-from-deprecated-icon-names.js @@ -1,18 +1,28 @@ export default function migrate(settings) { - const oldSetting = settings.get("header_links"); + const oldHeaderLinksSetting = settings.get("header_links"); - if (!oldSetting) { - return settings; + if (oldHeaderLinksSetting) { + const newHeaderLinksSetting = oldHeaderLinksSetting.map((link) => { + if (link.icon) { + link.icon = convertIconName(link.icon); + } + return link; + }); + + settings.set("header_links", newHeaderLinksSetting); } - const newSetting = oldSetting.map((link) => { - if (link.icon) { - link.icon = convertIconName(link.icon); - } - return link; - }); + const oldSvgIconsSetting = settings.get("Svg_icons"); + if (oldSvgIconsSetting) { + const newSvgIconsSetting = oldSvgIconsSetting + .split("|") + .map(convertIconName) + .join("|"); + + settings.set("svg_icons", newSvgIconsSetting); + settings.delete("Svg_icons"); + } - settings.set("header_links", newSetting); return settings; } diff --git a/settings.yml b/settings.yml index 27392e0..8f7c778 100644 --- a/settings.yml +++ b/settings.yml @@ -1,7 +1,7 @@ add_whitespace: type: bool default: false -Svg_icons: +svg_icons: type: "list" list_type: "compact" default: "fab-facebook|fab-twitter" diff --git a/test/unit/migrations/settings/0002-migrate-from-deprecated-icon-names-test.js b/test/unit/migrations/settings/0002-migrate-from-deprecated-icon-names-test.js index 8314a29..327cae9 100644 --- a/test/unit/migrations/settings/0002-migrate-from-deprecated-icon-names-test.js +++ b/test/unit/migrations/settings/0002-migrate-from-deprecated-icon-names-test.js @@ -37,6 +37,7 @@ module( target: "blank", }, ], + Svg_icons: "fab-facebook|fab-twitter|fab fa-cog|user-friends", }) ); @@ -74,6 +75,7 @@ module( target: "blank", }, ], + svg_icons: "fab-facebook|fab-twitter|fab-gear|user-group", }) );