Refactor navigation links to use Next.js routing and improve post handling
- Updated AboutButton to navigate to the about page using Next.js router. - Changed HeaderButtons and MobileNav to link directly to the about page. - Modified Home component to exclude the 'about' post from the posts list. - Added a helper function to strip YAML frontmatter from post summaries. - Enhanced API routes to handle reading and writing markdown files for posts.
This commit is contained in:
@@ -148,11 +148,21 @@ export default function Home() {
|
||||
})),
|
||||
];
|
||||
|
||||
// Helper to strip YAML frontmatter
|
||||
function stripFrontmatter(md: string): string {
|
||||
if (!md) return '';
|
||||
if (md.startsWith('---')) {
|
||||
const end = md.indexOf('---', 3);
|
||||
if (end !== -1) return md.slice(end + 3).replace(/^\s+/, '');
|
||||
}
|
||||
return md;
|
||||
}
|
||||
|
||||
// Helper to recursively collect all posts from the tree
|
||||
function collectPosts(nodes: Node[]): Post[] {
|
||||
let posts: Post[] = [];
|
||||
for (const node of nodes) {
|
||||
if (node.type === 'post') {
|
||||
if (node.type === 'post' && node.slug !== 'about') {
|
||||
posts.push(node);
|
||||
} else if (node.type === 'folder') {
|
||||
posts = posts.concat(collectPosts(node.children));
|
||||
@@ -258,7 +268,7 @@ export default function Home() {
|
||||
)}
|
||||
<div>Erstellt: {format(new Date(post.createdAt), 'd. MMMM yyyy HH:mm')}</div>
|
||||
</div>
|
||||
<p className="text-gray-700 mb-3 sm:mb-4 text-sm sm:text-base">{post.summary}</p>
|
||||
<p className="text-gray-700 mb-3 sm:mb-4 text-sm sm:text-base">{stripFrontmatter(post.summary)}</p>
|
||||
<div className="flex flex-wrap gap-1 sm:gap-2">
|
||||
{post.tags.map((tag: string) => {
|
||||
const q = search.trim().toLowerCase();
|
||||
@@ -317,7 +327,7 @@ export default function Home() {
|
||||
|
||||
{/* Posts */}
|
||||
{(() => {
|
||||
const posts = nodes.filter((n) => n.type === 'post');
|
||||
const posts = nodes.filter((n) => n.type === 'post' && n.slug !== 'about');
|
||||
const pinnedPosts = posts.filter((post: any) => post.pinned);
|
||||
const unpinnedPosts = posts.filter((post: any) => !post.pinned);
|
||||
return [...pinnedPosts, ...unpinnedPosts].map((post: any) => (
|
||||
@@ -341,7 +351,7 @@ export default function Home() {
|
||||
)}
|
||||
<div>Erstellt: {format(new Date(post.createdAt), 'd. MMMM yyyy HH:mm')}</div>
|
||||
</div>
|
||||
<p className="text-gray-700 mb-3 sm:mb-4 text-sm sm:text-base">{post.summary}</p>
|
||||
<p className="text-gray-700 mb-3 sm:mb-4 text-sm sm:text-base">{stripFrontmatter(post.summary)}</p>
|
||||
<div className="flex flex-wrap gap-1 sm:gap-2">
|
||||
{post.tags.map((tag: string) => (
|
||||
<span
|
||||
|
||||
Reference in New Issue
Block a user