mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-17 14:30:34 +08:00
feat(website): Generate sitemap.
This commit is contained in:
parent
cf7a4e2c40
commit
8e105fd053
@ -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:
|
||||
@ -35,4 +41,6 @@ connections:
|
||||
read: false
|
||||
write: true
|
||||
pages:
|
||||
- _ref: pages/home/home.yaml
|
||||
_ref:
|
||||
path: pages.yaml
|
||||
transformer: src/generateSitemap.js
|
||||
|
1
packages/website/pages.yaml
Normal file
1
packages/website/pages.yaml
Normal file
@ -0,0 +1 @@
|
||||
- _ref: pages/home/home.yaml
|
48
packages/website/src/generateSitemap.js
Normal file
48
packages/website/src/generateSitemap.js
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user