Bird
Raised Fist0
Astroframework~20 mins

RSS feed generation in Astro - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
RSS Feed Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this Astro RSS feed generation snippet?
Given this Astro component code snippet that generates an RSS feed, what will be the content of the generated RSS XML string?
Astro
import rss from '@astrojs/rss';

export const get = () => {
  return rss({
    title: 'My Blog',
    description: 'Latest posts',
    site: 'https://example.com',
    items: [
      { title: 'Post 1', pubDate: new Date('2024-01-01'), link: '/post-1' },
      { title: 'Post 2', pubDate: new Date('2024-01-02'), link: '/post-2' }
    ]
  });
};
ASyntaxError: Unexpected token 'export' in line 1
BTypeError: rss is not a function
C<?xml version="1.0" encoding="UTF-8"?>\n<rss version="2.0">\n<channel>\n<title>My Blog</title>\n<description>Latest posts</description>\n<link>https://example.com</link>\n<item>\n<title>Post 2</title>\n<link>https://example.com/post-2</link>\n<pubDate>Tue, 02 Jan 2024 00:00:00 GMT</pubDate>\n</item>\n</channel>\n</rss>
D<?xml version="1.0" encoding="UTF-8"?>\n<rss version="2.0">\n<channel>\n<title>My Blog</title>\n<description>Latest posts</description>\n<link>https://example.com</link>\n<item>\n<title>Post 1</title>\n<link>https://example.com/post-1</link>\n<pubDate>Mon, 01 Jan 2024 00:00:00 GMT</pubDate>\n</item>\n<item>\n<title>Post 2</title>\n<link>https://example.com/post-2</link>\n<pubDate>Tue, 02 Jan 2024 00:00:00 GMT</pubDate>\n</item>\n</channel>\n</rss>
Attempts:
2 left
💡 Hint
Look at how the rss function formats the items array into XML items with full links.
📝 Syntax
intermediate
1:30remaining
Which option will cause a syntax error in Astro RSS feed code?
Identify which code snippet will cause a syntax error when generating an RSS feed in Astro.
Aexport const get = () => rss({ title: 'Blog', site: 'https://site.com', items: [] });
Bexport const get = () => { return rss({ title: 'Blog', site: 'https://site.com', items: [] }); }
Cexport const get = () => rss({ title: 'Blog', site: 'https://site.com', items: [] ) };
D} ;)} ][ :smeti ,'moc.etis//:sptth' :etis ,'golB' :eltit {(ssr nruter { >= )( = teg tsnoc tropxe
Attempts:
2 left
💡 Hint
Check the parentheses and braces carefully.
❓ state_output
advanced
2:00remaining
What is the value of the 'link' field in the RSS item after running this Astro code?
Given this Astro RSS feed generation code, what is the full URL value of the 'link' field in the first item?
Astro
import rss from '@astrojs/rss';

const site = 'https://mysite.dev';
const posts = [
  { title: 'Hello', slug: 'hello-world', date: '2024-05-01' }
];

export const get = () => rss({
  title: 'MySite',
  site,
  items: posts.map(post => ({
    title: post.title,
    pubDate: new Date(post.date),
    link: `/${post.slug}`
  }))
});
Ahttps://mysite.dev
Bhttps://mysite.dev/hello-world
Chello-world
D/hello-world
Attempts:
2 left
💡 Hint
The rss function combines the site URL with the relative link automatically.
🔧 Debug
advanced
2:30remaining
Why does this Astro RSS feed code throw 'TypeError: rss is not a function'?
Examine the code and select the reason for the error 'TypeError: rss is not a function'.
Astro
import { rss } from '@astrojs/rss';

export const get = () => {
  return rss({
    title: 'Blog',
    site: 'https://blog.com',
    items: []
  });
};
AThe import statement is incorrect; rss is the default export, not a named export.
BThe rss function requires an async wrapper which is missing.
CThe items array cannot be empty and causes the error.
DThe get function must be named generateRSS instead.
Attempts:
2 left
💡 Hint
Check how rss is imported from the package.
🧠 Conceptual
expert
3:00remaining
Which option best describes how Astro's RSS feed generation handles date formatting?
Astro's '@astrojs/rss' package requires dates in the items array. How does it handle the date formatting internally for the RSS feed?
AIt converts JavaScript Date objects to RFC 822 formatted strings automatically for pubDate fields.
BIt requires dates to be preformatted as ISO 8601 strings before passing to rss().
CIt stores dates as Unix timestamps in the RSS XML output.
DIt ignores the date field and does not include pubDate in the RSS feed.
Attempts:
2 left
💡 Hint
Think about the standard date format used in RSS feeds.

Practice

(1/5)
1. What is the main purpose of generating an RSS feed in an Astro project?
easy
A. To automatically share website updates with subscribers
B. To improve website loading speed
C. To add interactive animations to the site
D. To create user login functionality

Solution

  1. Step 1: Understand RSS feed purpose

    RSS feeds are designed to share updates automatically with users or apps.
  2. Step 2: Match purpose with options

    Only To automatically share website updates with subscribers describes sharing updates automatically, which is the core use of RSS.
  3. Final Answer:

    To automatically share website updates with subscribers -> Option A
  4. Quick Check:

    RSS feeds share updates = A [OK]
Hint: RSS feeds share updates automatically, not speed or animations [OK]
Common Mistakes:
  • Confusing RSS with website speed optimization
  • Thinking RSS adds animations or login features
  • Assuming RSS is for styling or layout
2. Which import statement correctly brings in the RSS helper from Astro's RSS package?
easy
A. import { rss } from '@astrojs/rss';
B. import rss from 'astro/rss';
C. import { createRSS } from '@astrojs/rss';
D. import rssHelper from '@astro/rss';

Solution

  1. Step 1: Recall correct package and syntax

    The official package is '@astrojs/rss' and the helper is named 'rss'.
  2. Step 2: Match correct import syntax

    import { rss } from '@astrojs/rss'; uses correct named import from the correct package name.
  3. Final Answer:

    import { rss } from '@astrojs/rss'; -> Option A
  4. Quick Check:

    Correct package and named import = C [OK]
Hint: Use named import from '@astrojs/rss' exactly [OK]
Common Mistakes:
  • Using default import instead of named import
  • Wrong package name like 'astro/rss'
  • Incorrect helper function name
3. Given this Astro RSS feed code snippet, what will be the value of the first item's link?
const posts = [
  { title: 'Hello', date: '2024-01-01', description: 'Intro post', slug: 'hello' }
];

export const get = () => rss({
  title: 'My Blog',
  site: 'https://example.com',
  items: posts.map(post => ({
    title: post.title,
    pubDate: new Date(post.date),
    description: post.description,
    link: `/posts/${post.slug}`
  }))
});
medium
A. https://example.com/posts/hello
B. /hello
C. https://example.com/hello
D. /posts/hello

Solution

  1. Step 1: Analyze link construction in map

    The link is created as `/posts/${post.slug}`, which results in '/posts/hello'.
  2. Step 2: Understand site prefix usage

    The 'site' URL is not concatenated in the link property, so link remains relative.
  3. Final Answer:

    /posts/hello -> Option D
  4. Quick Check:

    Link uses relative path '/posts/hello' = B [OK]
Hint: Check if site URL is prepended; here it is not [OK]
Common Mistakes:
  • Assuming link includes full site URL
  • Confusing slug placement in URL
  • Ignoring template literal syntax
4. Identify the error in this Astro RSS feed generation code:
import { rss } from '@astrojs/rss';

const posts = [
  { title: 'Post 1', date: '2024-02-01', description: 'Desc', slug: 'post-1' }
];

export const get = () => rss({
  title: 'Blog',
  site: 'https://blog.com',
  items: posts.map(post => ({
    title: post.title,
    pubDate: post.date,
    description: post.description,
    link: `/blog/${post.slug}`
  }))
});
medium
A. The items array should be empty
B. Missing import statement for rss
C. pubDate should be a Date object, not a string
D. The link property must be an absolute URL

Solution

  1. Step 1: Check pubDate type requirement

    The rss helper expects pubDate as a Date object, but here it's a string.
  2. Step 2: Verify other code parts

    Import is correct, items array is valid, and link can be relative, so no other errors.
  3. Final Answer:

    pubDate should be a Date object, not a string -> Option C
  4. Quick Check:

    pubDate must be Date object = A [OK]
Hint: Convert date strings to Date objects for pubDate [OK]
Common Mistakes:
  • Leaving pubDate as string causes feed errors
  • Thinking link must be absolute URL
  • Forgetting to import rss helper
5. You want to generate an RSS feed in Astro that only includes posts published after January 1, 2024. Which code snippet correctly filters the posts before generating the feed?
const posts = [
  { title: 'Old Post', date: '2023-12-31', slug: 'old' },
  { title: 'New Post', date: '2024-01-02', slug: 'new' }
];

export const get = () => rss({
  title: 'Filtered Blog',
  site: 'https://filtered.com',
  items: posts
    .filter(post => ??? )
    .map(post => ({
      title: post.title,
      pubDate: new Date(post.date),
      link: `/posts/${post.slug}`
    }))
});
What should replace ??? to filter correctly?
hard
A. new Date(post.date) > new Date('2024-01-03')
B. new Date(post.date) >= new Date('2024-01-02')
C. post.date >= '2024-01-03'
D. post.date > '2024-01-03'

Solution

  1. Step 1: Understand date filtering logic

    We want posts published after January 1, 2024, so dates on or after 2024-01-02.
  2. Step 2: Compare dates as Date objects

    Comparing strings can be unreliable; converting to Date objects ensures correct comparison.
  3. Step 3: Choose correct comparison operator

    Using '>=' with new Date('2024-01-02') includes posts from that date onward.
  4. Final Answer:

    new Date(post.date) >= new Date('2024-01-02') -> Option B
  5. Quick Check:

    Date objects with >= for filtering = D [OK]
Hint: Always compare dates as Date objects, not strings [OK]
Common Mistakes:
  • Comparing date strings directly leads to errors
  • Using wrong comparison operator excludes needed posts
  • Filtering with incorrect date boundary
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard