fix: show 404 when post doesn't exist
This commit is contained in:
parent
34ddae165b
commit
aaeb92da9f
6 changed files with 9 additions and 12 deletions
|
|
@ -8,8 +8,7 @@ const lang = getLangFromUrl(Astro.url)
|
|||
const t = useTranslations(lang)
|
||||
|
||||
const allPosts = await getPostsByLocale(lang)
|
||||
const posts = allPosts
|
||||
.slice(0, common.latestPosts)
|
||||
const posts = allPosts.slice(0, common.latestPosts)
|
||||
---
|
||||
|
||||
<div class="my-8 text-xl font-medium md:my-8">
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ pubDate: 2025-11-18
|
|||
description: "This is the first post of my new Astro blog."
|
||||
author: "@lio@pounced-on.me"
|
||||
tags: ["furries", "making-friends"]
|
||||
# published: true
|
||||
---
|
||||
|
||||
meow
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@ const urls = {
|
|||
general: `/images/general/ogImage.png`,
|
||||
}
|
||||
|
||||
const isPost = Astro.url.pathname.includes("posts")
|
||||
const isPost = post
|
||||
|
||||
const ogImageURL = new URL(isPost ? urls.postURL : urls.general, Astro.site)
|
||||
const ogImageURL = new URL(post ? urls.postURL : urls.general, Astro.site)
|
||||
.href
|
||||
const permalink = new URL(Astro.url.pathname, Astro.site).href
|
||||
const config = lang === "de" ? de : en
|
||||
const title = isPost
|
||||
const title = post
|
||||
? `${post.title} - ${config.meta.title}`
|
||||
: `${config.meta.description} - ${config.meta.title}`
|
||||
const description = isPost ? post.description : config.meta.description
|
||||
const description = post ? post.description : config.meta.description
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ export async function GET(request: { url: URL }) {
|
|||
return rss({
|
||||
title: config.meta.title,
|
||||
description: config.meta.description,
|
||||
site:
|
||||
config.meta.url,
|
||||
site: config.meta.url,
|
||||
items: posts.map((post: any) => ({
|
||||
title: post.data.title,
|
||||
description: post.data.description,
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ export async function GET() {
|
|||
return rss({
|
||||
title: config.meta.title,
|
||||
description: config.meta.description,
|
||||
site:
|
||||
config.meta.url,
|
||||
site: config.meta.url,
|
||||
items: posts.map((post: any) => ({
|
||||
title: post.data.title,
|
||||
description: post.data.description,
|
||||
|
|
|
|||
|
|
@ -35,11 +35,10 @@ export const getPostsByLocale = async (locale: string) => {
|
|||
: await getCollection("dePosts")
|
||||
// Add the locale to the data of each post
|
||||
|
||||
|
||||
posts.forEach((post: any) => {
|
||||
post.data.lang = locale
|
||||
})
|
||||
const filtered = posts.filter(p => p.data.published)
|
||||
const filtered = posts.filter((p) => p.data.published)
|
||||
return filtered.sort(
|
||||
(a: any, b: any) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue