import { createServerFn } from '@tanstack/react-start';
import { readFile } from 'node:fs/promises';
import { join } from 'path';
import matter from 'gray-matter';
import { MarkdownMetadata } from '@/model/blog/markdown-metadata';
export const getAboutMarkdownServerFn = createServerFn({
method: 'GET',
}).handler(async ({ data }) => {
try {
const md = await readFile(`src/data/md/about.md`, 'utf-8');
const { data: mdData, content } = matter(md);
return {
...(mdData as MarkdownMetadata),
content: content.trimStart(),
};
} catch (err: any) {
if (err.code === 'ENOENT') {
// File not found
console.warn(`Markdown file not found for About page`);
return null; // Or throw a custom error, or return an empty object fallback
}
// Unexpected error
throw err;
}
});`
import { createServerFn } from '@tanstack/react-start';
import { readFile } from 'node:fs/promises';
import { join } from 'path';
import matter from 'gray-matter';
import { MarkdownMetadata } from '@/model/blog/markdown-metadata';
export const getAboutMarkdownServerFn = createServerFn({
method: 'GET',
}).handler(async ({ data }) => {
try {
const md = await readFile(`src/data/md/about.md`, 'utf-8');
const { data: mdData, content } = matter(md);
return {
...(mdData as MarkdownMetadata),
content: content.trimStart(),
};
} catch (err: any) {
if (err.code === 'ENOENT') {
// File not found
console.warn(`Markdown file not found for About page`);
return null; // Or throw a custom error, or return an empty object fallback
}
// Unexpected error
throw err;
}
});`