diff --git a/packages/cli/src/plugins/copy/plugin-copy-sitemap.js b/packages/cli/src/plugins/copy/plugin-copy-sitemap.js new file mode 100644 index 000000000..de756551d --- /dev/null +++ b/packages/cli/src/plugins/copy/plugin-copy-sitemap.js @@ -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 }; \ No newline at end of file diff --git a/packages/cli/test/cases/build.default.meta-files/build.default.meta-files.spec.js b/packages/cli/test/cases/build.default.meta-files/build.default.meta-files.spec.js index a3c52e259..e49106c51 100644 --- a/packages/cli/test/cases/build.default.meta-files/build.default.meta-files.spec.js +++ b/packages/cli/test/cases/build.default.meta-files/build.default.meta-files.spec.js @@ -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() { diff --git a/packages/cli/test/cases/build.default.meta-files/src/sitemap.xml b/packages/cli/test/cases/build.default.meta-files/src/sitemap.xml new file mode 100644 index 000000000..298d2eb63 --- /dev/null +++ b/packages/cli/test/cases/build.default.meta-files/src/sitemap.xml @@ -0,0 +1,20 @@ + + + + https://www.example.com/ + 2024-06-04T00:00:00Z + 1.0 + + + + https://www.example.com/about/ + 2023-12-15T16:20:00Z + 0.8 + + + + https://www.example.com/contact/ + + 0.5 + + \ No newline at end of file diff --git a/www/pages/docs/configuration.md b/www/pages/docs/configuration.md index 9b6ad9133..37cc894a6 100644 --- a/www/pages/docs/configuration.md +++ b/www/pages/docs/configuration.md @@ -270,7 +270,7 @@ export default { ``` ### Workspace -Path to where all your project files will be located. Using an absolute path is recommended. +Path to where all your project files will be located. Using an absolute path is recommended. Default is _src/_. #### Example @@ -282,4 +282,4 @@ export default { }; ``` -> Please note the trailing `/` here as for ESM, a path must end in a `/` for directories. \ No newline at end of file +> Please note the trailing `/` here as for ESM, as paths must end in a `/` for directories. \ No newline at end of file diff --git a/www/pages/docs/css-and-images.md b/www/pages/docs/css-and-images.md index 9895755f2..2043f0009 100644 --- a/www/pages/docs/css-and-images.md +++ b/www/pages/docs/css-and-images.md @@ -109,4 +109,24 @@ customElements.define('x-header', HeaderComponent); > } > > customElements.define('x-header', HeaderComponent); -> ``` \ No newline at end of file +> ``` + + +### Meta Files + +By default, Greenwood will automatically detect these "meta" files from the top-level of your [workspace directory](docs/configuration/#workspace) and automatically copy them over to the root of the build output directory. + +- _favicon.ico_ +- _robots.txt_ +- _sitemap.xml_ + +Example: + +```shell +src/ + favicon.ico + robots.txt + sitemap.xml +``` + +> If you need support for more custom copying of static files like this, please check out our docs on creating your own [copy plugin](plugins/copy/).