Skip to content

Commit

Permalink
robots.txt file and sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
mrswastik-robot committed Mar 22, 2024
1 parent bfeb7a3 commit c12ba7c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/[postTitle]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ export async function generateMetadata({ params }: Props) : Promise<Metadata> {
const postTitleWithSpaces = decodeURIComponent(params.postTitle as string).split("-").join(" ");
const { post }= await fetchPost(postTitleWithSpaces);
const metadata: Metadata = {
title: post[0].title,
description: post[0].description,
keywords: post[0].keywords,
title: post[0]?.title,
description: post[0]?.description,
keywords: post[0]?.keywords,
// answerKeywords: post[0].answerKeywords
openGraph: {
title: post[0]?.title,
description: post[0]?.description,
type: "website",
locale: "en_US",
url: "https://devotional-b.vercel.app",
},
};
return metadata;

Expand Down
15 changes: 15 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "Devotional-B",
description: "Get all your answers here.",
openGraph: {
title: "Devotional-B",
description: "Get all your answers here.",
type: "website",
locale: "en_US",
url: "https://devotional-b.vercel.app",
// images: [
// {
// url: "https://devotional-b.vercel.app/og.png",
// width: 1200,
// height: 630,
// alt: "Devotional-B",
// },
// ],
},
};

export default function RootLayout({
Expand Down
5 changes: 5 additions & 0 deletions app/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
User-Agent: *
Allow: /
Disallow: /private/

Sitemap: https://devotional-b.vercel.app/sitemap.xml
49 changes: 49 additions & 0 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@


import { MetadataRoute } from "next";

import { collection , query , getDocs } from "firebase/firestore";
import { db } from "@/utils/firebase";

type Post = {
title: string;
}

//Fetch all posts from firestore
export async function getPosts(){
const postsRef = collection(db, "questions");
const q = query(postsRef);

const posts = <any>[];
const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
posts.push(doc.data() as Post);
});

return posts;
}


export default async function sitemap(){

const baseUrl = "https://devotional-b.vercel.app";

const posts = await getPosts();

const postsUrls = posts?.map((post:any) => {
return{
url: `${baseUrl}/${post.title.split(" ").join("-")}`,
lastModified: new Date().toISOString(),
}
}) ?? [];

return[
{
url: baseUrl,
lastModified: new Date().toISOString(),
},
...postsUrls

]

}

0 comments on commit c12ba7c

Please sign in to comment.