Skip to content

Commit

Permalink
Merge pull request #29 from khaykingleb/improve-seo
Browse files Browse the repository at this point in the history
feat(seo): introduce dynamic sitemap.xml and robots.txt
  • Loading branch information
khaykingleb authored Oct 28, 2024
2 parents be9292d + 9d4a34d commit bab07b5
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "react-notion-x/src/styles.css";
import "prismjs/themes/prism-tomorrow.css";
import "katex/dist/katex.min.css";

import { LinksFunction, MetaFunction } from "@remix-run/node";
import type { LinksFunction, MetaFunction } from "@remix-run/node";
import {
Links,
Meta,
Expand Down
7 changes: 7 additions & 0 deletions app/routes/[robots.txt].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { generateRobotsTxt } from "@nasa-gcn/remix-seo";

export function loader() {
return generateRobotsTxt([
{ type: "sitemap", value: "https://khaykingleb.com/sitemap.xml" },
]);
}
12 changes: 12 additions & 0 deletions app/routes/[sitemap.xml].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { generateSitemap } from "@nasa-gcn/remix-seo";
import type { LoaderFunctionArgs } from "@remix-run/node";
// @ts-expect-error Virtual modules are not recognized by TypeScript
// https://github.com/nasa-gcn/remix-seo/issues/7
// eslint-disable-next-line import/no-unresolved
import { routes } from "virtual:remix/server-build";

export function loader({ request }: LoaderFunctionArgs) {
return generateSitemap(request, routes, {
siteUrl: "https://khaykingleb.com",
});
}
7 changes: 7 additions & 0 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SEOHandle } from "@nasa-gcn/remix-seo";
import { MetaFunction } from "@remix-run/node";

import { Avatar } from "~/components/atoms/Avatar";
Expand All @@ -20,6 +21,12 @@ export const meta: MetaFunction = () => {
];
};

export const handle: SEOHandle = {
getSitemapEntries: async () => {
return [{ route: "/", priority: 1, changefreq: "monthly" }];
},
};

export default function IndexRoute() {
return (
<div className="flex min-h-screen flex-col">
Expand Down
11 changes: 11 additions & 0 deletions app/routes/blog.$slug.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SEOHandle } from "@nasa-gcn/remix-seo";
import {
defer,
LoaderFunction,
Expand Down Expand Up @@ -111,6 +112,16 @@ export const loader: LoaderFunction = async ({
return defer({ post, recordMap: recordMapPromise });
};

export const handle: SEOHandle = {
getSitemapEntries: async () => {
return posts.map((post) => ({
route: `/blog/${post.slug}`,
priority: 0.7,
changefreq: "monthly",
}));
},
};

// @ts-expect-error: Expect not assignable type (otherwise, it would be a server timeout)
export const meta: MetaFunction = ({ data }: { data: { post: Post } }) => {
const { post } = data;
Expand Down
7 changes: 7 additions & 0 deletions app/routes/blog._index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SEOHandle } from "@nasa-gcn/remix-seo";
import { MetaFunction } from "@remix-run/node";
import { useCallback, useEffect, useMemo, useState } from "react";

Expand All @@ -8,6 +9,12 @@ import { Header } from "~/components/organisms/Header";
import { Pagination } from "~/components/organisms/Pagination";
import { posts } from "~/data/posts";

export const handle: SEOHandle = {
getSitemapEntries: async () => {
return [{ route: "/blog", priority: 1, changefreq: "weekly" }];
},
};

export const meta: MetaFunction = () => {
return [
{ charset: "utf-8" },
Expand Down
Empty file added app/routes/projects.tsx
Empty file.
1 change: 1 addition & 0 deletions cspell.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export default {
"vercel",
"katex",
"pageid",
"changefreq",
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"stylelint": "stylelint --cache --cache-location ./node_modules/.cache/stylelint \"app/**/*.{css,js}\""
},
"dependencies": {
"@nasa-gcn/remix-seo": "^2.0.1",
"@remix-run/node": "^2.11.2",
"@remix-run/react": "^2.11.2",
"@remix-run/serve": "^2.11.2",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bab07b5

Please sign in to comment.