Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions modules/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import MarkdownItAnchor from 'markdown-it-anchor'
import { defu } from 'defu'
import { read } from 'gray-matter'
import { array, safeParse } from 'valibot'
import { Feed } from 'feed'
import {
AuthorSchema,
RawBlogPostSchema,
Expand Down Expand Up @@ -159,6 +160,7 @@ export default defineNuxtModule({
const resolver = createResolver(import.meta.url)
const blogDir = resolver.resolve('../app/pages/blog')
const blogImagesDir = resolver.resolve('../public/blog/avatar')
const publicDir = resolver.resolve('../public')
const resolveAvatars = !nuxt.options._prepare

nuxt.options.extensions.push('.md')
Expand Down Expand Up @@ -221,5 +223,52 @@ export default defineNuxtModule({
}
}
}

// Generate content for RSS, Atom and JSON feeds
const feed = new Feed({
title: 'Blog - npmx',
description: 'a fast, modern browser for the npm registry',
id: 'https://npmx.dev/',
link: 'https://npmx.dev/',
language: 'en',
image: 'https://npmx.dev/logo.svg',
favicon: 'https://npmx.dev/favicon.ico',
feedLinks: {
rss: 'https://npmx.dev/rss.xml',
atom: 'https://npmx.dev/atom.xml',
json: 'https://npmx.dev/feed.json',
},
})

allPosts
.filter(post => !post.draft)
.forEach(post => {
feed.addItem({
title: post.title,
id: new URL(post.path, 'https://npmx.dev').toString(),
link: new URL(post.path, 'https://npmx.dev').toString(),
description: post.description,
author: post.authors.map(author => ({
name: author.name,
link: author.profileUrl ?? undefined,
// author.avatar is a relative URL - make it absolute to work in feed readers
avatar: author.avatar
? new URL(author.avatar, 'https://npmx.dev').toString()
: undefined,
})),
date: new Date(post.date),
image: post.image,
})
})

const rssPath = 'rss.xml'
const atomPath = 'atom.xml'
const jsonFeedPath = 'feed.json'

await Promise.all([
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of saving these files to disk, creating pre-rendered server-side routes could be a cleaner approach 🤔. Similar to server/routes/opensearch.xml.get.ts with https://nuxt.com/docs/4.x/getting-started/prerendering#selective-pre-rendering

Copy link
Copy Markdown
Contributor Author

@Kiwow Kiwow Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like exactly what I was looking for and didn't find. Thanks!

I'll add a mention of this to the PR description and look into it when I have time to work on this again.

writeFile(join(publicDir, rssPath), feed.rss2()),
writeFile(join(publicDir, atomPath), feed.atom1()),
writeFile(join(publicDir, jsonFeedPath), feed.json1()),
])
},
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"devalue": "5.6.4",
"eslint-plugin-regexp": "3.1.0",
"fast-check": "4.6.0",
"feed": "5.2.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm the feed package is only used behind prerendered routes and nowhere on a runtime path.
rg -nP "from ['\"]feed['\"]|require\(['\"]feed['\"]\)" --type=ts --type=js --type=vue
echo '---'
# Double-check no non-prerendered route imports getFeed
rg -nP -C2 "getFeed\s*\(" --type=ts

Repository: npmx-dev/npmx.dev

Length of output: 992


🏁 Script executed:

# Check where feed is imported in feeds.ts
cat -n server/utils/feeds.ts | head -20

echo '=== Checking nuxt.config.ts for prerender settings ==='
# Search for prerender configurations for the feed routes
rg -nP "atom\.xml|rss\.xml|feed\.json" nuxt.config.ts

echo '=== Current package.json state for feed ==='
# Check where feed is currently placed in package.json
rg -nP -B2 -A2 '"feed":\s*"5\.2\.0"' package.json

echo '=== Searching for any other getFeed or feed imports ==='
# Broader search for any other getFeed invocations
rg -nP "getFeed" --type=ts

Repository: npmx-dev/npmx.dev

Length of output: 1513


🏁 Script executed:

# View the prerender configuration for the feed routes in nuxt.config.ts
sed -n '193,210p' nuxt.config.ts

Repository: npmx-dev/npmx.dev

Length of output: 693


Move feed from devDependencies to dependencies for runtime safety.

feed is imported in server/utils/feeds.ts and used only by three routes (/rss.xml, /atom.xml, /feed.json), all of which have prerender: true in nuxt.config.ts. While this means the dependency is needed only at build time in a fully prerendered deploy, moving it to dependencies is recommended as a safer posture. If any of these routes ever fall back to runtime rendering—such as an ISR fallback, dev preview in production mode, or a prerender failure served on-demand—Nitro's bundled output will reference feed at runtime and it will be missing in a --prod/--production install.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 136, Move the "feed" package from devDependencies to
dependencies in package.json so it is available at runtime; update package.json
by removing "feed": "5.2.0" from devDependencies and adding the same entry under
dependencies. This ensures imports in server/utils/feeds.ts (used by the
/rss.xml, /atom.xml and /feed.json routes with prerender: true) are present in
production builds and prevents runtime errors if those routes are ever rendered
on-demand.

"h3": "1.15.8",
"h3-next": "npm:h3@2.0.1-rc.16",
"knip": "6.0.5",
Expand Down
Loading
Loading