Skip to content

Commit

Permalink
update lastmod support to handle set only date by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeceM committed Jun 29, 2021
1 parent 75f0fd2 commit 2302927
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ module.exports = withPrismicSitemap({
})
```

### `<lastmod>` support

The package makes use of lastmod support for the sitemap, this would need to be set by the user if you would want the date to come through at the current version of `0.3.0`.

Because the Sitemap file is written using a separate package, it supports parsing the date straight to the `YYYY-MM-DD` format, if you would like it to have the time as well, you will need to override the setting in the config:

```javascript
sitemap: {

sitemapConfig: {
lastmodDateOnly: false,
},

}
```

## API

The sitemap object is made up of the following:
Expand Down
12 changes: 11 additions & 1 deletion generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const generator = async (sitemap) => {
documentTypes = ['*'],
fileName = 'sitemap.xml',
publicPath = 'public',
sitemapConfig,
sitemapConfig = {
lastmodDateOnly: true,
},
defaultEntryOption = { changefreq: "monthly", priority: 1, },
staticPaths = [],
/** optional things */
Expand Down Expand Up @@ -124,6 +126,14 @@ function resolveDocumentOption(option, document) {
}
}

/**
* Adds the static path to the index
*
* @todo Make use of a async callback or handle the object depending on what happens
* @param {Object} option the static path to add
* @param {SitemapStream} stream
* @returns void
*/
function storeIfValid(option, stream) {
if (option.url === undefined) {
return;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reecem/prismic-sitemap",
"version": "0.3.0-alpha.1",
"version": "0.3.0-alpha.2",
"description": "Sitemap Generator for Prismic and Next.js",
"keywords": [
"javascript",
Expand Down Expand Up @@ -30,7 +30,7 @@
"test": "TEST_REPOSITORY=https://hbar.cdn.prismic.io/api/v2 jest"
},
"engines": {
"node": "^12.0"
"node": ">=12.0"
},
"author": "@ReeceM",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/buffer-example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Using Sitemap Generator visiting page loads sitemap.xml 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:news=\\"http://www.google.com/schemas/sitemap-news/0.9\\" xmlns:xhtml=\\"http://www.w3.org/1999/xhtml\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\" xmlns:video=\\"http://www.google.com/schemas/sitemap-video/1.1\\"><url><loc>https://example.com/notice/sldkfmlksdmfs</loc><lastmod>2020-07-16T13:05:08.000Z</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/page/more-pages-here</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app2</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-a-lot-i-dont-got</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-page-of-cabbages</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page21</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-page-of-cabbages1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page2</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/customer-reviews-page-example</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot11</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/another-page-here</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-is-the-time</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-is-the-time1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/blog/a-demo-blog-post</loc><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/blog/demo-post</loc><changefreq>weekly</changefreq><priority>0.8</priority></url></urlset>"`;
exports[`Using Sitemap Generator visiting page loads sitemap.xml 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:news=\\"http://www.google.com/schemas/sitemap-news/0.9\\" xmlns:xhtml=\\"http://www.w3.org/1999/xhtml\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\" xmlns:video=\\"http://www.google.com/schemas/sitemap-video/1.1\\"><url><loc>https://example.com/notice/sldkfmlksdmfs</loc><lastmod>2020-07-16</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/page/more-pages-here</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app2</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-a-lot-i-dont-got</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-page-of-cabbages</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page21</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-page-of-cabbages1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page2</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/customer-reviews-page-example</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot11</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/another-page-here</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-is-the-time</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-is-the-time1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/blog/a-demo-blog-post</loc><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/blog/demo-post</loc><changefreq>weekly</changefreq><priority>0.8</priority></url></urlset>"`;

0 comments on commit 2302927

Please sign in to comment.