Skip to content

Commit bab07b5

Browse files
authored
Merge pull request #29 from khaykingleb/improve-seo
feat(seo): introduce dynamic sitemap.xml and robots.txt
2 parents be9292d + 9d4a34d commit bab07b5

File tree

10 files changed

+62
-1
lines changed

10 files changed

+62
-1
lines changed

app/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import "react-notion-x/src/styles.css";
22
import "prismjs/themes/prism-tomorrow.css";
33
import "katex/dist/katex.min.css";
44

5-
import { LinksFunction, MetaFunction } from "@remix-run/node";
5+
import type { LinksFunction, MetaFunction } from "@remix-run/node";
66
import {
77
Links,
88
Meta,

app/routes/[robots.txt].ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { generateRobotsTxt } from "@nasa-gcn/remix-seo";
2+
3+
export function loader() {
4+
return generateRobotsTxt([
5+
{ type: "sitemap", value: "https://khaykingleb.com/sitemap.xml" },
6+
]);
7+
}

app/routes/[sitemap.xml].tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { generateSitemap } from "@nasa-gcn/remix-seo";
2+
import type { LoaderFunctionArgs } from "@remix-run/node";
3+
// @ts-expect-error Virtual modules are not recognized by TypeScript
4+
// https://github.com/nasa-gcn/remix-seo/issues/7
5+
// eslint-disable-next-line import/no-unresolved
6+
import { routes } from "virtual:remix/server-build";
7+
8+
export function loader({ request }: LoaderFunctionArgs) {
9+
return generateSitemap(request, routes, {
10+
siteUrl: "https://khaykingleb.com",
11+
});
12+
}

app/routes/_index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SEOHandle } from "@nasa-gcn/remix-seo";
12
import { MetaFunction } from "@remix-run/node";
23

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

24+
export const handle: SEOHandle = {
25+
getSitemapEntries: async () => {
26+
return [{ route: "/", priority: 1, changefreq: "monthly" }];
27+
},
28+
};
29+
2330
export default function IndexRoute() {
2431
return (
2532
<div className="flex min-h-screen flex-col">

app/routes/blog.$slug.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SEOHandle } from "@nasa-gcn/remix-seo";
12
import {
23
defer,
34
LoaderFunction,
@@ -111,6 +112,16 @@ export const loader: LoaderFunction = async ({
111112
return defer({ post, recordMap: recordMapPromise });
112113
};
113114

115+
export const handle: SEOHandle = {
116+
getSitemapEntries: async () => {
117+
return posts.map((post) => ({
118+
route: `/blog/${post.slug}`,
119+
priority: 0.7,
120+
changefreq: "monthly",
121+
}));
122+
},
123+
};
124+
114125
// @ts-expect-error: Expect not assignable type (otherwise, it would be a server timeout)
115126
export const meta: MetaFunction = ({ data }: { data: { post: Post } }) => {
116127
const { post } = data;

app/routes/blog._index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SEOHandle } from "@nasa-gcn/remix-seo";
12
import { MetaFunction } from "@remix-run/node";
23
import { useCallback, useEffect, useMemo, useState } from "react";
34

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

12+
export const handle: SEOHandle = {
13+
getSitemapEntries: async () => {
14+
return [{ route: "/blog", priority: 1, changefreq: "weekly" }];
15+
},
16+
};
17+
1118
export const meta: MetaFunction = () => {
1219
return [
1320
{ charset: "utf-8" },

app/routes/projects.tsx

Whitespace-only changes.

cspell.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ export default {
2626
"vercel",
2727
"katex",
2828
"pageid",
29+
"changefreq",
2930
],
3031
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"stylelint": "stylelint --cache --cache-location ./node_modules/.cache/stylelint \"app/**/*.{css,js}\""
1515
},
1616
"dependencies": {
17+
"@nasa-gcn/remix-seo": "^2.0.1",
1718
"@remix-run/node": "^2.11.2",
1819
"@remix-run/react": "^2.11.2",
1920
"@remix-run/serve": "^2.11.2",

pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)