Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/blog/astro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export default defineConfig({
markdown: {
remarkPlugins: [remarkPlugin],
},
});
});
1 change: 1 addition & 0 deletions apps/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@astrojs/react": "^4.1.2",
"@astrojs/rss": "^4.0.11",
"@astrojs/sitemap": "^3.2.1",
"@astrojs/tailwind": "^5.1.4",
"@astrojs/vercel": "^8.0.1",
"@crocoder-dev/remark-plugin": "*",
Expand Down
4 changes: 4 additions & 0 deletions apps/blog/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-agent: *
Allow: /

Sitemap: https://crocoder.dev/blog/sitemap.xml
2 changes: 1 addition & 1 deletion apps/blog/src/layouts/head.astro
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const allPartialsPlainText = (

const sufix = import.meta.env.DEV ? "" : "blog/";

const siteUrl = import.meta.env.SITE_URL + sufix;
const siteUrl = import.meta.env.PUBLIC_SITE_URL + sufix;

const posts = await getCollection("posts");
const currentPost = posts.find((post) => post.slug === slug);
Expand Down
47 changes: 47 additions & 0 deletions apps/blog/src/pages/sitemap.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getCollection } from "astro:content";
const markdownPosts = await getCollection("posts");

const prefix = import.meta.env.DEV ? "/" : "/blog";
const siteUrl = import.meta.env.PUBLIC_SITE_URL + (prefix === "/" ? "" : prefix);

export function GET() {
const posts = [
...markdownPosts.map((post: any) => ({
url: `${siteUrl}/${post.slug}`,
createdAt: post.data.createdAt
? new Date(post.data.createdAt)
: new Date(),
imageUrl: `${siteUrl}${post.data.image}`,
})),
];

posts.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());

const urls = posts
.map(
(post) => `
<url>
<loc>${post.url}</loc>
<lastmod>${post.createdAt}</lastmod>
${
post.imageUrl
? `
<image:image>
<image:loc>${post.imageUrl}</image:loc>
</image:image>`
: ""
}
<priority>1</priority>
</url>
`,
)
.join("");

return new Response(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
${urls}
</urlset>`,
{ headers: { "Content-Type": "application/xml" } },
);
}
4 changes: 4 additions & 0 deletions apps/website/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import tailwind from "@astrojs/tailwind";
import react from "@astrojs/react";
import vercel from "@astrojs/vercel/static";

// https://astro.build/config
export default defineConfig({
// redirects: {
// '/sitemap': '/sitemap.xml',
// },
output: "static",
adapter: vercel({
imageService: true,
Expand Down
4 changes: 4 additions & 0 deletions apps/website/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-agent: *
Allow: /

Sitemap: https://crocoder.dev/sitemap.xml
4 changes: 2 additions & 2 deletions apps/website/src/components/navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
data-navhidden
class="flex flex-col md:flex-row gap-7 mx-7 md:mx-0 md:ml-20 md:w-auto relative top-1"
>
<li>
<!-- <li>
<a
class="font-medium text-2xl md:text-lg text-[#E8E8E8] hover:text-white whitespace-nowrap"
href="/blog"
>
For CTOs
</a>
</li>
</li> -->
<li>
<a
class="font-medium text-2xl md:text-lg text-[#E8E8E8] hover:text-white"
Expand Down
1 change: 1 addition & 0 deletions apps/website/src/layouts/base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if (theme.fonts.font_family.secondary) {
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=5"
/>
<link rel="sitemap" href="/sitemap.xml" />
<Meta />
<AstroFont
config={[
Expand Down
35 changes: 35 additions & 0 deletions apps/website/src/pages/sitemap.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const siteUrl = import.meta.env.PUBLIC_SITE_URL;
const blogUrl = import.meta.env.PUBLIC_BLOG_URL;

export async function GET() {

console.log(blogUrl);

const urls = [
`<url>
<loc>${siteUrl}</loc>
<lastmod>${new Date()}</lastmod>
<priority>1</priority>
</url>`,
];
if (blogUrl) {
try {
const blogSitemapRes = await fetch(`${blogUrl}/sitemap.xml`);
if (blogSitemapRes.ok) {
const blogSitemap = await blogSitemapRes.text();
const blogUrls = blogSitemap.match(/<url>[\s\S]*?<\/url>/g) || [];
urls.push(...blogUrls);
}
} catch (error) {
console.error('Error fetching blog sitemap:', error);
}
}

return new Response(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
${urls.join("")}
</urlset>`,
{ headers: { "Content-Type": "application/xml" } },
);
}