Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/issue 1232 static sitemap #1240

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/).
Loading