Skip to content

Commit 7ffa9d0

Browse files
committed
README render tweaks, code cleanup, more TODOs
1 parent 63bfb6c commit 7ffa9d0

5 files changed

Lines changed: 111 additions & 20 deletions

File tree

bun.lock

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/PackageAuthor.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useContext } from 'react';
2-
import { View } from 'react-native';
2+
import { StyleSheet, View } from 'react-native';
33

44
import { A, Caption, colors, Label } from '~/common/styleguide';
55
import { type NpmUser } from '~/types';
@@ -33,21 +33,15 @@ export function PackageAuthor({ author }: Props) {
3333
<A
3434
href={`https://github.com/${ghUsername}`}
3535
target="_blank"
36-
style={{
37-
display: 'flex',
38-
flexDirection: 'row',
39-
gap: 12,
40-
alignItems: 'center',
41-
backgroundColor: 'transparent',
42-
}}
36+
style={styles.link}
4337
hoverStyle={isDark && { color: colors.primaryDark }}>
4438
<img
4539
src={`https://github.com/${ghUsername}.png`}
46-
style={{ width: 32, height: 32, borderRadius: '100%' }}
40+
style={styles.avatar}
4741
alt={`${ghUsername} avatar`}
4842
/>
4943
<View>
50-
<Caption style={{ lineHeight: 16, color: 'inherit' }}>{ghUsername}</Caption>
44+
<Caption style={styles.secondLine}>{ghUsername}</Caption>
5145
<Label style={{ color: 'inherit' }}>{validName}</Label>
5246
</View>
5347
</A>
@@ -78,3 +72,22 @@ function getValidName(potentialName: string): string {
7872
.join(' ');
7973
return cleanName.length ? cleanName : potentialName.replace(/[<>()]/g, '');
8074
}
75+
76+
const styles = StyleSheet.create({
77+
link: {
78+
display: 'flex',
79+
flexDirection: 'row',
80+
gap: 12,
81+
alignItems: 'center',
82+
backgroundColor: 'transparent',
83+
},
84+
secondLine: {
85+
lineHeight: 16,
86+
color: 'inherit',
87+
},
88+
avatar: {
89+
width: 32,
90+
height: 32,
91+
borderRadius: '100%',
92+
},
93+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"react-native-web": "^0.21.2",
4242
"rehype-raw": "^7.0.0",
4343
"rehype-sanitize": "^6.0.0",
44+
"remark-gfm": "^4.0.1",
4445
"use-debounce": "^10.0.6"
4546
},
4647
"devDependencies": {

pages/package/[...name].tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Linkify } from 'react-easy-linkify';
66
import { Platform, StyleSheet, View } from 'react-native';
77
import rehypeRaw from 'rehype-raw';
88
import rehypeSanitize from 'rehype-sanitize';
9+
import remarkGfm from 'remark-gfm';
910

1011
import { A, colors, darkColors, H6, Headline, Label, P, useLayout } from '~/common/styleguide';
1112
import { Button } from '~/components/Button';
@@ -29,21 +30,23 @@ import { getExampleDescription } from '~/util/strings';
2930
import urlWithQuery from '~/util/urlWithQuery';
3031

3132
type Props = {
33+
packageName: string;
3234
apiData: {
3335
libraries: LibraryType[];
3436
};
35-
registryData: NpmLatestRegistryData;
36-
packageName: string;
37+
registryData?: NpmLatestRegistryData;
3738
readmeContent?: string;
3839
};
3940

41+
// TODO: async render/data fetch
42+
// TODO: responsive/mobile viewports
4043
export default function PackagePage({ apiData, registryData, packageName, readmeContent }: Props) {
4144
const { isDark } = useContext(CustomAppearanceContext);
4245
const { isSmallScreen } = useLayout();
4346

4447
const library = apiData.libraries.find(lib => lib.npmPkg === packageName);
4548

46-
if (!library) {
49+
if (!library || !registryData) {
4750
return (
4851
<>
4952
<Navigation />
@@ -62,7 +65,6 @@ export default function PackagePage({ apiData, registryData, packageName, readme
6265
);
6366
}
6467

65-
const { description } = library.github;
6668
const { author, maintainers, dependencies, devDependencies, peerDependencies, engines } =
6769
registryData;
6870

@@ -92,13 +94,13 @@ export default function PackagePage({ apiData, registryData, packageName, readme
9294
<UpdatedAtView library={library} />
9395
</View>
9496
<CompatibilityTags library={library} />
95-
{description && description.length && (
97+
{library.github.description && library.github.description.length && (
9698
<Headline style={styles.description}>
9799
<Linkify
98100
options={{
99101
linkWrapper: props => <A {...props}>{props.children}</A>,
100102
}}>
101-
{emoji.emojify(description)}
103+
{emoji.emojify(library.github.description)}
102104
</Linkify>
103105
</Headline>
104106
)}
@@ -118,10 +120,12 @@ export default function PackagePage({ apiData, registryData, packageName, readme
118120
hr: () => null,
119121
a: (props: any) => <A containerStyle={{ display: 'inline-flex' }} {...props} />,
120122
// TODO: decide if we want to remove images/assets, or fix relative assets links
121-
// TODO: render code block in a better way
122123
// TODO: render blockquotes in a better way, support GH themed notes
124+
// TODO: render code block in a better way
125+
// TODO: render tables in a better way
123126
}}
124-
rehypePlugins={[rehypeRaw, rehypeSanitize]}>
127+
rehypePlugins={[rehypeRaw, rehypeSanitize]}
128+
remarkPlugins={[remarkGfm]}>
125129
{readmeContent}
126130
</Md>
127131
</View>
@@ -166,7 +170,7 @@ export default function PackagePage({ apiData, registryData, packageName, readme
166170
</>
167171
)}
168172
<H6 style={[styles.mainContentHeader, headerColorStyle]}>Additional information</H6>
169-
<View style={{ gap: 6 }}>
173+
<View style={styles.rowSpacing}>
170174
<MetaData library={library} secondary skipExamples />
171175
</View>
172176
{library.images && library.images.length ? (
@@ -187,7 +191,7 @@ export default function PackagePage({ apiData, registryData, packageName, readme
187191
<H6 style={[styles.mainContentHeader, headerColorStyle]}>Popularity</H6>
188192
<TrendingMark library={library} />
189193
<H6 style={[styles.contentHeader, headerColorStyle]}>Package analysis</H6>
190-
<View style={{ gap: 4 }}>
194+
<View style={styles.rowSpacing}>
191195
<A
192196
href={`https://bundlephobia.com/package/${library.npmPkg}`}
193197
target="_blank"
@@ -350,6 +354,9 @@ const styles = StyleSheet.create({
350354
borderWidth: 1,
351355
borderStyle: 'solid',
352356
},
357+
rowSpacing: {
358+
gap: 6,
359+
},
353360
});
354361

355362
export async function getServerSideProps(ctx: NextPageContext) {

styles/styles.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,40 @@ select {
242242
word-break: break-word;
243243
}
244244

245+
pre {
246+
background-color: var(--select-background);
247+
border-radius: 8px;
248+
padding: 10px 14px;
249+
color: #fff;
250+
margin-bottom: 0;
251+
line-height: 1.4;
252+
253+
&:last-child {
254+
margin-bottom: 12px;
255+
}
256+
}
257+
245258
img {
246259
max-width: 100%;
247260
}
261+
262+
blockquote {
263+
margin-inline-start: 1rem;
264+
}
265+
266+
ul, ol {
267+
padding-inline-start: 1rem;
268+
margin-bottom: 0;
269+
}
270+
271+
table {
272+
margin-top: 8px;
273+
border-collapse: collapse;
274+
width: fit-content;
275+
}
276+
277+
td, th {
278+
border: 1px solid var(--select-border);
279+
padding: 3px 6px;
280+
}
248281
}

0 commit comments

Comments
 (0)