From 8c34d810af95fae0ef846f54370a8c88bfab7123 Mon Sep 17 00:00:00 2001 From: "netop://ウィビ" Date: Sat, 11 Apr 2026 14:24:49 -0700 Subject: initial commit --- src/helper/populate-recents.ts | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/helper/populate-recents.ts (limited to 'src/helper/populate-recents.ts') diff --git a/src/helper/populate-recents.ts b/src/helper/populate-recents.ts new file mode 100644 index 0000000..551434b --- /dev/null +++ b/src/helper/populate-recents.ts @@ -0,0 +1,47 @@ + + + +/*** UTILITY ------------------------------------------ ***/ + +import { remarkRegex } from "src/utility/constant.ts"; + +/*** EXPORT ------------------------------------------- ***/ + +export default (documentList: Array<{ filename: string; }>, currentDocument: string): string => { + const currentIndex = documentList.findIndex(item => item.filename === currentDocument); + let isMemo = true; + let maximumIndex = documentList.length; + let minimumIndex = 0; + + if (remarkRegex.test(currentDocument)) + isMemo = false; + + if (currentIndex < 7) + minimumIndex = 0; + else + minimumIndex = currentIndex - 7; + + if (currentIndex < (maximumIndex - 8)) + maximumIndex = currentIndex + 8; + + const documents = documentList.slice(minimumIndex, maximumIndex).map((arrayItem: { filename: string; }) => { + if (!arrayItem) + return ""; + + const { filename } = arrayItem; + + if (filename === currentDocument) { + if (isMemo) + return `${filename.replace(".txt", "")}`; + else + return `${filename.replace(".txt", "")}`; + } else { + if (isMemo) + return `${filename.replace(".txt", "")}`; + else + return `${filename.replace(".txt", "")}`; + } + }); + + return documents.join(""); +} -- cgit v1.2.3