blog 이전
- git blog io 사용할때 쓴 포스팅 이전 - 현재 형식에 맞게 수정
This commit is contained in:
@@ -6,12 +6,15 @@ const collectFrontmatter = (raw) => {
|
||||
if (lines[0]?.trim() === '---') {
|
||||
cursor = 1;
|
||||
for (; cursor < lines.length; cursor += 1) {
|
||||
const line = lines[cursor].trim();
|
||||
const rawLine = lines[cursor];
|
||||
const line = rawLine.trim();
|
||||
if (line === '---') {
|
||||
cursor += 1;
|
||||
break;
|
||||
}
|
||||
if (!line) continue;
|
||||
if (/^\s+/.test(rawLine)) continue;
|
||||
if (!line.includes(':')) continue;
|
||||
const [key, ...rest] = line.split(':');
|
||||
meta[key.trim()] = rest.join(':').trim();
|
||||
}
|
||||
@@ -38,10 +41,20 @@ const extractExcerpt = (body) => {
|
||||
|
||||
const normalizeTags = (value) => {
|
||||
if (!value) return [];
|
||||
return value
|
||||
const mapped = value
|
||||
.split(',')
|
||||
.map((tag) => tag.trim())
|
||||
.filter(Boolean);
|
||||
.filter(Boolean)
|
||||
.map((tag) => {
|
||||
const lower = tag.toLowerCase();
|
||||
if (lower === 'diary' || lower === 'dailylog') return '일상';
|
||||
if (lower === 'dev' || lower === 'development') return '개발';
|
||||
if (lower === 'study') return '공부';
|
||||
if (lower === 'idea' || lower === 'ideas') return '아이디어';
|
||||
return tag;
|
||||
});
|
||||
|
||||
return Array.from(new Set(mapped));
|
||||
};
|
||||
|
||||
const normalizeTitle = (slug) =>
|
||||
@@ -49,8 +62,24 @@ const normalizeTitle = (slug) =>
|
||||
.replace(/-/g, ' ')
|
||||
.replace(/\b\w/g, (letter) => letter.toUpperCase());
|
||||
|
||||
const inferTagFromPath = (path) => {
|
||||
const match = path.match(/\/blog\/([^/]+)\//);
|
||||
if (!match) return '';
|
||||
const folder = match[1];
|
||||
if (folder === 'daily') return '일상';
|
||||
if (folder === 'dev') return '개발';
|
||||
if (folder === 'study') return '공부';
|
||||
if (folder === 'ideas') return '아이디어';
|
||||
return '';
|
||||
};
|
||||
|
||||
const inferDateFromSlug = (slug) => {
|
||||
const match = slug.match(/\d{4}-\d{2}-\d{2}/);
|
||||
return match ? match[0] : '';
|
||||
};
|
||||
|
||||
export const getBlogPosts = () => {
|
||||
const modules = import.meta.glob('/src/content/blog/*.md', {
|
||||
const modules = import.meta.glob('/src/content/blog/**/*.md', {
|
||||
as: 'raw',
|
||||
eager: true,
|
||||
});
|
||||
@@ -58,15 +87,25 @@ export const getBlogPosts = () => {
|
||||
const posts = Object.entries(modules).map(([path, raw]) => {
|
||||
const slug = path.split('/').pop().replace(/\.md$/, '');
|
||||
const { meta, body } = collectFrontmatter(raw);
|
||||
const inferredTag = inferTagFromPath(path);
|
||||
const title = meta.title || extractTitle(body) || normalizeTitle(slug);
|
||||
const excerpt = meta.excerpt || extractExcerpt(body);
|
||||
const date = meta.date || '';
|
||||
const excerpt = meta.excerpt || meta.description || extractExcerpt(body);
|
||||
const date = meta.date || inferDateFromSlug(slug);
|
||||
const baseTags = normalizeTags(meta.tags);
|
||||
const categoryTags = normalizeTags(meta.category);
|
||||
const tags = Array.from(
|
||||
new Set([
|
||||
...baseTags,
|
||||
...categoryTags,
|
||||
...(inferredTag ? [inferredTag] : []),
|
||||
])
|
||||
);
|
||||
return {
|
||||
slug,
|
||||
title,
|
||||
excerpt,
|
||||
date,
|
||||
tags: normalizeTags(meta.tags),
|
||||
tags,
|
||||
body,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user