|
1 | 1 | import path from 'path' |
2 | 2 | import { remark } from 'remark' |
3 | 3 | import html from 'remark-html' |
4 | | -import { GalleryItem, MarkdownFile } from "@/lib/interface"; |
| 4 | +import { MarkdownFile } from "@/lib/interface"; |
5 | 5 | import fs from 'fs' |
6 | 6 | import matter from "gray-matter"; |
7 | 7 |
|
@@ -100,38 +100,3 @@ export async function markdownToHtml(markdown: string): Promise<string> { |
100 | 100 |
|
101 | 101 | return result.toString() |
102 | 102 | } |
103 | | - |
104 | | -const IMAGES_ROOT = path.join(process.cwd(), 'public', 'images'); |
105 | | - |
106 | | -export async function getImages(dir = ''): Promise<GalleryItem[]> { |
107 | | - const absDir = path.join(IMAGES_ROOT, dir); |
108 | | - const entries = await fs.readdirSync(absDir, { withFileTypes: true }); |
109 | | - let files: GalleryItem[] = []; |
110 | | - for (const entry of entries) { |
111 | | - if (entry.isDirectory()) { |
112 | | - const subFiles = await getImages(path.join(dir, entry.name)); |
113 | | - files.push({ |
114 | | - type: 'folder', |
115 | | - name: entry.name, |
116 | | - path: path.join(dir, entry.name), |
117 | | - children: subFiles, |
118 | | - }); |
119 | | - } else if (/\.(png|jpe?g|gif|webp|avif)$/i.test(entry.name)) { |
120 | | - files.push({ |
121 | | - type: 'image', |
122 | | - name: entry.name, |
123 | | - path: path.join('/images', dir, entry.name).replace(/\\/g, '/'), |
124 | | - }); |
125 | | - } |
126 | | - } |
127 | | - return files; |
128 | | -} |
129 | | - |
130 | | -export function formatImageName(name: string) { |
131 | | - // Убираем расширение |
132 | | - const nameWithoutExt = name.replace(/\.[^/.]+$/, ""); |
133 | | - // Преобразуем kebab-case/underscore в слова с заглавной буквы |
134 | | - return nameWithoutExt |
135 | | - .replace(/[-_]+/g, ' ') |
136 | | - .replace(/\b\w/g, c => c.toUpperCase()); |
137 | | -} |
0 commit comments