Skip to content

Commit a7573a1

Browse files
committed
build: v1.0.0
1 parent 8132227 commit a7573a1

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed

lib/articles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const articles = [
7373
},
7474
{
7575
category: 'Проблематика',
76-
title: 'False sense of Comfort',
76+
title: 'False Sense of Comfort',
7777
content: 'Размышления о том, как индивидуальные интересы и личные границы влияют на участие в коллективных проектах.',
7878
href: '/messages/foundation/problematics/false-sense-of-comfort',
7979
},

lib/images.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import path from 'path';
2+
import fs from 'fs';
3+
import { GalleryItem } from "@/lib/interface";
4+
5+
const IMAGES_ROOT = path.join(process.cwd(), 'public', 'images');
6+
7+
export async function getImages(dir = ''): Promise<GalleryItem[]> {
8+
const absDir = path.join(IMAGES_ROOT, dir);
9+
const entries = fs.readdirSync(absDir, { withFileTypes: true });
10+
let files: GalleryItem[] = [];
11+
for (const entry of entries) {
12+
if (entry.isDirectory()) {
13+
const subFiles = await getImages(path.join(dir, entry.name));
14+
files.push({
15+
type: 'folder',
16+
name: entry.name,
17+
path: path.join(dir, entry.name),
18+
children: subFiles,
19+
});
20+
} else if (/(\.png|jpe?g|gif|webp|avif)$/i.test(entry.name)) {
21+
files.push({
22+
type: 'image',
23+
name: entry.name,
24+
path: path.join('/images', dir, entry.name).replace(/\\/g, '/'),
25+
});
26+
}
27+
}
28+
return files;
29+
}

lib/markdown.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path'
22
import { remark } from 'remark'
33
import html from 'remark-html'
4-
import { GalleryItem, MarkdownFile } from "@/lib/interface";
4+
import { MarkdownFile } from "@/lib/interface";
55
import fs from 'fs'
66
import matter from "gray-matter";
77

@@ -100,38 +100,3 @@ export async function markdownToHtml(markdown: string): Promise<string> {
100100

101101
return result.toString()
102102
}
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-
}

lib/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ export const toCategoryName = (category: string) => category === 'general' ? 'О
88
category.split('/').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join(' | ');
99

1010
export const toCategoryNumber = <T>(categoryFiles: Array<T>): string => categoryFiles.length > 4 ? `${categoryFiles.length} документов в категории` :`${categoryFiles.length} документа в категории`
11+
12+
export const formatImageName = (name: string) => {
13+
const nameWithoutExt = name.replace(/\.[^/.]+$/, "");
14+
return nameWithoutExt
15+
.replace(/[-_]+/g, ' ')
16+
.replace(/\b\w/g, c => c.toUpperCase());
17+
}

pages/images/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Head from 'next/head';
33
import Header from '@/lib/components/header';
44
import Footer from '@/lib/components/footer';
55
import { GalleryItem, GalleryProps, ImagesGalleryPageProps } from "@/lib/interface";
6-
import { formatImageName, getImages } from "@/lib/markdown";
6+
import { formatImageName } from "@/lib/utils";
77

88
function Gallery({ images, folder = '' }: GalleryProps) {
99
return (
@@ -59,6 +59,7 @@ export default function ImagesGalleryPage({ images }: ImagesGalleryPageProps) {
5959
}
6060

6161
export async function getStaticProps() {
62+
const { getImages } = await import("@/lib/images");
6263
const images = await getImages();
6364
return { props: { images } };
6465
}

0 commit comments

Comments
 (0)