emoji
This commit is contained in:
@@ -13,12 +13,15 @@ import { getPostsDirectory } from '@/lib/postsDirectory';
|
||||
const postsDirectory = getPostsDirectory();
|
||||
|
||||
const pinnedPath = path.join(postsDirectory, 'pinned.json');
|
||||
let pinnedSlugs: string[] = [];
|
||||
let pinnedData: { pinned: string[]; folderEmojis: Record<string, string> } = { pinned: [], folderEmojis: {} };
|
||||
if (fs.existsSync(pinnedPath)) {
|
||||
try {
|
||||
pinnedSlugs = JSON.parse(fs.readFileSync(pinnedPath, 'utf8'));
|
||||
const raw = fs.readFileSync(pinnedPath, 'utf8');
|
||||
pinnedData = JSON.parse(raw);
|
||||
if (!pinnedData.pinned) pinnedData.pinned = [];
|
||||
if (!pinnedData.folderEmojis) pinnedData.folderEmojis = {};
|
||||
} catch {
|
||||
pinnedSlugs = [];
|
||||
pinnedData = { pinned: [], folderEmojis: {} };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +105,7 @@ async function getPostByPath(filePath: string, relPath: string) {
|
||||
summary: data.summary,
|
||||
content: processedContent,
|
||||
createdAt: createdAt.toISOString(),
|
||||
pinned: pinnedSlugs.includes(relPath.replace(/\.md$/, '')),
|
||||
pinned: pinnedData.pinned.includes(relPath.replace(/\.md$/, '')),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,7 +120,8 @@ async function readPostsDir(dir: string, relDir = ''): Promise<any[]> {
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
const children = await readPostsDir(fullPath, relPath);
|
||||
folders.push({ type: 'folder', name: entry.name, path: relPath, children });
|
||||
const emoji = pinnedData.folderEmojis[relPath] || '📁';
|
||||
folders.push({ type: 'folder', name: entry.name, path: relPath, emoji, children });
|
||||
} else if (entry.isFile() && entry.name.endsWith('.md')) {
|
||||
posts.push(await getPostByPath(fullPath, relPath));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user