Skip to content

Commit f7f7d92

Browse files
scottyhqpre-commit-ci[bot]jhamman
authored
Deploy with Netlify instead of Vercel (#778)
* try ditching vercel * replace vercel badge with netlify * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove remaining vercel refs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixup eslint config * bump node --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Joseph Hamman <[email protected]>
1 parent 2f2f01c commit f7f7d92

File tree

10 files changed

+90
-47
lines changed

10 files changed

+90
-47
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# xarray landing page
22

3-
![Vercel Deployment](https://img.shields.io/github/deployments/xarray-contrib/xarray.dev/Production?label=vercel&logo=vercel&style=for-the-badge)
3+
[![Netlify Status](https://api.netlify.com/api/v1/badges/4f940719-54bd-4ff7-95e0-0088dfb3c10f/deploy-status)](https://app.netlify.com/projects/xarraydev/deploys)
44

55
Landing Page for xarray project.
66

@@ -44,10 +44,11 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the
4444

4545
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
4646

47-
<a href="https://vercel.com?utm_source=xarray&utm_campaign=oss">
48-
<p align="center">
49-
<img src="https://www.datocms-assets.com/31049/1618983297-powered-by-vercel.svg">
50-
</p>
47+
<a href='https://www.netlify.com'>
48+
<img
49+
src='https://www.netlify.com/assets/badges/netlify-badge-color-bg.svg'
50+
alt='Deploys by Netlify'
51+
/>
5152
</a>
5253

5354
## Authoring blog post tips

netlify.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[build]
2+
publish = ".next"
3+
command = "npm run build"
4+
5+
[build.environment]
6+
NODE_VERSION = "20"
7+
8+
# Redirect rules for Next.js
9+
[[redirects]]
10+
from = "/_next/static/*"
11+
to = "/static/:splat"
12+
status = 200
13+
14+
# Handle client-side routing
15+
[[redirects]]
16+
from = "/*"
17+
to = "/404.html"
18+
status = 404
19+
20+
# Environment variables for different deploy contexts
21+
[context.production.environment]
22+
NEXT_PUBLIC_SITE_URL = "https://xarray.dev"
23+
24+
[context.deploy-preview.environment]
25+
NEXT_PUBLIC_SITE_URL = "$DEPLOY_PRIME_URL"
26+
27+
[context.branch-deploy.environment]
28+
NEXT_PUBLIC_SITE_URL = "$DEPLOY_PRIME_URL"
29+
30+
# Headers for security
31+
[[headers]]
32+
for = "/*"
33+
[headers.values]
34+
X-Frame-Options = "DENY"
35+
X-XSS-Protection = "1; mode=block"
36+
X-Content-Type-Options = "nosniff"
37+
Referrer-Policy = "strict-origin-when-cross-origin"
38+
39+
# Cache static assets
40+
[[headers]]
41+
for = "/static/*"
42+
[headers.values]
43+
Cache-Control = "public, max-age=31536000, immutable"
44+
45+
[[headers]]
46+
for = "/_next/static/*"
47+
[headers.values]
48+
Cache-Control = "public, max-age=31536000, immutable"

public/vercel.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/footer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getRootURL } from '@/lib/seo-utils'
1414

1515
import { GitSHA } from '@/components/git-sha'
1616
import { Image, Link } from '@/components/mdx'
17-
import { VercelCallout } from '@/components/vercel'
17+
import { NetlifyCallout } from '@/components/netlify'
1818
import { footerItems } from '@/data/footer-items'
1919
import { FaGithub, FaRss, FaTwitter, FaYoutube } from 'react-icons/fa'
2020

@@ -154,7 +154,7 @@ export const Footer = () => {
154154
</Stack>
155155
</SimpleGrid>
156156
<VStack as='footer' spacing={4} mt={12} textAlign='center'>
157-
<VercelCallout />
157+
<NetlifyCallout />
158158
</VStack>
159159
</Container>
160160
</Box>

src/components/git-sha.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ import { Link } from '@/components/mdx'
22
import { Flex, Text } from '@chakra-ui/react'
33
import { IoGitBranchOutline } from 'react-icons/io5'
44

5-
const sha = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA || ''
6-
const owner = process.env.NEXT_PUBLIC_VERCEL_GIT_REPO_OWNER || ''
7-
const slug = process.env.NEXT_PUBLIC_VERCEL_GIT_REPO_SLUG || ''
5+
const sha = process.env.HEAD || ''
6+
const repositoryUrl = process.env.REPOSITORY_URL || ''
7+
8+
// Extract owner and repo from REPOSITORY_URL (format: https://github.com/owner/repo)
9+
const getRepoInfo = (url) => {
10+
if (!url) return { owner: '', slug: '' }
11+
const match = url.match(/github\.com\/([^\/]+)\/([^\/]+?)(?:\.git)?$/)
12+
return match ? { owner: match[1], slug: match[2] } : { owner: '', slug: '' }
13+
}
14+
15+
const { owner, slug } = getRepoInfo(repositoryUrl)
816

917
export const GitSHA = () => {
1018
if (!sha || !owner || !slug) {

src/components/layout.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export const Layout = ({
3535
//)
3636

3737
// Determine the base URL based on the environment
38-
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL
39-
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
40-
: 'http://localhost:3000'
38+
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL
39+
? process.env.NEXT_PUBLIC_SITE_URL
40+
: process.env.URL || 'http://localhost:3000'
4141

4242
// Construct the full card URL
4343
const fullCardUrl = card.startsWith('http') ? card : `${baseUrl}${card}`

src/components/netlify.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Link } from '@/components/mdx'
2+
import { Box } from '@chakra-ui/react'
3+
4+
export function NetlifyCallout() {
5+
return (
6+
<a href='https://www.netlify.com'>
7+
<img
8+
src='https://www.netlify.com/assets/badges/netlify-badge-color-bg.svg'
9+
alt='Deploys by Netlify'
10+
/>
11+
</a>
12+
)
13+
}

src/components/vercel.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/lib/seo-utils.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
export function getRootURL() {
22
let url = 'https://xarray.dev'
3-
if (
4-
process.env.NEXT_PUBLIC_VERCEL_URL &&
5-
process.env.NEXT_PUBLIC_VERCEL_ENV !== 'production'
6-
) {
7-
url = `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
3+
4+
// Use Netlify URL environment variable for deploy previews and branch deploys
5+
if (process.env.NEXT_PUBLIC_SITE_URL && process.env.CONTEXT !== 'production') {
6+
url = process.env.NEXT_PUBLIC_SITE_URL
7+
} else if (process.env.URL && process.env.CONTEXT !== 'production') {
8+
url = process.env.URL
89
}
910

1011
return url

src/pages/cards/[id].js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function getStaticPaths() {
8888
const paths = getAllPostsIds()
8989

9090
const isDev =
91-
process.env.VERCEL_ENV === 'preview' ||
91+
process.env.CONTEXT !== 'production' ||
9292
process.env.NODE_ENV === 'development'
9393
// We'll pre-render only these paths at build time.
9494
// { fallback: false } means other routes should 404.

0 commit comments

Comments
 (0)