Skip to content

Commit a4233a6

Browse files
committed
feat: countAllImages
1 parent df1811e commit a4233a6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/markdown.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,18 @@ export function getAllCategories(): string[] {
7979
return Array.from(categories).sort()
8080
}
8181

82-
export function countAllImages(): number {
83-
// @todo
84-
return 0;
82+
export function countAllImages(dir: string = 'public'): number {
83+
let count = 0;
84+
const entries = fs.readdirSync(dir, {withFileTypes: true});
85+
for (const entry of entries) {
86+
const fullPath = path.join(dir, entry.name);
87+
if (entry.isDirectory()) {
88+
count += countAllImages(fullPath);
89+
} else if (entry.isFile() && /\.(png|jpe?g)$/i.test(entry.name)) {
90+
count++;
91+
}
92+
}
93+
return count;
8594
}
8695

8796
export async function markdownToHtml(markdown: string): Promise<string> {

lib/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
32

43
export const toDate = (date: string) => new Date(date).toLocaleDateString('ru-RU');

0 commit comments

Comments
 (0)