slug problem fixed

This commit is contained in:
michi 2025-08-26 15:56:33 +02:00
parent 00af25d9d6
commit 3e478b3574
25 changed files with 165 additions and 18 deletions

View File

@ -12,6 +12,11 @@
],
"rootMainFiles": [],
"pages": {
"/": [
"static/chunks/webpack.js",
"static/chunks/main.js",
"static/chunks/pages/index.js"
],
"/_app": [
"static/chunks/webpack.js",
"static/chunks/main.js",
@ -27,6 +32,11 @@
"static/chunks/main.js",
"static/chunks/pages/admin.js"
],
"/admin/login": [
"static/chunks/webpack.js",
"static/chunks/main.js",
"static/chunks/pages/admin/login.js"
],
"/blog/[slug]": [
"static/chunks/webpack.js",
"static/chunks/main.js",

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
self.__BUILD_MANIFEST={"polyfillFiles":["static/chunks/polyfills.js"],"devFiles":["static/chunks/react-refresh.js"],"ampDevFiles":[],"lowPriorityFiles":["static/development/_buildManifest.js","static/development/_ssgManifest.js"],"rootMainFiles":[],"pages":{"/_app":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/_app.js"],"/_error":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/_error.js"],"/admin":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/admin.js"],"/blog/[slug]":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/blog/[slug].js"],"/devlog":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/devlog.js"]},"ampFirstPages":[]}
self.__BUILD_MANIFEST={"polyfillFiles":["static/chunks/polyfills.js"],"devFiles":["static/chunks/react-refresh.js"],"ampDevFiles":[],"lowPriorityFiles":["static/development/_buildManifest.js","static/development/_ssgManifest.js"],"rootMainFiles":[],"pages":{"/":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/index.js"],"/_app":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/_app.js"],"/_error":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/_error.js"],"/admin":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/admin.js"],"/admin/login":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/admin/login.js"],"/blog/[slug]":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/blog/[slug].js"],"/devlog":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/devlog.js"]},"ampFirstPages":[]}

View File

@ -4,5 +4,8 @@
"/_document": "pages/_document.js",
"/admin": "pages/admin.js",
"/devlog": "pages/devlog.js",
"/blog/[slug]": "pages/blog/[slug].js"
"/blog/[slug]": "pages/blog/[slug].js",
"/admin/login": "pages/admin/login.js",
"/api/logout": "pages/api/logout.js",
"/": "pages/index.js"
}

View File

@ -1 +1 @@
self.__BUILD_MANIFEST = {__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/_error":["static\u002Fchunks\u002Fpages\u002F_error.js"],"/admin":["static\u002Fchunks\u002Fpages\u002Fadmin.js"],"/blog/[slug]":["static\u002Fchunks\u002Fpages\u002Fblog\u002F[slug].js"],"/devlog":["static\u002Fchunks\u002Fpages\u002Fdevlog.js"],sortedPages:["\u002F_app","\u002F_error","\u002Fadmin","\u002Fblog\u002F[slug]","\u002Fdevlog"]};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()
self.__BUILD_MANIFEST = {__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/":["static\u002Fchunks\u002Fpages\u002Findex.js"],"/_error":["static\u002Fchunks\u002Fpages\u002F_error.js"],"/admin":["static\u002Fchunks\u002Fpages\u002Fadmin.js"],"/admin/login":["static\u002Fchunks\u002Fpages\u002Fadmin\u002Flogin.js"],"/blog/[slug]":["static\u002Fchunks\u002Fpages\u002Fblog\u002F[slug].js"],"/devlog":["static\u002Fchunks\u002Fpages\u002Fdevlog.js"],sortedPages:["\u002F","\u002F_app","\u002F_error","\u002Fadmin","\u002Fadmin\u002Flogin","\u002Fblog\u002F[slug]","\u002Fdevlog"]};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()

File diff suppressed because one or more lines are too long

View File

@ -8,13 +8,24 @@ const AdminLayout = ({ children }) => {
const handleLogout = async () => {
setIsLoggingOut(true);
try {
// Cookie löschen
// API-Route für Logout aufrufen
await fetch('/api/logout', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});
// Cookie clientseitig löschen (als Backup)
document.cookie = 'isAuthenticated=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
// Zur Login-Seite weiterleiten
router.push('/admin/login');
} catch (error) {
console.error('Logout-Fehler:', error);
// Fallback: Cookie trotzdem löschen und weiterleiten
document.cookie = 'isAuthenticated=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
router.push('/admin/login');
} finally {
setIsLoggingOut(false);
}

17
pages/api/logout.js Normal file
View File

@ -0,0 +1,17 @@
export default function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).json({ message: 'Method not allowed' });
}
try {
// Cookie serverseitig löschen
res.setHeader('Set-Cookie', [
'isAuthenticated=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; SameSite=Strict'
]);
res.status(200).json({ message: 'Logout successful' });
} catch (error) {
console.error('Logout API error:', error);
res.status(500).json({ message: 'Internal server error' });
}
}

View File

@ -1,12 +1,9 @@
import { useRouter } from 'next/router';
import { motion } from 'framer-motion';
import devlogData from '../../data/devlog.json';
import Image from 'next/image';
import { supabase } from '../../lib/supabase';
export default function BlogPost() {
const router = useRouter();
const { slug } = router.query;
const blog = devlogData.find((entry) => entry.slug === slug);
export default function BlogPost({ blog }) {
if (!blog) {
return (
@ -40,8 +37,17 @@ export default function BlogPost() {
</motion.div>
<div className="space-y-8">
{blog.content && blog.content.map((item, index) =>
item.type === 'text' ? (
{blog.content && blog.content.map((item, index) => {
// Handle both old format (type/value) and new format (direct content)
if (typeof item === 'string') {
return (
<p key={index} className="text-gray-600 text-lg">
{item}
</p>
);
}
return item.type === 'text' ? (
<p key={index} className="text-gray-600 text-lg">
{item.value}
</p>
@ -50,14 +56,25 @@ export default function BlogPost() {
key={index}
className="relative w-full h-64 rounded-lg overflow-hidden"
>
{/* Only render image if src is valid */}
{item.value && (item.value.startsWith('/') || item.value.startsWith('http')) && (
<Image
src={item.value}
alt={blog.title}
fill
className="object-cover"
priority
/>
)}
</div>
)
);
})}
{/* If no structured content, show description */}
{(!blog.content || blog.content.length === 0) && blog.description && (
<p className="text-gray-600 text-lg">
{blog.description}
</p>
)}
</div>
</div>
@ -65,3 +82,65 @@ export default function BlogPost() {
</motion.div>
);
}
export async function getServerSideProps({ params }) {
const { slug } = params;
try {
// First, try to find the blog post in Supabase
const { data: supabaseBlog, error } = await supabase
.from('devlog_entries')
.select('*')
.eq('slug', slug)
.single();
if (supabaseBlog && !error) {
// Found in Supabase, format the data
const blog = {
id: supabaseBlog.id,
title: supabaseBlog.title,
date: supabaseBlog.date,
description: supabaseBlog.description,
slug: supabaseBlog.slug,
image: supabaseBlog.image,
content: supabaseBlog.content || []
};
return {
props: {
blog
}
};
}
// If not found in Supabase, try the static JSON file
const staticBlog = devlogData.find((entry) => entry.slug === slug);
if (staticBlog) {
return {
props: {
blog: staticBlog
}
};
}
// Blog post not found
return {
props: {
blog: null
}
};
} catch (error) {
console.error('Error fetching blog post:', error);
// Fallback to static data
const staticBlog = devlogData.find((entry) => entry.slug === slug);
return {
props: {
blog: staticBlog || null
}
};
}
}