summaryrefslogtreecommitdiff
path: root/src/helper/populate-recents.ts
diff options
context:
space:
mode:
authornetop://ウィビ <paul@webb.page>2026-04-11 14:24:49 -0700
committernetop://ウィビ <paul@webb.page>2026-04-11 14:24:49 -0700
commit8c34d810af95fae0ef846f54370a8c88bfab7123 (patch)
tree436beaf30f7b2b3f15741dd54a37e313964d1f7d /src/helper/populate-recents.ts
initial commitHEADprimary
Diffstat (limited to 'src/helper/populate-recents.ts')
-rw-r--r--src/helper/populate-recents.ts47
1 files changed, 47 insertions, 0 deletions
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 `<a class="current" href="/${filename.replace(".txt", "")}">${filename.replace(".txt", "")}</a>`;
+ else
+ return `<a class="current" href="/remarks/${filename.replace(".txt", "")}">${filename.replace(".txt", "")}</a>`;
+ } else {
+ if (isMemo)
+ return `<a href="/${filename.replace(".txt", "")}">${filename.replace(".txt", "")}</a>`;
+ else
+ return `<a href="/remarks/${filename.replace(".txt", "")}">${filename.replace(".txt", "")}</a>`;
+ }
+ });
+
+ return documents.join("");
+}