Merge branch 'main' into astro-quicklink

This commit is contained in:
Tony Sullivan 2022-06-27 18:10:24 +00:00 committed by GitHub
commit 714fa3b755
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 8 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/sitemap': patch
---
fix: if `serialize` function returns `undefined` for the passed entry, such entry will be excluded from sitemap

View file

@ -245,8 +245,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup PNPM
uses: pnpm/action-setup@v2.2.1
@ -276,7 +274,9 @@ jobs:
commit: '[ci] release'
title: '[ci] release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Needs access to push to main
GITHUB_TOKEN: ${{ secrets.FREDKBOT_GITHUB_TOKEN }}
# Needs access to publish to npm
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Generate Notification

View file

@ -29,3 +29,5 @@ jobs:
with:
commit_message: '[ci] format'
branch: ${{ github.head_ref }}
# Needs access to push to main
token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }}

View file

@ -29,12 +29,16 @@ jobs:
- name: Collect stats
run: node scripts/stats/index.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Needs access to collect stats from the GitHub API
GITHUB_TOKEN: ${{ secrets.FREDKBOT_GITHUB_TOKEN }}
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: '[ci] collect stats'
branch: ${{ github.head_ref }}
# Needs access to push to main
token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }}
lockfile:
if: github.repository_owner == 'withastro'
@ -61,7 +65,8 @@ jobs:
uses: peter-evans/create-pull-request@v3
with:
branch: ci/lockfile
token: ${{ secrets.NIGHTLY_PERSONAL_GITHUB_TOKEN }}
# Access token is needed to trigger CI on this PR
token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }}
commit-message: '[ci] update lockfile'
title: '[ci] update lockfile'
body: >

View file

@ -222,7 +222,9 @@ The `LinkItem` type has two required fields: `url` (the fully-qualified URL for
The `serialize` function should return `SitemapItem`, touched or not.
The example below shows the ability to add the sitemap specific properties individually.
To exclude the passed entry from sitemap it should return `undefined`.
The example below shows the ability to exclude certain entries and add the sitemap specific properties individually.
__astro.config.mjs__
@ -234,6 +236,9 @@ export default {
integrations: [
sitemap({
serialize(item) {
if (/exclude-from-sitemap/.test(item.url)) {
return undefined;
}
if (/your-special-page/.test(item.url)) {
item.changefreq = 'daily';
item.lastmod = new Date();

View file

@ -38,7 +38,7 @@ export type SitemapOptions =
priority?: number;
// called for each sitemap item just before to save them on disk, sync or async
serialize?(item: SitemapItem): SitemapItem | Promise<SitemapItem>;
serialize?(item: SitemapItem): SitemapItem | Promise<SitemapItem | undefined> | undefined;
}
| undefined;
@ -117,8 +117,14 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
const serializedUrls: SitemapItem[] = [];
for (const item of urlData) {
const serialized = await Promise.resolve(serialize(item));
serializedUrls.push(serialized);
if (serialized) {
serializedUrls.push(serialized);
}
}
if (serializedUrls.length === 0) {
logger.warn('No pages found!');
return;
}
urlData = serializedUrls;
} catch (err) {
logger.error(`Error serializing pages\n${(err as any).toString()}`);