diff --git a/generate-sitemap.js b/generate-sitemap.js new file mode 100644 index 0000000..29a823a --- /dev/null +++ b/generate-sitemap.js @@ -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 = ` + + ${sitemapUrls + .map( + (url) => ` + + ${url} + ` + ) + .join('')} +`; + + // Write the sitemap.xml to the public directory + fs.writeFileSync(path.join(__dirname, 'public', 'sitemap.xml'), sitemapContent); +})(); diff --git a/package.json b/package.json index 115ad1b..a6e4e3a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "generate-sitemap": "node generate-sitemap.js" }, "dependencies": { "@datadog/browser-rum": "^5.10.0", diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..d9723fa --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,3 @@ +User-agent: * +Allow: / +Sitemap: https://glamaura.me/sitemap.xml diff --git a/public/sitemap.xml b/public/sitemap.xml new file mode 100644 index 0000000..9f25662 --- /dev/null +++ b/public/sitemap.xml @@ -0,0 +1,40 @@ + + + + + https://glamaura.me/posts/10-most-essential-pet-accessories-that-every-new-cat-owner-needs + + + https://glamaura.me/posts/achieve-flawless-skin + + + https://glamaura.me/posts/best-anti-aging-skincare-products-of-2024 + + + https://glamaura.me/posts/dress-to-impress-womens-apparel-guide-for-formal-places-in-2024 + + + https://glamaura.me/posts/flutter-the-good-the-bad-and-the-ugly + + + https://glamaura.me/posts/guide-to-hair-type + + + https://glamaura.me/posts/mixing-patterns-cloth + + + https://glamaura.me/posts/the-ultimate-guide-to-hydrating-your-skin + + + https://glamaura.me/posts/top-5-must-have-pet-accessories-for-your-furry-friend + + + https://glamaura.me/posts/top-picks-for-every-type-of-boyfriend + + + https://glamaura.me/posts/top-womens-perfumes-of-2024-your-ultimate-buying-guide + + + https://glamaura.me/posts/your-everyday-step-by-step-skincare-guide + + \ No newline at end of file