Skip to content

Commit

Permalink
added sitemap?
Browse files Browse the repository at this point in the history
  • Loading branch information
kielbasa-elp committed Aug 26, 2024
1 parent a109ea1 commit b80bd56
Show file tree
Hide file tree
Showing 4 changed files with 4,389 additions and 3,320 deletions.
9 changes: 9 additions & 0 deletions app/routes/blog_.$slug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { json, redirect } from "@remix-run/node";
import { generateMetadata } from "~/utils/meta";
import { BlogPost } from "~/views/BlogPost";
import { posts } from "~/views/BlogPostsData/blogPosts";
import { SEOHandle } from "@nasa-gcn/remix-seo";

export const meta: MetaFunction<typeof loader> = ({ data }) => {
return generateMetadata({
Expand All @@ -18,6 +19,14 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
});
};

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

export async function loader({ params }: LoaderFunctionArgs) {
const currentBlogPostData = posts.find(
(blogPostData) => blogPostData.slug === params.slug
Expand Down
29 changes: 29 additions & 0 deletions app/routes/sitemap[.]xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { generateSitemap } from "@nasa-gcn/remix-seo";
import { type LoaderFunctionArgs, type ServerBuild } from "@remix-run/node";

export async function loader({ request }: LoaderFunctionArgs) {
const serverBuild = await getBuild();

return generateSitemap(request, serverBuild.routes, {
siteUrl: getDomainUrl(request),
});
}

async function getBuild() {
return (await (import.meta.env.DEV
? //@ts-ignore
import("../../build/server/index.js")
: import(
/* @vite-ignore */
import.meta.resolve("../../build/server/index.js")
))) as unknown as ServerBuild;
}

function getDomainUrl(request: Request) {
const host =
request.headers.get("X-Forwarded-Host") ??
request.headers.get("host") ??
new URL(request.url).host;
const protocol = host.includes("localhost") ? "http" : "https";
return `${protocol}://${host}`;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@buildel/buildel": "^0.1.6",
"@buildel/buildel-auth": "^0.0.2",
"@nasa-gcn/remix-seo": "^2.0.1",
"@remix-run/node": "^2.7.2",
"@remix-run/react": "^2.7.2",
"@remix-run/serve": "^2.7.2",
Expand Down
Loading

0 comments on commit b80bd56

Please sign in to comment.