From 0a77b3a841b5631822051b533a1a4fb6ea25e665 Mon Sep 17 00:00:00 2001 From: Sangeet Agarwal Date: Mon, 20 Nov 2023 18:20:23 -0500 Subject: [PATCH] feat: canonical urls for index pg, projects and tags --- app/routes/__index/index.tsx | 3 ++- app/routes/__index/projects.tsx | 6 ++++-- app/routes/__index/tags.$tag.tsx | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/routes/__index/index.tsx b/app/routes/__index/index.tsx index 48e97a3..21c779b 100644 --- a/app/routes/__index/index.tsx +++ b/app/routes/__index/index.tsx @@ -22,7 +22,8 @@ export const loader: LoaderFunction = async () => { posts.forEach((post) => { return (post.date = formatDate(post.date)); }); - return { posts, siteMetadata }; + const canonical = `${siteMetadata.siteUrl}/`; + return { posts, siteMetadata, canonical }; }; const MAX_DISPLAY = 10; export default function Index() { diff --git a/app/routes/__index/projects.tsx b/app/routes/__index/projects.tsx index dbc70fb..21dd29d 100644 --- a/app/routes/__index/projects.tsx +++ b/app/routes/__index/projects.tsx @@ -5,6 +5,7 @@ import { json } from "@remix-run/server-runtime"; import { Card } from "~/components/Card"; import projectsData from "~/data/projectsData"; import { getSeoMeta } from "~/seo"; +import { siteMetadata } from "~/utils/siteMetadata"; export const handle: SEOHandle = { getSitemapEntries: async (request) => { @@ -24,10 +25,11 @@ export let meta = (context: any) => { export const loader: LoaderFunction = async () => { const projects = projectsData; - return json(projects); + const canonical = `${siteMetadata.siteUrl}/projects`; + return json({ projects, canonical }); }; export default function Projects() { - const projects = useLoaderData(); + const { projects } = useLoaderData(); return ( <>
diff --git a/app/routes/__index/tags.$tag.tsx b/app/routes/__index/tags.$tag.tsx index ea228b3..2d4113f 100644 --- a/app/routes/__index/tags.$tag.tsx +++ b/app/routes/__index/tags.$tag.tsx @@ -45,7 +45,8 @@ export const loader: LoaderFunction = async ({ filteredFrontMatters.forEach((frontMatter) => { return (frontMatter.date = formatDate(frontMatter.date)); }); - return json({ filteredFrontMatters, tag }); + const canonical = `${siteMetadata.siteUrl}/tags/${tag}`; + return json({ filteredFrontMatters, tag, canonical }); } };