-
-
Notifications
You must be signed in to change notification settings - Fork 533
feat: provide rss, atom and json feeds for the blog #2562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kiwow
wants to merge
35
commits into
npmx-dev:main
Choose a base branch
from
Kiwow:rss
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
e620cb1
Add feed package
Kiwow 9b3fd46
First version of feed generation
Kiwow 995a5bb
[autofix.ci] apply automated fixes
autofix-ci[bot] 38fdefe
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] 764b2ac
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] c8a0147
Remove generated files
Kiwow 034ffd6
Don't generate files to /public
Kiwow 021d241
Add prerendered endpoint for each feed type
Kiwow 4ad82dc
Include link rel='alternate' on blog pages
Kiwow 4f8a193
Get rid of unnecessary exports
Kiwow 71390b1
Hack around the type error
Kiwow 0feba05
Add e2e test that verifies links and file types
Kiwow cfdb1a5
Update locator usage
Kiwow 74b2c73
Move header setting to nuxt config
Kiwow 4d27065
Finish test
Kiwow 453ceb5
Merge branch 'main' into rss
Kiwow 1389051
Update comments
Kiwow 9939025
Merge remote-tracking branch 'origin/main' into rss
Kiwow 106d240
Simplify feed generation by not caching the object
Kiwow 02dfcfa
Streamline absolute URLs
Kiwow aa540af
fix: Properly reinclude .nuxt/ route
Kiwow c5bfb69
Revert "fix: Properly reinclude .nuxt/ route"
Kiwow 5a2c622
Fix comment
Kiwow f5e9f22
Capitalize A
Kiwow fca6411
fix: lint
Kiwow dfdfaef
Merge branch 'main' into rss
Kiwow 607ee7c
Merge remote-tracking branch 'origin/main' into rss
Kiwow f9bf8c3
Merge remote-tracking branch 'origin/main' into rss
Kiwow 28f7c03
Merge remote-tracking branch 'origin/main' into rss
Kiwow 5ef6ebf
pnpm dedupe
Kiwow 152028b
Update feed package
Kiwow 8e2b743
Merge remote-tracking branch 'origin/main' into rss
Kiwow 05b96e8
Move feeds under /blog, remove JSON feed
Kiwow 2785ff6
Assert feed body is nonempty
Kiwow 251ddaa
Merge remote-tracking branch 'origin/main' into rss
Kiwow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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.
This file contains hidden or 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 @@ | ||
| import { getFeed } from '../../utils/feeds' | ||
|
|
||
| export default defineEventHandler(() => { | ||
| return getFeed().atom1() | ||
| }) |
This file contains hidden or 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 @@ | ||
| import { getFeed } from '../../utils/feeds' | ||
|
|
||
| export default defineEventHandler(() => { | ||
| return getFeed().rss2() | ||
| }) |
This file contains hidden or 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,40 @@ | ||
| import { Feed } from 'feed' | ||
| import { posts } from '#blog/posts' | ||
|
|
||
| const makeUrlAbsolute = (url: string) => new URL(url, 'https://npmx.dev').toString() | ||
|
|
||
| export function getFeed() { | ||
| // Generate content for RSS and Atom | ||
| const feed = new Feed({ | ||
| title: 'Blog - npmx', | ||
| description: 'A fast, modern browser for the npm registry', | ||
| id: 'https://npmx.dev/blog', | ||
| link: 'https://npmx.dev/blog', | ||
| language: 'en', | ||
| image: 'https://npmx.dev/logo.svg', | ||
| favicon: 'https://npmx.dev/favicon.ico', | ||
| feedLinks: { | ||
| rss: 'https://npmx.dev/blog/rss.xml', | ||
| atom: 'https://npmx.dev/blog/atom.xml', | ||
| }, | ||
| }) | ||
|
|
||
| for (const post of posts.filter(p => !p.draft)) { | ||
| feed.addItem({ | ||
| title: post.title, | ||
| id: makeUrlAbsolute(post.path), | ||
| link: makeUrlAbsolute(post.path), | ||
| 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 ? makeUrlAbsolute(author.avatar) : undefined, | ||
| })), | ||
|
coderabbitai[bot] marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||
| date: new Date(post.date), | ||
| image: post.image ? makeUrlAbsolute(post.image) : undefined, | ||
| }) | ||
| } | ||
|
|
||
| return feed | ||
| } | ||
This file contains hidden or 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,52 @@ | ||
| import { expect, test } from './test-utils' | ||
|
|
||
| test.describe('Blog feeds', () => { | ||
| test.describe('have alternate links and matching content types', () => { | ||
| const feeds = [ | ||
| { | ||
| name: 'RSS', | ||
| contentType: 'application/rss+xml', | ||
| }, | ||
| { | ||
| name: 'Atom', | ||
| contentType: 'application/atom+xml', | ||
| }, | ||
| ] | ||
|
|
||
| for (const feed of feeds) { | ||
| test(feed.name, async ({ page, goto }) => { | ||
| await goto('/blog', { waitUntil: 'domcontentloaded' }) | ||
|
|
||
| const locator = page.locator(`link[rel='alternate'][type='${feed.contentType}']`).first() | ||
| await expect(locator).toHaveAttribute('href') | ||
|
|
||
| const href = await locator.getAttribute('href') | ||
| expect(href).not.toBeNull() | ||
|
|
||
| if (typeof href !== 'string') { | ||
| return | ||
| } | ||
|
|
||
| // href is an absolute link | ||
| expect(href.slice(0, 16)).toBe('https://npmx.dev') | ||
|
|
||
| const { contentType, corsHeader, body } = await page.evaluate(async feedHref => { | ||
| // Fetch the same path as in the alternate link | ||
| const url = feedHref.slice(16) | ||
| const response = await fetch(url) | ||
| return { | ||
| contentType: response.headers.get('Content-Type'), | ||
| corsHeader: response.headers.get('Access-Control-Allow-Origin'), | ||
| body: await response.text(), | ||
| } | ||
| }, href) | ||
|
|
||
| expect(contentType).toBe(feed.contentType) | ||
| expect(body.length).toBeGreaterThan(0) | ||
| // Make sure feeds are available to browser-based readers, see | ||
| // https://www.blogsareback.com/guides/enable-cors | ||
| expect(corsHeader).toBe('*') | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
| } | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.