Skip to content

Commit

Permalink
feat: canonical urls for index pg, projects and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
SangeetAgarwal committed Nov 20, 2023
1 parent 2bbda86 commit 0a77b3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/routes/__index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 4 additions & 2 deletions app/routes/__index/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 (
<>
<div className="divide-y divide-gray-200 dark:divide-gray-700">
Expand Down
3 changes: 2 additions & 1 deletion app/routes/__index/tags.$tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
};

Expand Down

0 comments on commit 0a77b3a

Please sign in to comment.