Skip to content

Commit 61ba5c2

Browse files
authored
ease on GH queries, RSS auto-discovery meta, other tweaks (#2337)
1 parent 7228589 commit 61ba5c2

File tree

6 files changed

+43
-16
lines changed

6 files changed

+43
-16
lines changed

components/PageMeta.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Head from 'next/head';
2+
import { type PropsWithChildren } from 'react';
23

34
const site = {
45
title: 'React Native Directory',
@@ -7,17 +8,18 @@ const site = {
78

89
const BASE_OG_URL = 'https://og.expo.dev/?theme=rnd';
910

10-
type PageMetaProps = {
11+
type PageMetaProps = PropsWithChildren<{
1112
title?: string;
1213
description?: string;
1314
path?: string;
1415
searchQuery?: string | string[];
15-
};
16+
}>;
1617

1718
export default function PageMeta({
1819
title,
1920
searchQuery,
2021
path,
22+
children,
2123
description = site.description,
2224
}: PageMetaProps) {
2325
const pageTitle = `${title ? title + ' • ' : ''}${site.title}`;
@@ -45,6 +47,8 @@ export default function PageMeta({
4547
<meta name="twitter:image" content={socialImage} />
4648

4749
<link rel="canonical" href={`https://reactnative.directory${path ? `/${path}` : ''}`} />
50+
51+
{children}
4852
</Head>
4953
);
5054
}

pages/rss/added.xml.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export async function getServerSideProps(ctx: NextPageContext) {
1313
return { notFound: true };
1414
}
1515

16+
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
17+
res.setHeader('Cache-Control', 'public, s-maxage=600, stale-while-revalidate=300');
18+
1619
try {
1720
const response = await ssrFetch(
1821
'/libraries',
@@ -35,8 +38,6 @@ export async function getServerSideProps(ctx: NextPageContext) {
3538
res.write('Error: Cannot generate RSS feed');
3639
}
3740

38-
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
39-
res.setHeader('Cache-Control', 'public, s-maxage=600, stale-while-revalidate=300');
4041
res.end();
4142

4243
return { props: {} };

pages/rss/updated.xml.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export async function getServerSideProps(ctx: NextPageContext) {
1313
return { notFound: true };
1414
}
1515

16+
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
17+
res.setHeader('Cache-Control', 'public, s-maxage=600, stale-while-revalidate=300');
18+
1619
try {
1720
const response = await ssrFetch(
1821
'/libraries',
@@ -35,8 +38,6 @@ export async function getServerSideProps(ctx: NextPageContext) {
3538
res.write('Error: Cannot generate RSS feed');
3639
}
3740

38-
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
39-
res.setHeader('Cache-Control', 'public, s-maxage=600, stale-while-revalidate=300');
4041
res.end();
4142

4243
return { props: {} };

scenes/HomeScene.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,20 @@ export default function HomeScene({
3535

3636
return (
3737
<>
38-
<PageMeta />
38+
<PageMeta>
39+
<link
40+
rel="alternate"
41+
type="application/rss+xml"
42+
title="RSS: Recently added libraries"
43+
href="/rss/added.xml"
44+
/>
45+
<link
46+
rel="alternate"
47+
type="application/rss+xml"
48+
title="RSS: Recently updated libraries"
49+
href="/rss/updated.xml"
50+
/>
51+
</PageMeta>
3952
<Navigation
4053
title="React Native packages registry"
4154
description="Browse thousands of open-source packages and find the best ones for your current or next project.">

scripts/build-and-score-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ const DATASET: LibraryDataEntryType[] = USE_DEBUG_REPOS ? debugGithubRepos : git
3434
const DATA_PATH = path.resolve('assets', 'data.json');
3535
const CHECK_DATA_PATH = path.resolve('assets', 'check-data.json');
3636

37-
const CHUNK_SIZE = 25;
37+
const CHUNK_SIZE = 20;
3838
const NPM_STATS_CHUNK_SIZE = 10;
39-
const SLEEP_TIME = 250;
39+
const SLEEP_TIME = 500;
4040

4141
const invalidRepos: string[] = [];
4242
const mismatchedRepos: LibraryType[] = [];

scripts/helpers.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,24 @@ export async function makeGraphqlQuery(query: string, variables = {}) {
1919
variables,
2020
}),
2121
});
22-
try {
23-
return await result.json();
24-
} catch (error: unknown) {
25-
console.error('GitHub GraphQL response parse failed!', {
22+
if (result.ok) {
23+
try {
24+
return await result.json();
25+
} catch (error: unknown) {
26+
console.error('GitHub GraphQL response parse failed!', {
27+
status: result.status,
28+
statusText: result.statusText,
29+
error: error instanceof Error ? error.message : String(error),
30+
});
31+
throw error;
32+
}
33+
} else {
34+
console.error('GitHub GraphQL invalid response!', {
2635
status: result.status,
2736
statusText: result.statusText,
28-
error: error instanceof Error ? error.message : String(error),
29-
body: result.body,
37+
body: result?.body ? await result.text() : undefined,
3038
});
31-
throw error;
39+
throw new Error(`GitHub GraphQL invalid response: ${result.status}`);
3240
}
3341
}
3442

0 commit comments

Comments
 (0)