deniz bektaş

This commit is contained in:
2026-04-03 16:20:51 +03:00
parent d0cd1c7ee3
commit fb6933edd0
53 changed files with 4742 additions and 98 deletions

30
lib/activity.ts Normal file
View File

@@ -0,0 +1,30 @@
import fs from 'fs';
import path from 'path';
export interface ActivityEntry {
id: string;
timestamp: string;
type: 'post' | 'notebook' | 'infosec' | 'project' | 'link' | 'update' | 'system';
message: string;
link?: string;
}
const activityFile = path.join(process.cwd(), 'content', 'activity.json');
export function getActivity(): ActivityEntry[] {
if (!fs.existsSync(activityFile)) return [];
const raw = fs.readFileSync(activityFile, 'utf-8');
return JSON.parse(raw);
}
export function addActivity(entry: Omit<ActivityEntry, 'id' | 'timestamp'>) {
const entries = getActivity();
const newEntry: ActivityEntry = {
id: Date.now().toString(),
timestamp: new Date().toISOString(),
...entry,
};
entries.unshift(newEntry);
fs.writeFileSync(activityFile, JSON.stringify(entries.slice(0, 500), null, 2));
return newEntry;
}

71
lib/posts.ts Normal file
View File

@@ -0,0 +1,71 @@
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import { remark } from 'remark';
import html from 'remark-html';
const contentDir = path.join(process.cwd(), 'content');
export interface Post {
slug: string;
title: string;
date: string;
excerpt: string;
tags: string[];
content?: string;
category: 'blog' | 'notebook' | 'infosec';
}
export function getPosts(category: 'blog' | 'notebook' | 'infosec'): Post[] {
const dir = path.join(contentDir, category);
if (!fs.existsSync(dir)) return [];
const files = fs.readdirSync(dir).filter((f) => f.endsWith('.md'));
return files
.map((filename) => {
const slug = filename.replace('.md', '');
const raw = fs.readFileSync(path.join(dir, filename), 'utf-8');
const { data } = matter(raw);
return {
slug,
title: data.title || slug,
date: data.date || '2024-01-01',
excerpt: data.excerpt || '',
tags: data.tags || [],
category,
};
})
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
}
export async function getPost(
category: 'blog' | 'notebook' | 'infosec',
slug: string
): Promise<Post | null> {
const filePath = path.join(contentDir, category, `${slug}.md`);
if (!fs.existsSync(filePath)) return null;
const raw = fs.readFileSync(filePath, 'utf-8');
const { data, content } = matter(raw);
const processed = await remark().use(html).process(content);
return {
slug,
title: data.title || slug,
date: data.date || '2024-01-01',
excerpt: data.excerpt || '',
tags: data.tags || [],
content: processed.toString(),
category,
};
}
export function getAllPosts(): Post[] {
return [
...getPosts('blog'),
...getPosts('infosec'),
...getPosts('notebook'),
].sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
}