B. Sitemap function requires an array, not an object
C. Filter function should return a boolean but returns undefined
D. No error; code is correct
Solution
Step 1: Check get function signature
Astro allows get to be sync or async; sync is valid here.
Step 2: Verify Sitemap usage
Sitemap accepts an object with changefreq and filter keys as shown.
Step 3: Confirm filter function returns boolean
page.startsWith('/blog') returns true or false, so filter is valid.
Final Answer:
No error; code is correct -> Option D
Quick Check:
Code syntax and logic are correct = No error; code is correct [OK]
Hint: Check return types and function signatures carefully [OK]
Common Mistakes:
Assuming async is always required for get
Thinking Sitemap needs an array argument
Misunderstanding filter return value
5. You want to generate a sitemap in Astro that excludes pages with empty paths or falsy values and sets changefreq to 'monthly'. Which code snippet correctly achieves this?
hard
A. export const get = () => Sitemap({ filter: page => page, changefreq: 'monthly' });
B. export const get = () => Sitemap({ filter: page => !!page, changefreq: 'monthly' });
C. export const get = () => Sitemap({ filter: page => page === '', changefreq: 'monthly' });
D. export const get = () => Sitemap({ filter: page => page.length > 0, changefreq: 'monthly' });
Solution
Step 1: Understand filtering falsy values
Using !!page converts page to boolean, excluding falsy values like empty strings.
Step 2: Check other options
export const get = () => Sitemap({ filter: page => page, changefreq: 'monthly' }); returns page directly, which may include falsy values; export const get = () => Sitemap({ filter: page => page.length > 0, changefreq: 'monthly' }); assumes page has length property which may cause errors if undefined; export const get = () => Sitemap({ filter: page => page === '', changefreq: 'monthly' }); includes only empty strings, which is opposite of desired filtering; export const get = () => Sitemap({ filter: page => !!page, changefreq: 'monthly' }); correctly filters out falsy values.
Final Answer:
export const get = () => Sitemap({ filter: page => !!page, changefreq: 'monthly' }); -> Option B