-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e1e948
commit b3be66b
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import fs from "fs"; | ||
|
||
const Sitemap = () => {}; | ||
|
||
export const getServerSideProps = async function ({ res }) { | ||
const dataRes = await fetch( | ||
"https://justicehub.in/api/3/action/package_search?fq=groups:budgets-for-justice&rows=200" | ||
).then((re) => re.json()); | ||
const allData = dataRes.result.results; | ||
|
||
const staticPages = fs | ||
.readdirSync("pages") | ||
.filter((staticPage) => { | ||
return ![ | ||
"_app.tsx", | ||
"_document.tsx", | ||
"_error.tsx", | ||
"sitemap.xml.js", | ||
"explore", | ||
"index.tsx", | ||
].includes(staticPage); | ||
}) | ||
.map((staticPagePath) => { | ||
return `https://budgets.justicehub.in/${staticPagePath}`; | ||
}); | ||
|
||
allData.forEach((scheme) => | ||
staticPages.push(`https://budgets.justicehub.in/datasets/${scheme.name}`) | ||
); | ||
staticPages.unshift(`https://budgets.justicehub.in/`); | ||
|
||
const sitemap = `<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
${staticPages | ||
.map((url) => { | ||
return ` | ||
<url> | ||
<loc>${url}</loc> | ||
<lastmod>${new Date().toISOString()}</lastmod> | ||
<changefreq>monthly</changefreq> | ||
<priority>1.0</priority> | ||
</url> | ||
`; | ||
}) | ||
.join("")} | ||
</urlset> | ||
`; | ||
|
||
res.setHeader("Content-Type", "text/xml"); | ||
res.write(sitemap); | ||
res.end(); | ||
|
||
return { | ||
props: {}, | ||
}; | ||
}; | ||
|
||
export default Sitemap; |