From b14c4c50cfd8bf1a4597245dc4d63c96f89be5e5 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 6 Sep 2021 08:29:14 +0200 Subject: [PATCH] Added sitemap building --- docs/content/changelog/CHANGELOG.md | 4 ++ docs/package.json | 7 +-- docs/scripts/generate-sitemap.js | 66 +++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 docs/scripts/generate-sitemap.js diff --git a/docs/content/changelog/CHANGELOG.md b/docs/content/changelog/CHANGELOG.md index e24f4be7..ce8453f8 100644 --- a/docs/content/changelog/CHANGELOG.md +++ b/docs/content/changelog/CHANGELOG.md @@ -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 diff --git a/docs/package.json b/docs/package.json index 6df57cae..9fb11a26 100644 --- a/docs/package.json +++ b/docs/package.json @@ -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", diff --git a/docs/scripts/generate-sitemap.js b/docs/scripts/generate-sitemap.js new file mode 100644 index 00000000..a1a8f338 --- /dev/null +++ b/docs/scripts/generate-sitemap.js @@ -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 = ` + + + + ${baseUrl} + ${new Date().toISOString()} + daily + 1.0 + + ${pages + .map((page) => { + return ` + + ${`${page.slug}`} + ${page.lastModified} + monthly + 1.0 + + `; + }) + .join('')} + + `; + + fs.writeFileSync('public/sitemap.xml', sitemap); + })(); \ No newline at end of file