mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-07-21 21:13:45 +08:00
Fix blog canonical URLs
This commit is contained in:
parent
b647b3e941
commit
17fb6960d0
@ -1,24 +1,37 @@
|
||||
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||
import { createFileRoute, notFound, redirect } from "@tanstack/react-router";
|
||||
import codeSnippetsCssUrl from "@/assets/code-snippet.css?url";
|
||||
import { ContentPageWrapper } from "@/components/ContentPageWrapper";
|
||||
import { currentBaseUrl } from "@/constants";
|
||||
import { Mdx } from "@/features/blog/components/mdx";
|
||||
import { createMetaTags } from "@/lib/createMetaTags";
|
||||
|
||||
export const Route = createFileRoute("/_layout/$slug")({
|
||||
loader: async ({ params }) => {
|
||||
const { allPosts } = await import("@/content-collections");
|
||||
const post = allPosts.find((post) => post._meta.path.endsWith(params.slug));
|
||||
const post = allPosts.find((post) => post._meta.path === params.slug);
|
||||
|
||||
if (!post) {
|
||||
if (post) return { post };
|
||||
|
||||
if (allPosts.some((post) => post._meta.path === `blog/${params.slug}`)) {
|
||||
throw redirect({
|
||||
to: "/",
|
||||
to: "/blog/$slug",
|
||||
params: { slug: params.slug },
|
||||
statusCode: 301,
|
||||
});
|
||||
}
|
||||
|
||||
return { post };
|
||||
throw notFound();
|
||||
},
|
||||
head: ({ loaderData }) => ({
|
||||
links: [{ rel: "stylesheet", href: codeSnippetsCssUrl }],
|
||||
links: loaderData
|
||||
? [
|
||||
{ rel: "stylesheet", href: codeSnippetsCssUrl },
|
||||
{
|
||||
rel: "canonical",
|
||||
href: `${currentBaseUrl}/${loaderData.post._meta.path}`,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
meta: loaderData
|
||||
? [
|
||||
...createMetaTags({
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||
import { createFileRoute, notFound } from "@tanstack/react-router";
|
||||
import { cx } from "@typebot.io/ui/lib/cva";
|
||||
import codeSnippetsCssUrl from "@/assets/code-snippet.css?url";
|
||||
import { ContentPageWrapper } from "@/components/ContentPageWrapper";
|
||||
import { TextLink } from "@/components/link";
|
||||
import { currentBaseUrl } from "@/constants";
|
||||
import { Mdx } from "@/features/blog/components/mdx";
|
||||
import { authors } from "@/features/blog/data/authors";
|
||||
import { formatDate } from "@/features/blog/helpers";
|
||||
@ -11,18 +12,26 @@ import { createMetaTags } from "@/lib/createMetaTags";
|
||||
export const Route = createFileRoute("/_layout/blog/$slug")({
|
||||
loader: async ({ params }) => {
|
||||
const { allPosts } = await import("@/content-collections");
|
||||
const post = allPosts.find((post) => post._meta.path.endsWith(params.slug));
|
||||
const post = allPosts.find(
|
||||
(post) => post._meta.path === `blog/${params.slug}`,
|
||||
);
|
||||
|
||||
if (!post) {
|
||||
throw redirect({
|
||||
to: "/blog",
|
||||
});
|
||||
throw notFound();
|
||||
}
|
||||
|
||||
return { post, author: authors[post.author as keyof typeof authors] };
|
||||
},
|
||||
head: ({ loaderData }) => ({
|
||||
links: [{ rel: "stylesheet", href: codeSnippetsCssUrl }],
|
||||
links: loaderData
|
||||
? [
|
||||
{ rel: "stylesheet", href: codeSnippetsCssUrl },
|
||||
{
|
||||
rel: "canonical",
|
||||
href: `${currentBaseUrl}/${loaderData.post._meta.path}`,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
meta: loaderData
|
||||
? [
|
||||
...createMetaTags({
|
||||
|
||||
@ -2,6 +2,7 @@ import { createFileRoute, Link } from "@tanstack/react-router";
|
||||
import { isDefined } from "@typebot.io/lib/utils";
|
||||
import { Card } from "@/components/Card";
|
||||
import { ContentPageWrapper } from "@/components/ContentPageWrapper";
|
||||
import { currentBaseUrl } from "@/constants";
|
||||
import { formatDate } from "@/features/blog/helpers";
|
||||
import { createMetaTags } from "@/lib/createMetaTags";
|
||||
|
||||
@ -18,6 +19,7 @@ export const Route = createFileRoute("/_layout/blog/")({
|
||||
};
|
||||
},
|
||||
head: () => ({
|
||||
links: [{ rel: "canonical", href: `${currentBaseUrl}/blog` }],
|
||||
meta: createMetaTags({
|
||||
title: "Typebot Blog",
|
||||
description:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user