Skip to content

Commit

Permalink
ProjectEvergreen#1232 - Adding default static sitemap plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jstockdi committed Jun 5, 2024
1 parent 44f8e6e commit 37cec2e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/cli/src/plugins/copy/plugin-copy-sitemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { checkResourceExists } from '../../lib/resource-utils.js';

const greenwoodPluginCopySitemap = [{
type: 'copy',
name: 'plugin-copy-sitemap',
provider: async (compilation) => {
const fileName = 'sitemap.xml';
const { outputDir, userWorkspace } = compilation.context;
const sitemapPathUrl = new URL(`./${fileName}`, userWorkspace);
const assets = [];

if (await checkResourceExists(sitemapPathUrl)) {
assets.push({
from: sitemapPathUrl,
to: new URL(`./${fileName}`, outputDir)
});
}

return assets;
}
}];

export { greenwoodPluginCopySitemap };
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ describe('Build Greenwood With: ', function() {
expect(robots.length).to.equal(1);
});
});

describe('Default output for project level sitemap.xml', function() {
let sitemaps;

before(async function() {
sitemaps = await glob(`${this.context.publicDir}/sitemap.xml`);
});

it('should have one sitemap.xml file in the output directory', function() {
expect(sitemaps.length).to.equal(1);
});
});
});

after(function() {
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/test/cases/build.default.meta-files/src/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.example.com/</loc>
<lastmod>2024-06-04T00:00:00Z</lastmod>
<priority>1.0</priority>
</url>

<url>
<loc>https://www.example.com/about/</loc>
<lastmod>2023-12-15T16:20:00Z</lastmod>
<priority>0.8</priority>
</url>

<url>
<loc>https://www.example.com/contact/</loc>

<priority>0.5</priority>
</url>
</urlset>

0 comments on commit 37cec2e

Please sign in to comment.