Skip to content

Commit

Permalink
sitemapsh updated
Browse files Browse the repository at this point in the history
  • Loading branch information
SH20RAJ authored Mar 25, 2024
1 parent 766e1a6 commit 6f40bba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function ArticlesPage() {
setIsLoading(true);
try {
const response = await fetch(
`https://dev.to/api/articles/latest/?per_page=22&page=${page}`
`https://dev.to/api/articles/?per_page=22&page=${page}`
);
const data = await response.json();
setArticles((prevArticles) => [...prevArticles, ...data]);
Expand Down
2 changes: 1 addition & 1 deletion src/app/sitemapsh/[id]/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ console.log(randomNumber);
let getArticlesFromDevTo = async (params) => {
console.log("params", params);
const response = await fetch(
`https://dev.to/api/articles/latest/?per_page=100000&page=${
`https://dev.to/api/articles/?per_page=100000&page=${
params || generateRandomNumber(1, 1000).toString()
}`
);
Expand Down
31 changes: 9 additions & 22 deletions src/app/sitemapsh/route.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
import { NextResponse } from "next/server";

// Mock function to fetch articles (replace this with your actual implementation)
let getArticlesFromDevTo = async () => {
const response = await fetch(
`https://dev.to/api/articles/?per_page=100000&page=1`
);
const data = await response.json();
return data;
};

export async function GET(req) {
if (req.method === "GET") {
if (true) {
try {
// Fetch articles from Dev.to or your database
const articles = await getArticlesFromDevTo();

// Start building the XML
let xml = '<?xml version="1.0" encoding="UTF-8"?>';
xml +=
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
xml += '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

for (let i = 0; i < 1000; i++) {
xml += "<sitemap>";
xml += `<loc>https://sh20raj.com/sitemapsh/${Math.floor(Math.random()*10000)}</loc>`; // Modify URL structure as needed
xml += "</sitemap>";

// Add each article URL to the sitemap
articles.forEach((article) => {
xml += "<url>";
xml += `<loc>https://sh20raj.com${article.path}</loc>`; // Modify URL structure as needed
xml += `<lastmod>${new Date(article.published_at).toISOString()}</lastmod>`; // Use published date as last modified
xml += "<changefreq>weekly</changefreq>"; // You can adjust the change frequency
xml += "<priority>0.8</priority>"; // Priority can be adjusted based on the importance of the page
xml += "</url>";
});
}

xml += "</urlset>";
xml += "</sitemapindex>";

// Set the response headers and status
return new NextResponse(xml, {
Expand Down

0 comments on commit 6f40bba

Please sign in to comment.