Skip to content

Commit 350564a

Browse files
committed
Fix GitHub Pages assets and continue Hebrew translation
1 parent bb93062 commit 350564a

File tree

9 files changed

+80
-48
lines changed

9 files changed

+80
-48
lines changed

next.config.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,32 @@
55
/**
66
* @type {import('next').NextConfig}
77
**/
8+
// detect when we're building for GitHub Pages so we can set the
9+
// correct base path. the workflow sets GITHUB_REPOSITORY which looks
10+
// like "user/repo"; the repository name is used as the basePath.
11+
const isGitHubActions = process.env.GITHUB_ACTIONS === 'true';
12+
const repoName = isGitHubActions
13+
? '/' + process.env.GITHUB_REPOSITORY.split('/')[1]
14+
: '';
15+
816
const nextConfig = {
17+
// when exporting we need to tell Next.js to write to `out` and also
18+
// make sure all asset references are prefixed with the base path
19+
output: 'export',
20+
basePath: repoName,
21+
assetPrefix: repoName,
22+
trailingSlash: true,
23+
images: {
24+
// Required for static export (GitHub Pages).
25+
unoptimized: true,
26+
},
27+
env: {
28+
// if we don't set this explicitly, the value would be empty at
29+
// runtime in the browser. components that build their own
30+
// `<img src="/…"/>` paths rely on this to know the correct prefix.
31+
NEXT_PUBLIC_BASE_PATH: repoName,
32+
},
33+
934
pageExtensions: ['jsx', 'js', 'ts', 'tsx', 'mdx', 'md'],
1035
reactStrictMode: true,
1136
experimental: {
@@ -14,7 +39,6 @@ const nextConfig = {
1439
scrollRestoration: true,
1540
legacyBrowsers: false,
1641
},
17-
env: {},
1842
webpack: (config, {dev, isServer, ...options}) => {
1943
if (process.env.ANALYZE) {
2044
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"analyze": "ANALYZE=true next build",
88
"dev": "next dev",
99
"dev:remote-watch": "next-remote-watch ./src/content",
10-
"build": "next build && node --experimental-modules ./scripts/downloadFonts.mjs",
10+
"build": "next build && next export -o out && node --experimental-modules ./scripts/downloadFonts.mjs",
1111
"lint": "next lint",
1212
"lint:fix": "next lint --fix",
1313
"format:source": "prettier --config .prettierrc --write \"{plugins,src}/**/*.{js,ts,jsx,tsx,css}\"",

src/components/Layout/HomeContent.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -632,39 +632,41 @@ function CTA({children, icon, href}) {
632632
);
633633
}
634634

635-
const reactConf2021Cover = '/images/home/conf2021/cover.svg';
636-
const reactConf2019Cover = '/images/home/conf2019/cover.svg';
635+
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || '';
636+
637+
const reactConf2021Cover = basePath + '/images/home/conf2021/cover.svg';
638+
const reactConf2019Cover = basePath + '/images/home/conf2019/cover.svg';
637639
const communityImages = [
638640
{
639-
src: '/images/home/community/react_conf_fun.webp',
641+
src: basePath + '/images/home/community/react_conf_fun.webp',
640642
alt: 'אנשים שרים קריוקי ב-React Conf',
641643
},
642644
{
643-
src: '/images/home/community/react_india_sunil.webp',
645+
src: basePath + '/images/home/community/react_india_sunil.webp',
644646
alt: 'Sunil Pai מרצה ב-React India',
645647
},
646648
{
647-
src: '/images/home/community/react_conf_hallway.webp',
649+
src: basePath + '/images/home/community/react_conf_hallway.webp',
648650
alt: 'שיחת מסדרון בין שני אנשים ב-React Conf',
649651
},
650652
{
651-
src: '/images/home/community/react_india_hallway.webp',
653+
src: basePath + '/images/home/community/react_india_hallway.webp',
652654
alt: 'שיחת מסדרון ב-React India',
653655
},
654656
{
655-
src: '/images/home/community/react_conf_elizabet.webp',
657+
src: basePath + '/images/home/community/react_conf_elizabet.webp',
656658
alt: 'Elizabet Oliveira מרצה ב-React Conf',
657659
},
658660
{
659-
src: '/images/home/community/react_india_selfie.webp',
661+
src: basePath + '/images/home/community/react_india_selfie.webp',
660662
alt: 'אנשים מצלמים סלפי קבוצתי ב-React India',
661663
},
662664
{
663-
src: '/images/home/community/react_conf_nat.webp',
665+
src: basePath + '/images/home/community/react_conf_nat.webp',
664666
alt: 'Nat Alison מרצה ב-React Conf',
665667
},
666668
{
667-
src: '/images/home/community/react_india_team.webp',
669+
src: basePath + '/images/home/community/react_india_team.webp',
668670
alt: 'מארגנים שמברכים את המשתתפים ב-React India',
669671
},
670672
];
@@ -1000,35 +1002,35 @@ function Example3() {
10001002
id: 'vids-0',
10011003
title: 'React: The Documentary',
10021004
description: 'סיפור המקור של React',
1003-
image: '/images/home/videos/documentary.webp',
1005+
image: basePath + '/images/home/videos/documentary.webp',
10041006
url: 'https://www.youtube.com/watch?v=8pDqJVdNa44',
10051007
},
10061008
{
10071009
id: 'vids-1',
10081010
title: 'Rethinking Best Practices',
10091011
description: 'Pete Hunt (2013)',
1010-
image: '/images/home/videos/rethinking.jpg',
1012+
image: basePath + '/images/home/videos/rethinking.jpg',
10111013
url: 'https://www.youtube.com/watch?v=x7cQ3mrcKaY',
10121014
},
10131015
{
10141016
id: 'vids-2',
10151017
title: 'Introducing React Native',
10161018
description: 'Tom Occhino (2015)',
1017-
image: '/images/home/videos/rn.jpg',
1019+
image: basePath + '/images/home/videos/rn.jpg',
10181020
url: 'https://www.youtube.com/watch?v=KVZ-P-ZI6W4',
10191021
},
10201022
{
10211023
id: 'vids-3',
10221024
title: 'Introducing React Hooks',
10231025
description: 'Sophie Alpert and Dan Abramov (2018)',
1024-
image: '/images/home/videos/hooks.jpg',
1026+
image: basePath + '/images/home/videos/hooks.jpg',
10251027
url: 'https://www.youtube.com/watch?v=V-QO-KO90iQ',
10261028
},
10271029
{
10281030
id: 'vids-4',
10291031
title: 'היכרות עם Server Components',
10301032
description: 'Dan Abramov and Lauren Tan (2020)',
1031-
image: '/images/home/videos/rsc.jpg',
1033+
image: basePath + '/images/home/videos/rsc.jpg',
10321034
url: 'https://www.youtube.com/watch?v=TQQPAU21ZUw',
10331035
},
10341036
];
@@ -2381,10 +2383,10 @@ function fetchTalks(confId) {
23812383
url: 'https://www.youtube.com/watch?v=FZ0cG47msEk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=1',
23822384
image: {
23832385
speakers: [
2384-
'/images/home/conf2021/andrew.jpg',
2385-
'/images/home/conf2021/lauren.jpg',
2386-
'/images/home/conf2021/juan.jpg',
2387-
'/images/home/conf2021/rick.jpg',
2386+
basePath + '/images/home/conf2021/andrew.jpg',
2387+
basePath + '/images/home/conf2021/lauren.jpg',
2388+
basePath + '/images/home/conf2021/juan.jpg',
2389+
basePath + '/images/home/conf2021/rick.jpg',
23882390
],
23892391
},
23902392
},
@@ -2394,7 +2396,7 @@ function fetchTalks(confId) {
23942396
description: 'Shruti Kapoor',
23952397
url: 'https://www.youtube.com/watch?v=ytudH8je5ko&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=2',
23962398
image: {
2397-
speakers: ['/images/home/conf2021/shruti.jpg'],
2399+
speakers: [basePath + '/images/home/conf2021/shruti.jpg'],
23982400
},
23992401
},
24002402
{
@@ -2403,7 +2405,7 @@ function fetchTalks(confId) {
24032405
description: 'Shaundai Person',
24042406
url: 'https://www.youtube.com/watch?v=pj5N-Khihgc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=3',
24052407
image: {
2406-
speakers: ['/images/home/conf2021/shaundai.jpg'],
2408+
speakers: [basePath + '/images/home/conf2021/shaundai.jpg'],
24072409
},
24082410
},
24092411
{

src/components/Layout/Page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function Page({children, toc, routeTree, meta, section}: PageProps) {
114114
title={title}
115115
titleForTitleTag={meta.titleForTitleTag}
116116
isHomePage={isHomePage}
117-
image={`/images/og-` + section + '.png'}
117+
image={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/images/og-` + section + '.png'}
118118
searchOrder={searchOrder}
119119
/>
120120
<SocialBanner />

src/components/MDX/Diagram.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ export function Diagram({
3636
{captionPosition === 'top' && <Caption text={children} />}
3737
<div className="dark-image">
3838
<Image
39-
src={`/images/docs/diagrams/${name}.dark.png`}
39+
src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/images/docs/diagrams/${name}.dark.png`}
4040
alt={alt}
4141
height={height}
4242
width={width}
4343
/>
4444
</div>
4545
<div className="light-image">
4646
<Image
47-
src={`/images/docs/diagrams/${name}.png`}
47+
src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/images/docs/diagrams/${name}.png`}
4848
alt={alt}
4949
height={height}
5050
width={width}

src/components/MDX/MDXComponents.tsx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ const IllustrationContext = React.createContext<{
224224
isInBlock: false,
225225
});
226226

227+
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || '';
228+
227229
function Illustration({
228230
caption,
229231
src,
@@ -238,12 +240,13 @@ function Illustration({
238240
authorLink: string;
239241
}) {
240242
const {isInBlock} = React.useContext(IllustrationContext);
243+
const prefixedSrc = src.startsWith('/') ? basePath + src : src;
241244

242245
return (
243246
<div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
244247
<figure className="my-8 flex justify-center">
245248
<img
246-
src={src}
249+
src={prefixedSrc}
247250
alt={alt}
248251
style={{maxHeight: 300}}
249252
className="rounded-lg"
@@ -275,23 +278,26 @@ function IllustrationBlock({
275278
const imageInfos = Children.toArray(children).map(
276279
(child: any) => child.props
277280
);
278-
const images = imageInfos.map((info, index) => (
279-
<figure key={index}>
280-
<div className="bg-white rounded-lg p-4 flex-1 flex xl:p-6 justify-center items-center my-4">
281-
<img
282-
className="text-primary"
283-
src={info.src}
284-
alt={info.alt}
285-
height={info.height}
286-
/>
287-
</div>
288-
{info.caption ? (
289-
<figcaption className="text-secondary dark:text-secondary-dark text-center leading-tight mt-4">
290-
{info.caption}
291-
</figcaption>
292-
) : null}
293-
</figure>
294-
));
281+
const images = imageInfos.map((info, index) => {
282+
const prefixed = info.src && info.src.startsWith('/') ? basePath + info.src : info.src;
283+
return (
284+
<figure key={index}>
285+
<div className="bg-white rounded-lg p-4 flex-1 flex xl:p-6 justify-center items-center my-4">
286+
<img
287+
className="text-primary"
288+
src={prefixed}
289+
alt={info.alt}
290+
height={info.height}
291+
/>
292+
</div>
293+
{info.caption ? (
294+
<figcaption className="text-secondary dark:text-secondary-dark text-center leading-tight mt-4">
295+
{info.caption}
296+
</figcaption>
297+
) : null}
298+
</figure>
299+
);
300+
});
295301
return (
296302
<IllustrationContext.Provider value={isInBlockTrue}>
297303
<div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">

src/components/Seo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const Seo = withRouter(
3939
({
4040
title,
4141
titleForTitleTag,
42-
image = '/images/og-default.png',
42+
image = (process.env.NEXT_PUBLIC_BASE_PATH || '') + '/images/og-default.png',
4343
router,
4444
children,
4545
isHomePage,

src/styles/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ ol.mdx-illustration-block {
639639
transform: translateY(-50%);
640640
width: 60px;
641641
height: 49px;
642-
background: center / contain no-repeat url('/images/g_arrow.png');
642+
background: center / contain no-repeat url("" + (process.env.NEXT_PUBLIC_BASE_PATH || '') + "/images/g_arrow.png");
643643
}
644644
.mdx-illustration-block li:first-child:after {
645645
content: ' ';

tailwind.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ module.exports = {
5353
'conic-gradient(from 90deg at -10% 100%, #BCC1CD 0deg, #BCC1CD 90deg, #FFFFFF 360deg)',
5454
'gradient-right':
5555
'conic-gradient(from -90deg at 110% 100%, #FFFFFF 0deg, #EBECF0 90deg, #EBECF0 360deg)',
56-
'meta-gradient': "url('/images/meta-gradient.png')",
57-
'meta-gradient-dark': "url('/images/meta-gradient-dark.png')",
56+
'meta-gradient': "url('" + (process.env.NEXT_PUBLIC_BASE_PATH || '') + "/images/meta-gradient.png')",
57+
'meta-gradient-dark': "url('" + (process.env.NEXT_PUBLIC_BASE_PATH || '') + "/images/meta-gradient-dark.png')",
5858
},
5959
maxWidth: {
6060
...defaultTheme.maxWidth,

0 commit comments

Comments
 (0)