-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generate-sitemap script to package.json
- Loading branch information
1 parent
57b4950
commit febadc6
Showing
4 changed files
with
87 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const globby = require('globby'); // Make sure to install globby first | ||
|
||
(async () => { | ||
// Paths under the pages directory that should be in the sitemap | ||
const pages = await globby([ | ||
'pages/*.js', // All JS files in the pages directory | ||
'!pages/_*.js', // Exclude Next.js special files | ||
'!pages/api', // Exclude API routes | ||
]); | ||
|
||
// Path to the posts directory containing Markdown files | ||
const posts = await globby('posts/**/*.md'); | ||
|
||
// Combine and convert both lists to URL paths | ||
const sitemapUrls = [...pages, ...posts].map((file) => { | ||
const filePath = file | ||
.replace('pages', '') | ||
.replace('posts', '/posts') | ||
.replace(/\.js$/, '') | ||
.replace(/\.md$/, '') | ||
.replace(/index$/, ''); // Remove index to avoid duplicate home page entry | ||
return `https://glamaura.me${filePath}`; | ||
}); | ||
|
||
// Create the sitemap.xml content | ||
const sitemapContent = `<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
${sitemapUrls | ||
.map( | ||
(url) => ` | ||
<url> | ||
<loc>${url}</loc> | ||
</url>` | ||
) | ||
.join('')} | ||
</urlset>`; | ||
|
||
// Write the sitemap.xml to the public directory | ||
fs.writeFileSync(path.join(__dirname, 'public', 'sitemap.xml'), sitemapContent); | ||
})(); |
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,3 @@ | ||
User-agent: * | ||
Allow: / | ||
Sitemap: https://glamaura.me/sitemap.xml |
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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
|
||
<url> | ||
<loc>https://glamaura.me/posts/10-most-essential-pet-accessories-that-every-new-cat-owner-needs</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/achieve-flawless-skin</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/best-anti-aging-skincare-products-of-2024</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/dress-to-impress-womens-apparel-guide-for-formal-places-in-2024</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/flutter-the-good-the-bad-and-the-ugly</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/guide-to-hair-type</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/mixing-patterns-cloth</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/the-ultimate-guide-to-hydrating-your-skin</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/top-5-must-have-pet-accessories-for-your-furry-friend</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/top-picks-for-every-type-of-boyfriend</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/top-womens-perfumes-of-2024-your-ultimate-buying-guide</loc> | ||
</url> | ||
<url> | ||
<loc>https://glamaura.me/posts/your-everyday-step-by-step-skincare-guide</loc> | ||
</url> | ||
</urlset> |