mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-06 08:52:47 +02:00
Added sitemap building
This commit is contained in:
@@ -2,8 +2,12 @@
|
||||
|
||||
## [3.1.0] - (Upcoming release)
|
||||
|
||||
- [#73](https://github.com/estruyf/vscode-front-matter/issues/73): List view option for the dashboard
|
||||
- [#77](https://github.com/estruyf/vscode-front-matter/issues/77): Dashboard grouping pages functionality integrated
|
||||
- [#81](https://github.com/estruyf/vscode-front-matter/issues/81): Optimizing the content folders to use a new setting to simplify configuration
|
||||
- [#87](https://github.com/estruyf/vscode-front-matter/issues/87): Fix issue with autofocus and command palette
|
||||
- [#88](https://github.com/estruyf/vscode-front-matter/issues/88): Fix issue with search sorting
|
||||
- [#90](https://github.com/estruyf/vscode-front-matter/issues/90): Refactoring to use Recoil state management
|
||||
|
||||
## [3.0.2] - 2021-08-31
|
||||
|
||||
|
||||
+4
-3
@@ -3,11 +3,12 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"changelog": "node scripts/copy-changelog.js",
|
||||
"dev": "npm run changelog && next dev",
|
||||
"build": "npm run changelog && next build",
|
||||
"build": "npm run changelog && npm run sitemap && next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
"lint": "next lint",
|
||||
"changelog": "node scripts/copy-changelog.js",
|
||||
"sitemap": "node scripts/generate-sitemap.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docsearch/js": "^3.0.0-alpha.40",
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const matter = require('gray-matter');
|
||||
|
||||
(async () => {
|
||||
const baseUrl = `https://frontmatter.codes`;
|
||||
|
||||
// Ignore Next.js specific files (e.g., _app.js) and API routes.
|
||||
let pages = fs
|
||||
.readdirSync(path.join(__dirname, '../pages'))
|
||||
.filter((staticPage) => {
|
||||
return ![
|
||||
"_app.tsx",
|
||||
"_document.tsx",
|
||||
"_error.tsx",
|
||||
"sitemap.xml.tsx",
|
||||
"index.tsx",
|
||||
"404",
|
||||
"api"
|
||||
].includes(staticPage);
|
||||
})
|
||||
.map((staticPagePath) => ({
|
||||
lastModified: new Date().toISOString(),
|
||||
slug: `${baseUrl}/${staticPagePath}`
|
||||
}));
|
||||
|
||||
const mdDir = path.join(process.cwd(), 'content');
|
||||
const mdFiles = fs.readdirSync(path.join(mdDir, 'docs')).filter(f => f.endsWith(`.md`));
|
||||
const mdPages = mdFiles.map((fileName) => {
|
||||
const fullPath = path.join(mdDir, 'docs', `${fileName}`)
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||
const { data } = matter(fileContents);
|
||||
return {
|
||||
lastModified: data["lastmod"] || new Date().toISOString(),
|
||||
slug: `${baseUrl}/docs/${data['slug'] || fileName.split('.').slice(0, -1).join('.')}`
|
||||
};
|
||||
});
|
||||
|
||||
pages = [...pages, ...mdPages];
|
||||
|
||||
const sitemap = `
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>${baseUrl}</loc>
|
||||
<lastmod>${new Date().toISOString()}</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>
|
||||
${pages
|
||||
.map((page) => {
|
||||
return `
|
||||
<url>
|
||||
<loc>${`${page.slug}`}</loc>
|
||||
<lastmod>${page.lastModified}</lastmod>
|
||||
<changefreq>monthly</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>
|
||||
`;
|
||||
})
|
||||
.join('')}
|
||||
</urlset>
|
||||
`;
|
||||
|
||||
fs.writeFileSync('public/sitemap.xml', sitemap);
|
||||
})();
|
||||
Reference in New Issue
Block a user