-
Notifications
You must be signed in to change notification settings - Fork 777
Expand file tree
/
Copy pathgatsby-node.ts
More file actions
144 lines (133 loc) · 4.95 KB
/
gatsby-node.ts
File metadata and controls
144 lines (133 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import path from 'path'
import fs from 'fs/promises'
import { GatsbyNode } from 'gatsby'
const axios = require('axios')
export { createPages } from './gatsby/createPages'
export { onCreateNode, onPreInit } from './gatsby/onCreateNode'
export { createSchemaCustomization } from './gatsby/createSchemaCustomization'
export { sourceNodes } from './gatsby/sourceNodes'
export { onPostBuild } from './gatsby/onPostBuild'
export { createResolvers } from './gatsby/createResolvers'
export { onPreBootstrap } from './gatsby/onPreBootstrap'
// Implement the Gatsby API "onCreatePage". This is
// called after every page is created.
export const onCreatePage: GatsbyNode['onCreatePage'] = async ({ page, actions }) => {
const { createPage, deletePage } = actions
// Add build time to credits page using environment variable
if (page.path === '/credits/') {
// Use Vercel's VERCEL_ENV variable or current time as fallback
const buildDate = process.env.VERCEL_GIT_COMMIT_SHA
? new Date() // This will be the actual build time when deployed
: new Date()
const options: Intl.DateTimeFormatOptions = {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
timeZone: 'America/Los_Angeles',
}
const buildTime = buildDate.toLocaleString('en-US', options)
deletePage(page)
createPage({
...page,
context: {
...page.context,
buildTime,
// Also pass the commit SHA if available for debugging
commitSha: process.env.VERCEL_GIT_COMMIT_SHA?.substring(0, 7) || 'local',
},
})
}
if (page.path.match(/^\/community\/profiles/)) {
page.matchPath = '/community/profiles/*'
createPage(page)
}
if (page.path.match(/^\/events\//)) {
page.matchPath = '/events/*'
createPage(page)
}
if (page.path.match(/^\/next\-steps/)) {
page.matchPath = '/next-steps/*'
createPage(page)
}
// Add client-side routing for custom presentations
if (page.path.match(/^\/for\//)) {
page.matchPath = '/for/*'
createPage(page)
}
}
export const onCreateBabelConfig: GatsbyNode['onCreateBabelConfig'] = ({ actions }) => {
actions.setBabelPlugin({
name: '@babel/plugin-transform-react-jsx',
options: {
runtime: 'automatic',
},
})
}
export const onCreateWebpackConfig: GatsbyNode['onCreateWebpackConfig'] = ({ stage, actions }) => {
actions.setWebpackConfig({
...(process.env.GATSBY_MINIMAL === 'true'
? {
devtool: false,
}
: null),
cache: process.env.NODE_ENV === 'development' || {
compression: 'gzip',
},
resolve: {
extensions: ['.js', '.ts', '.tsx'],
modules: [
path.resolve(__dirname, '.cache', 'gatsby-source-git', 'posthog-main-repo', 'docs'),
path.resolve(__dirname, 'contents', 'docs'),
'node_modules',
],
alias: {
'~': path.resolve(__dirname, 'src'),
lib: path.resolve(__dirname, 'src', 'lib'),
types: path.resolve(__dirname, 'src', 'types'),
images: path.resolve(__dirname, 'src', 'images'),
components: path.resolve(__dirname, 'src', 'components'),
constants: path.resolve(__dirname, 'src', 'constants'),
logic: path.resolve(__dirname, 'src', 'logic'),
hooks: path.resolve(__dirname, 'src', 'hooks'),
// Mapping
docs: path.resolve(__dirname, '.cache', 'gatsby-source-git', 'posthog-main-repo', 'docs'),
onboarding: path.resolve(
__dirname,
'.cache',
'gatsby-source-git',
'posthog-main-repo',
'docs',
'onboarding'
),
'scenes/onboarding/OnboardingDocsContentWrapper': path.resolve(
__dirname,
'src',
'components',
'Docs',
'OnboardingContentWrapper.tsx'
),
},
},
})
}
exports.createPages = async ({ actions }) => {
const { createPage } = actions
try {
const response = await axios.get('https://jobs.ashbyhq.com/supabase')
const jobData = JSON.parse(response.data)
const jobs = jobData?.jobBoard?.jobPostings || []
// Create the jobs page with the data
createPage({
path: '/jobs',
component: require.resolve('./src/templates/jobs.tsx'),
context: {
jobs: jobs,
},
})
} catch (error) {
console.error('Error fetching jobs:', error)
}
}