-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sitemap): use pages to build the sitemap
- Loading branch information
Showing
13 changed files
with
143 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/sitemap': patch | ||
--- | ||
|
||
Correctly emit sitemap when building website in SSG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { loadFixture, readXML } from './test-utils.js'; | ||
import { expect } from 'chai'; | ||
|
||
describe('Content collections support', () => { | ||
/** @type {import('./test-utils.js').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/content/', | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('SSR pages require zero config', async () => { | ||
const data = await readXML(fixture.readFile('/sitemap-0.xml')); | ||
const urls = data.urlset.url; | ||
|
||
expect(urls[0].loc[0]).to.equal('https://example.com/'); | ||
expect(urls[1].loc[0]).to.equal('https://example.com/blog/bar/'); | ||
expect(urls[2].loc[0]).to.equal('https://example.com/blog/foo/'); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/integrations/sitemap/test/fixtures/content/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import mdx from '@astrojs/mdx'; | ||
import sitemap from '@astrojs/sitemap'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
site: 'https://example.com', | ||
integrations: [mdx(), sitemap()], | ||
}); | ||
|
10 changes: 10 additions & 0 deletions
10
packages/integrations/sitemap/test/fixtures/content/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@test/sitemap-ssr", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/sitemap": "workspace:*", | ||
"@astrojs/mdx": "workspace:*" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/integrations/sitemap/test/fixtures/content/src/content/blog/bar.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: "First post" | ||
description: "Lorem ipsum dolor sit amet" | ||
pubDate: "Jul 08 2022" | ||
--- |
5 changes: 5 additions & 0 deletions
5
packages/integrations/sitemap/test/fixtures/content/src/content/blog/foo.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: "Markdown Style Guide" | ||
description: "Here is a sample of some basic Markdown syntax that can be used when writing Markdown content in Astro." | ||
pubDate: "Jul 01 2022" | ||
--- |
20 changes: 20 additions & 0 deletions
20
packages/integrations/sitemap/test/fixtures/content/src/content/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineCollection, z } from 'astro:content'; | ||
|
||
const blog = defineCollection({ | ||
// Type-check frontmatter using a schema | ||
schema: z.object({ | ||
title: z.string(), | ||
description: z.string(), | ||
// Transform string to Date object | ||
pubDate: z | ||
.string() | ||
.or(z.date()) | ||
.transform((val) => new Date(val)), | ||
updatedDate: z | ||
.string() | ||
.optional() | ||
.transform((str) => (str ? new Date(str) : undefined)), | ||
}), | ||
}); | ||
|
||
export const collections = { blog }; |
18 changes: 18 additions & 0 deletions
18
packages/integrations/sitemap/test/fixtures/content/src/pages/blog/[...slug].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
import { CollectionEntry, getCollection } from 'astro:content'; | ||
export async function getStaticPaths() { | ||
const posts = await getCollection('blog'); | ||
return posts.map((post) => ({ | ||
params: { slug: post.slug }, | ||
props: post, | ||
})); | ||
} | ||
type Props = CollectionEntry<'blog'>; | ||
const post = Astro.props; | ||
const { Content } = await post.render(); | ||
--- | ||
|
||
<h1>{post.data.title}</h1> | ||
<Content /> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.