From 2d1c1782de7fc6fc299227f03e19078676af59e9 Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Sun, 14 Jan 2024 23:52:46 +0000 Subject: [PATCH] changelogManager: refactor --- src/modules/changelog/changelogManager.js | 36 ++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/modules/changelog/changelogManager.js b/src/modules/changelog/changelogManager.js index b267b321..b8763fb5 100644 --- a/src/modules/changelog/changelogManager.js +++ b/src/modules/changelog/changelogManager.js @@ -5,33 +5,35 @@ let changelog = loadJSON('./src/modules/changelog/changelog.json') export default function(string) { try { + const currentChangelog = changelog.current; + switch (string) { case "version": - return `v.${changelog["current"]["version"]}${ - changelog["current"]["date"] ? `· ${changelog["current"]["date"]}` : '' + return `v.${currentChangelog.version}${ + currentChangelog.date ? `· ${currentChangelog.date}` : '' }` case "title": - return replaceBase(changelog["current"]["title"]); + return replaceBase(currentChangelog.title); case "banner": - return changelog["current"]["banner"] ? { - url: `updateBanners/${changelog["current"]["banner"]["file"]}`, - width: changelog["current"]["banner"]["width"], - height: changelog["current"]["banner"]["height"] + const currentBanner = changelog.current.banner; + return currentBanner ? { + ...currentBanner, + url: `updateBanners/${currentBanner.file}` } : false; case "content": - return replaceBase(changelog["current"]["content"]); + return replaceBase(currentChangelog.content); case "history": - return changelog["history"].map((i) => { + return changelog.history.map((log) => { + const banner = log.banner; return { - title: replaceBase(i["title"]), - version: `v.${i["version"]}${ - i["date"] ? `· ${i["date"]}` : '' + title: replaceBase(log.title), + version: `v.${log.version}${ + log.date ? `· ${log.date}` : '' }`, - content: replaceBase(i["content"]), - banner: i["banner"] ? { - url: `updateBanners/${i["banner"]["file"]}`, - width: i["banner"]["width"], - height: i["banner"]["height"] + content: replaceBase(log.content), + banner: banner ? { + ...banner, + url: `updateBanners/${banner.file}` } : false, } });