Skip to content

Commit

Permalink
feat(website): Generate sitemap.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gervwyk committed Jul 19, 2023
1 parent cf7a4e2 commit 8e105fd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/website/lowdefy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ plugins:
- name: '@lowdefy/website'
version: 'workspace:*'
connections:
- id: discord
type: AxiosHttp
properties:
method: post
url:
_secret: DISCORD_WEBHOOK
- id: newsletter
type: MongoDBCollection
properties:
Expand All @@ -35,4 +41,6 @@ connections:
read: false
write: true
pages:
- _ref: pages/home/home.yaml
_ref:
path: pages.yaml
transformer: src/generateSitemap.js
1 change: 1 addition & 0 deletions packages/website/pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- _ref: pages/home/home.yaml
48 changes: 48 additions & 0 deletions packages/website/src/generateSitemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2020-2023 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import fs from 'fs';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';

function transformer(pages) {
const sitemapStart = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
`;
const sitemapEnd = `
</urlset>`;
const now = new Date();
const addPage = (acc, page) => {
return acc.concat(`
<url>
<loc>https://docs.lowdefy.com/${page.id}</loc>
<lastmod>${now.getFullYear()}-${now.getMonth() > 8 ? '' : 0}${now.getMonth() + 1}-${
now.getDate() > 9 ? '' : 0
}${now.getDate()}</lastmod>
</url>
`);
};

const sitemap = pages.reduce(addPage, sitemapStart).concat(sitemapEnd);

fs.writeFileSync(
path.join(dirname(fileURLToPath(import.meta.url)), '../public/sitemap.xml'),
sitemap
);

return pages;
}
export default transformer;

0 comments on commit 8e105fd

Please sign in to comment.