Compare commits
1 Commits
v1.2.8-rc.
...
v1.2.8
| Author | SHA1 | Date | |
|---|---|---|---|
| 678c803408 |
@@ -54,7 +54,7 @@ export default async function BlogPost({ params }: BlogPostProps) {
|
|||||||
const { locale, slug } = await params;
|
const { locale, slug } = await params;
|
||||||
setRequestLocale(locale);
|
setRequestLocale(locale);
|
||||||
const post = await getPostBySlug(slug, locale);
|
const post = await getPostBySlug(slug, locale);
|
||||||
const { prev, next } = await getAdjacentPosts(slug, locale);
|
const { prev, next, isPrevRandom, isNextRandom } = await getAdjacentPosts(slug, locale);
|
||||||
|
|
||||||
if (!post) {
|
if (!post) {
|
||||||
notFound();
|
notFound();
|
||||||
@@ -70,11 +70,7 @@ export default async function BlogPost({ params }: BlogPostProps) {
|
|||||||
category={post.frontmatter.category}
|
category={post.frontmatter.category}
|
||||||
readingTime={getReadingTime(post.content)}
|
readingTime={getReadingTime(post.content)}
|
||||||
/>
|
/>
|
||||||
{(new Date(post.frontmatter.date) > new Date() || post.frontmatter.public === false) && (
|
|
||||||
<div className="bg-orange-500 text-white text-center py-2 px-4 font-bold text-sm tracking-wider uppercase relative z-50">
|
|
||||||
Preview (Not visible in production)
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{/* Featured Image Header */}
|
{/* Featured Image Header */}
|
||||||
{post.frontmatter.featuredImage ? (
|
{post.frontmatter.featuredImage ? (
|
||||||
<div className="relative w-full h-[70vh] min-h-[500px] overflow-hidden group">
|
<div className="relative w-full h-[70vh] min-h-[500px] overflow-hidden group">
|
||||||
@@ -114,6 +110,12 @@ export default async function BlogPost({ params }: BlogPostProps) {
|
|||||||
</time>
|
</time>
|
||||||
<span className="w-1 h-1 bg-white/30 rounded-full" />
|
<span className="w-1 h-1 bg-white/30 rounded-full" />
|
||||||
<span>{getReadingTime(post.content)} min read</span>
|
<span>{getReadingTime(post.content)} min read</span>
|
||||||
|
{(new Date(post.frontmatter.date) > new Date() || post.frontmatter.public === false) && (
|
||||||
|
<>
|
||||||
|
<span className="w-1 h-1 bg-white/30 rounded-full" />
|
||||||
|
<span className="px-2 py-0.5 border border-white/40 text-white/80 rounded uppercase tracking-widest text-[10px] md:text-xs font-bold">Draft Preview</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -142,6 +144,12 @@ export default async function BlogPost({ params }: BlogPostProps) {
|
|||||||
</time>
|
</time>
|
||||||
<span className="w-1 h-1 bg-neutral-300 rounded-full" />
|
<span className="w-1 h-1 bg-neutral-300 rounded-full" />
|
||||||
<span>{getReadingTime(post.content)} min read</span>
|
<span>{getReadingTime(post.content)} min read</span>
|
||||||
|
{(new Date(post.frontmatter.date) > new Date() || post.frontmatter.public === false) && (
|
||||||
|
<>
|
||||||
|
<span className="w-1 h-1 bg-neutral-300 rounded-full" />
|
||||||
|
<span className="px-2 py-0.5 border border-orange-500/50 text-orange-600 rounded uppercase tracking-widest text-[10px] md:text-xs font-bold">Draft Preview</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -173,7 +181,7 @@ export default async function BlogPost({ params }: BlogPostProps) {
|
|||||||
|
|
||||||
{/* Post Navigation */}
|
{/* Post Navigation */}
|
||||||
<div className="mt-16">
|
<div className="mt-16">
|
||||||
<PostNavigation prev={prev} next={next} locale={locale} />
|
<PostNavigation prev={prev} next={next} isPrevRandom={isPrevRandom} isNextRandom={isNextRandom} locale={locale} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Back to blog link */}
|
{/* Back to blog link */}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export default async function BlogIndex({ params }: BlogIndexProps) {
|
|||||||
{featuredPost && featuredPost.frontmatter.featuredImage && (
|
{featuredPost && featuredPost.frontmatter.featuredImage && (
|
||||||
<>
|
<>
|
||||||
<Image
|
<Image
|
||||||
src={featuredPost.frontmatter.featuredImage}
|
src={`${featuredPost.frontmatter.featuredImage}?gravity=obj:face`}
|
||||||
alt={featuredPost.frontmatter.title}
|
alt={featuredPost.frontmatter.title}
|
||||||
fill
|
fill
|
||||||
className="absolute inset-0 w-full h-full object-cover opacity-40 md:opacity-60"
|
className="absolute inset-0 w-full h-full object-cover opacity-40 md:opacity-60"
|
||||||
@@ -80,8 +80,8 @@ export default async function BlogIndex({ params }: BlogIndexProps) {
|
|||||||
{featuredPost &&
|
{featuredPost &&
|
||||||
(new Date(featuredPost.frontmatter.date) > new Date() ||
|
(new Date(featuredPost.frontmatter.date) > new Date() ||
|
||||||
featuredPost.frontmatter.public === false) && (
|
featuredPost.frontmatter.public === false) && (
|
||||||
<Badge variant="accent" className="bg-orange-500 text-white border-none">
|
<Badge variant="neutral" className="border border-white/30 bg-transparent text-white/80 shadow-none">
|
||||||
Preview
|
Draft Preview
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -160,7 +160,7 @@ export default async function BlogIndex({ params }: BlogIndexProps) {
|
|||||||
{post.frontmatter.featuredImage && (
|
{post.frontmatter.featuredImage && (
|
||||||
<div className="relative h-48 md:h-72 overflow-hidden">
|
<div className="relative h-48 md:h-72 overflow-hidden">
|
||||||
<Image
|
<Image
|
||||||
src={post.frontmatter.featuredImage}
|
src={`${post.frontmatter.featuredImage}?gravity=obj:face`}
|
||||||
alt={post.frontmatter.title}
|
alt={post.frontmatter.title}
|
||||||
fill
|
fill
|
||||||
className="w-full h-full object-cover transition-transform duration-1000 group-hover:scale-110"
|
className="w-full h-full object-cover transition-transform duration-1000 group-hover:scale-110"
|
||||||
@@ -175,24 +175,22 @@ export default async function BlogIndex({ params }: BlogIndexProps) {
|
|||||||
{post.frontmatter.category}
|
{post.frontmatter.category}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
{(new Date(post.frontmatter.date) > new Date() ||
|
|
||||||
post.frontmatter.public === false) && (
|
|
||||||
<Badge
|
|
||||||
variant="accent"
|
|
||||||
className="absolute top-3 right-3 md:top-6 md:right-6 shadow-lg bg-orange-500 text-white border-none"
|
|
||||||
>
|
|
||||||
Preview
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="p-5 md:p-10 flex flex-col flex-1">
|
<div className="p-5 md:p-10 flex flex-col flex-1">
|
||||||
<div className="text-[10px] md:text-sm font-bold text-accent-dark mb-2 md:mb-4 tracking-widest uppercase">
|
<div className="flex items-center gap-3 text-[10px] md:text-sm font-bold text-accent-dark mb-2 md:mb-4 tracking-widest uppercase">
|
||||||
{new Date(post.frontmatter.date).toLocaleDateString(locale, {
|
<span>
|
||||||
year: 'numeric',
|
{new Date(post.frontmatter.date).toLocaleDateString(locale, {
|
||||||
month: 'long',
|
year: 'numeric',
|
||||||
day: 'numeric',
|
month: 'long',
|
||||||
})}
|
day: 'numeric',
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
{(new Date(post.frontmatter.date) > new Date() ||
|
||||||
|
post.frontmatter.public === false) && (
|
||||||
|
<span className="px-1.5 py-0.5 border border-current rounded-sm text-[9px] md:text-xs">Draft</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<h3 className="text-lg md:text-2xl font-bold text-primary mb-3 md:mb-6 group-hover:text-accent-dark transition-colors line-clamp-2 leading-tight">
|
<h3 className="text-lg md:text-2xl font-bold text-primary mb-3 md:mb-6 group-hover:text-accent-dark transition-colors line-clamp-2 leading-tight">
|
||||||
{post.frontmatter.title}
|
{post.frontmatter.title}
|
||||||
|
|||||||
@@ -5,43 +5,47 @@ import { PostMdx } from '@/lib/blog';
|
|||||||
interface PostNavigationProps {
|
interface PostNavigationProps {
|
||||||
prev: PostMdx | null;
|
prev: PostMdx | null;
|
||||||
next: PostMdx | null;
|
next: PostMdx | null;
|
||||||
|
isPrevRandom?: boolean;
|
||||||
|
isNextRandom?: boolean;
|
||||||
locale: string;
|
locale: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PostNavigation({ prev, next, locale }: PostNavigationProps) {
|
export default function PostNavigation({ prev, next, isPrevRandom, isNextRandom, locale }: PostNavigationProps) {
|
||||||
if (!prev && !next) return null;
|
if (!prev && !next) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 w-full mt-16">
|
<div className="grid grid-cols-1 md:grid-cols-2 w-full mt-16">
|
||||||
{/* Previous Post (Older) */}
|
{/* Previous Post (Older) */}
|
||||||
{prev ? (
|
{prev ? (
|
||||||
<Link
|
<Link
|
||||||
href={`/${locale}/blog/${prev.slug}`}
|
href={`/${locale}/blog/${prev.slug}`}
|
||||||
className="group relative h-64 md:h-80 overflow-hidden block"
|
className="group relative h-64 md:h-80 overflow-hidden block"
|
||||||
>
|
>
|
||||||
{/* Background Image */}
|
{/* Background Image */}
|
||||||
{prev.frontmatter.featuredImage ? (
|
{prev.frontmatter.featuredImage ? (
|
||||||
<div
|
<div
|
||||||
className="absolute inset-0 bg-cover bg-center transition-transform duration-700 group-hover:scale-110"
|
className="absolute inset-0 bg-cover bg-center transition-transform duration-700 group-hover:scale-110"
|
||||||
style={{ backgroundImage: `url(${prev.frontmatter.featuredImage})` }}
|
style={{ backgroundImage: `url(${prev.frontmatter.featuredImage})` }}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="absolute inset-0 bg-neutral-100" />
|
<div className="absolute inset-0 bg-neutral-100" />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Overlay */}
|
{/* Overlay */}
|
||||||
<div className="absolute inset-0 bg-black/60 group-hover:bg-black/50 transition-colors duration-300" />
|
<div className="absolute inset-0 bg-black/60 group-hover:bg-black/50 transition-colors duration-300" />
|
||||||
|
|
||||||
{/* Content */}
|
{/* Content */}
|
||||||
<div className="absolute inset-0 flex flex-col justify-center p-8 md:p-12 text-white z-10">
|
<div className="absolute inset-0 flex flex-col justify-center p-8 md:p-12 text-white z-10">
|
||||||
<span className="text-sm font-bold uppercase tracking-wider mb-2 opacity-70">
|
<span className="text-sm font-bold uppercase tracking-wider mb-2 opacity-70">
|
||||||
{locale === 'de' ? 'Vorheriger Beitrag' : 'Previous Post'}
|
{isPrevRandom
|
||||||
|
? (locale === 'de' ? 'Weiterer Artikel' : 'More Article')
|
||||||
|
: (locale === 'de' ? 'Vorheriger Beitrag' : 'Previous Post')}
|
||||||
</span>
|
</span>
|
||||||
<h3 className="text-xl md:text-2xl font-bold leading-tight group-hover:underline decoration-2 underline-offset-4">
|
<h3 className="text-xl md:text-2xl font-bold leading-tight group-hover:underline decoration-2 underline-offset-4">
|
||||||
{prev.frontmatter.title}
|
{prev.frontmatter.title}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Arrow Icon */}
|
{/* Arrow Icon */}
|
||||||
<div className="absolute left-4 top-1/2 -translate-y-1/2 text-white/30 group-hover:text-white group-hover:-translate-x-2 transition-all duration-300">
|
<div className="absolute left-4 top-1/2 -translate-y-1/2 text-white/30 group-hover:text-white group-hover:-translate-x-2 transition-all duration-300">
|
||||||
<svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
@@ -55,33 +59,35 @@ export default function PostNavigation({ prev, next, locale }: PostNavigationPro
|
|||||||
|
|
||||||
{/* Next Post (Newer) */}
|
{/* Next Post (Newer) */}
|
||||||
{next ? (
|
{next ? (
|
||||||
<Link
|
<Link
|
||||||
href={`/${locale}/blog/${next.slug}`}
|
href={`/${locale}/blog/${next.slug}`}
|
||||||
className="group relative h-64 md:h-80 overflow-hidden block"
|
className="group relative h-64 md:h-80 overflow-hidden block"
|
||||||
>
|
>
|
||||||
{/* Background Image */}
|
{/* Background Image */}
|
||||||
{next.frontmatter.featuredImage ? (
|
{next.frontmatter.featuredImage ? (
|
||||||
<div
|
<div
|
||||||
className="absolute inset-0 bg-cover bg-center transition-transform duration-700 group-hover:scale-110"
|
className="absolute inset-0 bg-cover bg-center transition-transform duration-700 group-hover:scale-110"
|
||||||
style={{ backgroundImage: `url(${next.frontmatter.featuredImage})` }}
|
style={{ backgroundImage: `url(${next.frontmatter.featuredImage})` }}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="absolute inset-0 bg-neutral-100" />
|
<div className="absolute inset-0 bg-neutral-100" />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Overlay */}
|
{/* Overlay */}
|
||||||
<div className="absolute inset-0 bg-black/60 group-hover:bg-black/50 transition-colors duration-300" />
|
<div className="absolute inset-0 bg-black/60 group-hover:bg-black/50 transition-colors duration-300" />
|
||||||
|
|
||||||
{/* Content */}
|
{/* Content */}
|
||||||
<div className="absolute inset-0 flex flex-col justify-center items-end text-right p-8 md:p-12 text-white z-10">
|
<div className="absolute inset-0 flex flex-col justify-center items-end text-right p-8 md:p-12 text-white z-10">
|
||||||
<span className="text-sm font-bold uppercase tracking-wider mb-2 opacity-70">
|
<span className="text-sm font-bold uppercase tracking-wider mb-2 opacity-70">
|
||||||
{locale === 'de' ? 'Nächster Beitrag' : 'Next Post'}
|
{isNextRandom
|
||||||
|
? (locale === 'de' ? 'Weiterer Artikel' : 'More Article')
|
||||||
|
: (locale === 'de' ? 'Nächster Beitrag' : 'Next Post')}
|
||||||
</span>
|
</span>
|
||||||
<h3 className="text-xl md:text-2xl font-bold leading-tight group-hover:underline decoration-2 underline-offset-4">
|
<h3 className="text-xl md:text-2xl font-bold leading-tight group-hover:underline decoration-2 underline-offset-4">
|
||||||
{next.frontmatter.title}
|
{next.frontmatter.title}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Arrow Icon */}
|
{/* Arrow Icon */}
|
||||||
<div className="absolute right-4 top-1/2 -translate-y-1/2 text-white/30 group-hover:text-white group-hover:translate-x-2 transition-all duration-300">
|
<div className="absolute right-4 top-1/2 -translate-y-1/2 text-white/30 group-hover:text-white group-hover:translate-x-2 transition-all duration-300">
|
||||||
<svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
|||||||
29
lib/blog.ts
29
lib/blog.ts
@@ -109,7 +109,7 @@ export async function getAllPostsMetadata(locale: string): Promise<Partial<PostM
|
|||||||
export async function getAdjacentPosts(
|
export async function getAdjacentPosts(
|
||||||
slug: string,
|
slug: string,
|
||||||
locale: string,
|
locale: string,
|
||||||
): Promise<{ prev: PostMdx | null; next: PostMdx | null }> {
|
): Promise<{ prev: PostMdx | null; next: PostMdx | null; isPrevRandom?: boolean; isNextRandom?: boolean }> {
|
||||||
const posts = await getAllPosts(locale);
|
const posts = await getAllPosts(locale);
|
||||||
const currentIndex = posts.findIndex((post) => post.slug === slug);
|
const currentIndex = posts.findIndex((post) => post.slug === slug);
|
||||||
|
|
||||||
@@ -120,10 +120,31 @@ export async function getAdjacentPosts(
|
|||||||
// Posts are sorted by date descending (newest first)
|
// Posts are sorted by date descending (newest first)
|
||||||
// So "next" post (newer) is at index - 1
|
// So "next" post (newer) is at index - 1
|
||||||
// And "previous" post (older) is at index + 1
|
// And "previous" post (older) is at index + 1
|
||||||
const next = currentIndex > 0 ? posts[currentIndex - 1] : null;
|
let next = currentIndex > 0 ? posts[currentIndex - 1] : null;
|
||||||
const prev = currentIndex < posts.length - 1 ? posts[currentIndex + 1] : null;
|
let prev = currentIndex < posts.length - 1 ? posts[currentIndex + 1] : null;
|
||||||
|
|
||||||
return { prev, next };
|
let isNextRandom = false;
|
||||||
|
let isPrevRandom = false;
|
||||||
|
|
||||||
|
const getRandomPost = (excludeSlugs: string[]) => {
|
||||||
|
const available = posts.filter(p => !excludeSlugs.includes(p.slug));
|
||||||
|
if (available.length === 0) return null;
|
||||||
|
return available[Math.floor(Math.random() * available.length)];
|
||||||
|
};
|
||||||
|
|
||||||
|
// If there's no next post (we are at the newest post), show a random post instead
|
||||||
|
if (!next && posts.length > 2) {
|
||||||
|
next = getRandomPost([slug, prev?.slug].filter(Boolean) as string[]);
|
||||||
|
isNextRandom = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's no previous post (we are at the oldest post), show a random post instead
|
||||||
|
if (!prev && posts.length > 2) {
|
||||||
|
prev = getRandomPost([slug, next?.slug].filter(Boolean) as string[]);
|
||||||
|
isPrevRandom = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { prev, next, isPrevRandom, isNextRandom };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getReadingTime(content: string): number {
|
export function getReadingTime(content: string): number {
|
||||||
|
|||||||
@@ -23,11 +23,28 @@ export default function imgproxyLoader({
|
|||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if src contains custom gravity query parameter
|
||||||
|
let gravity = 'sm'; // Use smart gravity (content-aware) by default
|
||||||
|
let cleanSrc = src;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Dummy base needed for relative URLs
|
||||||
|
const url = new URL(src, 'http://localhost');
|
||||||
|
const customGravity = url.searchParams.get('gravity');
|
||||||
|
if (customGravity) {
|
||||||
|
gravity = customGravity;
|
||||||
|
url.searchParams.delete('gravity');
|
||||||
|
cleanSrc = src.startsWith('http') ? url.href : url.pathname + url.search;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback if parsing fails
|
||||||
|
}
|
||||||
|
|
||||||
// We use the width provided by Next.js for responsive images
|
// We use the width provided by Next.js for responsive images
|
||||||
// Height is set to 0 to maintain aspect ratio
|
// Height is set to 0 to maintain aspect ratio
|
||||||
return getImgproxyUrl(src, {
|
return getImgproxyUrl(cleanSrc, {
|
||||||
width,
|
width,
|
||||||
resizing_type: 'fit',
|
resizing_type: 'fit',
|
||||||
gravity: 'sm', // Use smart gravity (content-aware) instead of face detection (requires ML/Pro)
|
gravity,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user