Challenge - 5 Problems
Astro Sitemap Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat is the output of this Astro sitemap generation snippet?
Given this Astro sitemap generation code, what will be the content of the generated sitemap.xml?
Astro
import { Sitemap } from 'astro:sitemap'; export async function get() { return Sitemap({ site: 'https://example.com', filter: (page) => !page.includes('draft'), }); } // Pages: ['index.astro', 'about.astro', 'draft-post.astro']
Attempts:
2 left
💡 Hint
Remember the filter excludes pages containing 'draft'.
✗ Incorrect
The filter function removes any page with 'draft' in its name, so 'draft-post.astro' is excluded from the sitemap.
📝 Syntax
intermediateWhich option causes a syntax error in Astro sitemap generation?
Identify the code snippet that will cause a syntax error when generating a sitemap in Astro.
Astro
import { Sitemap } from 'astro:sitemap'; export async function get() { return Sitemap({ site: 'https://mysite.com', exclude: ['private.astro'], }); }
Attempts:
2 left
💡 Hint
Check the type of the 'exclude' property value.
✗ Incorrect
The 'exclude' property expects an array of strings, not a single string. Option D passes a string, causing a syntax or runtime error.
❓ state_output
advancedWhat is the value of the sitemap URL count after running this Astro code?
Given this sitemap generation code and pages, how many URLs will the sitemap contain?
Astro
import { Sitemap } from 'astro:sitemap'; const pages = ['index.astro', 'blog/post1.astro', 'blog/post2.astro', 'secret.astro']; export async function get() { return Sitemap({ site: 'https://blogsite.com', filter: (page) => !page.includes('secret'), }); }
Attempts:
2 left
💡 Hint
Count pages excluding those with 'secret' in the name.
✗ Incorrect
The filter removes 'secret.astro', so the sitemap includes 3 pages: 'index.astro', 'blog/post1.astro', and 'blog/post2.astro'.
🔧 Debug
advancedWhy does this Astro sitemap generation code fail to include nested pages?
This code generates a sitemap but misses nested pages like 'blog/post1.astro'. What is the likely cause?
Astro
import { Sitemap } from 'astro:sitemap'; export async function get() { return Sitemap({ site: 'https://mysite.com', pages: ['index.astro', 'about.astro'], }); }
Attempts:
2 left
💡 Hint
Check what pages are passed to the sitemap generator.
✗ Incorrect
Only 'index.astro' and 'about.astro' are listed in 'pages', so nested pages like 'blog/post1.astro' are not included.
🧠 Conceptual
expertWhich option best describes how Astro's sitemap generation handles dynamic routes?
Astro supports dynamic routes like '/blog/[slug].astro'. How does the sitemap generation handle these routes by default?
Attempts:
2 left
💡 Hint
Think about how dynamic routes need data to generate URLs.
✗ Incorrect
Astro cannot guess all dynamic URLs automatically; you must supply them manually for the sitemap.
