Skip to content

Commit

Permalink
add sitemap to robots
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzabuzaid committed Nov 19, 2023
1 parent 4cba72b commit 89db5c3
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 10 deletions.
6 changes: 6 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mdx from "@astrojs/mdx";
import partytown from "@astrojs/partytown";
import prefetch from "@astrojs/prefetch";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
Expand All @@ -24,6 +25,11 @@ export default defineConfig({
}),
react(),
sitemap(),
partytown({
config: {
debug: true,
},
}),
],
markdown: {
rehypePlugins: [
Expand Down
45 changes: 38 additions & 7 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@astrojs/mdx": "^1.0.0",
"@astrojs/partytown": "^2.0.2",
"@astrojs/prefetch": "^0.4.0",
"@astrojs/rss": "^3.0.0",
"@astrolib/seo": "^0.6.0",
Expand Down Expand Up @@ -45,6 +46,7 @@
"remark-inline-links": "^7.0.0",
"remark-toc": "^8.0.1",
"satori": "^0.10.3",
"schema-dts": "^1.1.2",
"shiki": "^0.14.5",
"sidebarjs": "^10.0.0",
"tailwind": "^4.0.0",
Expand Down
5 changes: 4 additions & 1 deletion public/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ Disallow: /nogooglebot/
User-agent: *
Allow: /
Disallow: /tags/
Disallow: /recipes/
Disallow: /recipes/


Sitemap: https://writer.sh/sitemap-index.xml
14 changes: 14 additions & 0 deletions src/assets/authors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ezzabuzaid": {
"mainUrl": "https://twitter.com/ezzabuzaid",
"additionalUrls": [
"https://www.twitch.tv/ezzabuzaid",
"https://www.youtube.com/@ezzabuzaid",
"https://linkedin.com/in/ezzabuzaid",
"https://github.com/ezzabuzaid"
],
"description": "Computer Engineer by specialization, Software Engineer by profession, and an Engineer at heart.",
"email": "ezzabuzaid@hotmail.com",
"jobTitle": "Software Engineer"
}
}
2 changes: 1 addition & 1 deletion src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const activeNav = Astro.url.pathname.split("/")[1];
</a>
<a
target="_blank"
href="https://feeds.feedburner.com/writersh"
href="./rss.xml"
aria-label="rss feed"
title="RSS Feed"
>
Expand Down
4 changes: 4 additions & 0 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface Props {
section?: string;
tags?: string[];
};
schema?: string;
}
const {
article = {},
Expand All @@ -29,6 +30,7 @@ const {
author = SITE.author,
description = SITE.desc,
ogImage = SITE.ogImage,
schema,
canonicalURL = new URL(Astro.url.pathname, Astro.site).href,
} = Astro.props;
Expand Down Expand Up @@ -65,12 +67,14 @@ const socialImageURL = new URL(ogImage, Astro.url.origin).href;
<!-- Fathom - beautiful, simple website analytics -->
<script
src="https://cdn.usefathom.com/script.js"
is:inline
data-honor-dnt="true"
data-site="PBWPAFRL"
defer></script>
<!-- / Fathom -->

<!-- Twitter -->
{schema && <script type="application/ld+json" set:html={schema} />}

<AstroSeo
title={pageTitle || title}
Expand Down
19 changes: 18 additions & 1 deletion src/layouts/PostDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import slugify, { slugifyStr } from "@utils/slugify";
import type { CollectionEntry } from "astro:content";
import Chat from "./ask/Chat.tsx";
import { splitWords } from "./ask/split-words";
import { articleSchema } from "../utils/structured-data";
export interface Props {
post: CollectionEntry<"blog">;
Expand All @@ -24,17 +25,34 @@ const {
tags,
minutesRead,
} = post.data;
import authors from "../assets/authors.json";
const id = slugify(post);
const { Content } = await post.render();
const ogUrl = new URL(ogImage ? ogImage : `${title}.png`, Astro.url.origin)
.href;
const devMode = import.meta.env.DEV;
const schema = JSON.stringify(
articleSchema({
articleType: "BlogPosting",
audience: {
description: "Developers",
type: "Developers",
},
// @ts-ignore
author: authors[author],
datePublished: post.data.pubDatetime.toISOString(),
title,
description,
url: Astro.url.href,
})
);
---

{devMode && <Chat client:only post={slugify(post)} />}

<Layout
schema={schema}
title={title}
author={author}
description={description}
Expand Down Expand Up @@ -322,4 +340,3 @@ const devMode = import.meta.env.DEV;
})();
</script>
</Layout>
./ask/Chat.tsx
48 changes: 48 additions & 0 deletions src/utils/structured-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as dts from "schema-dts";

interface ArticleSchemaOptions {
articleType: "TechArticle" | "BlogPosting";
url: string;
title: string;
description: string;
datePublished: string;
dateModified?: string;
author: {
email?: string;
name?: string;
mainUrl?: string;
jobTitle?: string;
description?: string;
additionalUrls?: string[];
};
audience: {
type: string;
description: string;
};
}

export const articleSchema: (
options: ArticleSchemaOptions
) => dts.TechArticle = options => ({
"@type": "TechArticle",
url: options.url,
headline: options.title,
description: options.description,
datePublished: options.datePublished,
dateModified: options.dateModified,
audience: {
"@type": "Audience",
audienceType: options.audience.type,
audienceDescription: options.audience.description,
},
isAccessibleForFree: true,
author: {
"@type": "Person",
name: options.author.name,
email: options.author.email,
url: options.author.mainUrl,
jobTitle: options.author.jobTitle,
sameAs: options.author.additionalUrls,
description: options.author.description,
},
});

0 comments on commit 89db5c3

Please sign in to comment.