Skip to content

Commit

Permalink
feature/issue 1232 static sitemap (#1240)
Browse files Browse the repository at this point in the history
* #1232 - Adding default static sitemap plugin

* 1232 - Adding meta files documentation

* update meta files docs and usage examples

---------

Co-authored-by: Owen Buckley <owenbuckley13@gmail.com>
  • Loading branch information
jstockdi and thescientist13 authored Jun 22, 2024
1 parent 294a02e commit 957a780
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 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>
4 changes: 2 additions & 2 deletions www/pages/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -282,4 +282,4 @@ export default {
};
```

> Please note the trailing `/` here as for ESM, a path must end in a `/` for directories.
> Please note the trailing `/` here as for ESM, as paths must end in a `/` for directories.
22 changes: 21 additions & 1 deletion www/pages/docs/css-and-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,24 @@ customElements.define('x-header', HeaderComponent);
> }
>
> customElements.define('x-header', HeaderComponent);
> ```
> ```
### 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/).

0 comments on commit 957a780

Please sign in to comment.