mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 18:13:29 +00:00
Fix RSS discovery for pages without updates (#4626)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"gitbook": patch
|
||||
---
|
||||
|
||||
Only advertise RSS feeds on pages with Updates blocks.
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
import { getLLMsTxtURL, getPageMarkdownURL } from '@/lib/llms-directive';
|
||||
import type { AncestorRevisionPage } from '@/lib/pages';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
import { getPageRSSURL } from '@/routes/rss';
|
||||
|
||||
const LINK_PREVIEW_MAX_COUNT = 500;
|
||||
|
||||
@@ -86,6 +87,14 @@ export async function PageBody(props: {
|
||||
|
||||
return (
|
||||
<CurrentPageProvider page={{ spaceId: context.space.id, pageId: page.id }}>
|
||||
{contentHasUpdates ? (
|
||||
<link
|
||||
rel="alternate"
|
||||
type="application/rss+xml"
|
||||
href={getPageRSSURL(context, page)}
|
||||
title="RSS Feed"
|
||||
/>
|
||||
) : null}
|
||||
<main
|
||||
className={tcls(
|
||||
'relative min-w-0 flex-1',
|
||||
|
||||
@@ -39,7 +39,6 @@ import {
|
||||
getDocumentFilterableTags,
|
||||
updatesFilterStyleHref,
|
||||
} from '@/lib/updates';
|
||||
import { getPageRSSURL } from '@/routes/rss';
|
||||
|
||||
export type SitePageProps = {
|
||||
context: GitBookSiteContext;
|
||||
@@ -244,9 +243,6 @@ export async function generateSitePageMetadata(props: SitePageProps): Promise<Me
|
||||
languages: alternates?.languages,
|
||||
types: {
|
||||
'text/markdown': `${linker.toAbsoluteURL(linker.toPathInSpace(page.path))}.md`,
|
||||
// We always reference the RSS feed even if the page doesn't have updates blocks,
|
||||
// It might result in 404, but we can't know here if the page has updates blocks.
|
||||
'application/rss+xml': [{ url: getPageRSSURL(context, page), title: 'RSS Feed' }],
|
||||
// Currently it will output with an empty "type" like <link rel="alternate" href="..." type />
|
||||
// Team at Vercel is aware of this and will ensure it will be omitted when the value is empty in future versions of Next.js
|
||||
// https://gitbook.slack.com/archives/C04K6MV5W1K/p1763034072958419?thread_ts=1762937203.511629&cid=C04K6MV5W1K
|
||||
|
||||
@@ -29,3 +29,22 @@ it('should not expose a RSS feed for a page without updates (root page)', async
|
||||
expect(response.status).toBe(404);
|
||||
expect(await response.text()).toBe('No updates found in page');
|
||||
});
|
||||
|
||||
for (const path of ['', '/text-page', '/blocks/updates']) {
|
||||
it(`only advertises an RSS feed when the page has updates (${path || '/'})`, async () => {
|
||||
const response = await fetch(
|
||||
getContentTestURL(`https://gitbook.gitbook.io/test-gitbook-open${path}`),
|
||||
{ headers: { 'User-Agent': 'Googlebot' } }
|
||||
);
|
||||
expect(response.status).toBe(200);
|
||||
const html = await response.text();
|
||||
const links = Array.from(html.matchAll(/<link\b[^>]*>/g), ([link]) => link).filter((link) =>
|
||||
link.includes('type="application/rss+xml"')
|
||||
);
|
||||
expect(links).toHaveLength(path === '/blocks/updates' ? 1 : 0);
|
||||
if (path === '/blocks/updates') {
|
||||
expect(links[0]).toContain('/blocks/updates/rss.xml');
|
||||
expect(html.slice(0, html.indexOf('</head>'))).toContain('type="application/rss+xml"');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user