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/get-documents.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/helper/get-documents.ts (limited to 'src/helper/get-documents.ts') diff --git a/src/helper/get-documents.ts b/src/helper/get-documents.ts new file mode 100644 index 0000000..ca9ce93 --- /dev/null +++ b/src/helper/get-documents.ts @@ -0,0 +1,35 @@ + + + +/*** EXPORT ------------------------------------------- ***/ + +export default async(directory: string) => { + const posts: string[] = []; + + try { + const files: Deno.DirEntry[] = []; + + for await (const dirEntry of Deno.readDir(directory)) { + if (dirEntry.isFile) + files.push(dirEntry); + } + + /*** Deno is weird in that if you do NOT call `.reverse()` + it will NOT load everything in the directory…WTF?! ***/ + + files.sort((a, b) => a.name.localeCompare(b.name)).reverse(); + + for (const file of files) { + if (file.name.startsWith(".")) + return; + + if (file.name.endsWith(".txt")) + posts.push(file.name); + } + } catch(error) { + console.error(`Error reading directory for posts: ${String(error)}`); + } finally { + // deno-lint-ignore no-unsafe-finally + return posts; + } +} -- cgit v1.2.3