-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgatsby-node.js
More file actions
356 lines (309 loc) · 11 KB
/
gatsby-node.js
File metadata and controls
356 lines (309 loc) · 11 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
const _ = require('lodash')
const path = require('path')
const { createFilePath } = require('gatsby-source-filesystem')
const axios = require('axios')
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type MarkdownRemarkFrontmatter {
category: [BlogCategory]
author: String
templateKey: String
date: Date @dateformat
title: String
subTitle: String
company: String
}
type BlogCategory {
label: String
id: String
}
type IronicRelease implements Node {
version: String!
releaseNotesUrl: String!
publishedAt: Date @dateformat
htmlUrl: String!
}
`
createTypes(typeDefs)
}
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions
return graphql(`
{
allMarkdownRemark(limit: 1000) {
edges {
node {
id
fields {
slug
}
frontmatter {
category {
label
}
author
templateKey
}
}
}
}
}
`).then(result => {
if (result.errors) {
result.errors.forEach(e => console.error(e.toString()))
return Promise.reject(result.errors)
}
const posts = result.data.allMarkdownRemark.edges
posts.forEach(edge => {
const id = edge.node.id
createPage({
path: edge.node.fields.slug.replace('/pages', ''),
category: edge.node.frontmatter.category,
component: path.resolve(
`src/templates/${String(edge.node.frontmatter.templateKey)}.js`
),
// additional data can be passed via context
context: {
id,
},
})
})
// category pages:
let categories = []
// Iterate through each post, putting all found categories into `categories`
posts.forEach(edge => {
if (_.get(edge, `node.frontmatter.category`)) {
categories = categories.concat(edge.node.frontmatter.category[0].label)
}
})
// Eliminate duplicate categories
categories = _.uniq(categories)
// Make category pages
categories.forEach(category => {
const categoriePath = `/category/${_.kebabCase(category)}/`
createPage({
path: categoriePath,
component: path.resolve(`src/templates/tags.js`),
context: {
category,
},
})
})
// author pages:
let authors = []
// Iterate through each post, putting all found authors into `authors`
posts.forEach(edge => {
if (_.get(edge, `node.frontmatter.author`)) {
authors = authors.concat(edge.node.frontmatter.author)
}
})
// Eliminate duplicate categories
authors = _.uniq(authors)
// Make category pages
authors.forEach(author => {
const authorPath = `/author/${_.kebabCase(author)}/`
createPage({
path: authorPath,
component: path.resolve(`src/templates/tags.js`),
context: {
author,
},
})
})
})
}
async function getSeriesStatusData() {
try {
console.log('📋 Fetching OpenStack series status data...')
const response = await axios.get('https://raw.githubusercontent.com/openstack/releases/master/data/series_status.yaml')
// Simple YAML parsing for series data
const yamlContent = response.data
const seriesMatches = yamlContent.match(/- name: ([^\s]+)\s+release-id: ([^\s]+)/g)
if (!seriesMatches) {
throw new Error('Could not parse series status data')
}
const seriesData = {}
const seriesOrder = []
seriesMatches.forEach(match => {
const nameMatch = match.match(/name: ([^\s]+)/)
const idMatch = match.match(/release-id: ([^\s]+)/)
if (nameMatch && idMatch) {
const name = nameMatch[1]
const releaseId = idMatch[1]
seriesData[name] = releaseId
seriesOrder.push(name) // This gives us newest-first order from the YAML
}
})
console.log(`✅ Found ${Object.keys(seriesData).length} series in OpenStack data`)
return { seriesData, seriesOrder }
} catch (error) {
console.log('⚠️ Could not fetch series status, using fallback data')
// Fallback to known series if API fails
const fallbackOrder = [
'hibiscus', 'gazpacho', 'flamingo', 'epoxy', 'dalmatian', 'caracal',
'bobcat', 'antelope', 'zed', 'yoga', 'xena', 'wallaby', 'victoria', 'ussuri'
]
const fallbackData = {
'hibiscus': '2026.2', 'gazpacho': '2026.1', 'flamingo': '2025.2', 'epoxy': '2025.1',
'dalmatian': '2024.2', 'caracal': '2024.1', 'bobcat': '2023.2', 'antelope': '2023.1',
'zed': '2022.2', 'yoga': '2022.1', 'xena': '2021.2', 'wallaby': '2021.1',
'victoria': '2020.2', 'ussuri': '2020.1'
}
return { seriesData: fallbackData, seriesOrder: fallbackOrder }
}
}
async function getLatestReleaseSeries() {
try {
console.log('🔍 Auto-detecting latest OpenStack release series...')
// Get dynamic series data from OpenStack
const { seriesData, seriesOrder } = await getSeriesStatusData()
let knownSeries = seriesOrder
console.log(`📋 Checking series in order: ${knownSeries.slice(0, 5).join(', ')}${knownSeries.length > 5 ? '...' : ''}`)
// Try each series until we find one with ironic.yaml
for (const series of knownSeries) {
try {
await axios.head(`https://raw.githubusercontent.com/openstack/releases/master/deliverables/${series}/ironic.yaml`)
console.log(`✅ Found Ironic releases in series: ${series}`)
return { series, seriesData }
} catch (error) {
// Series doesn't have ironic.yaml, try next
continue
}
}
throw new Error('No ironic.yaml found in any release series')
} catch (error) {
console.log('⚠️ Auto-detection failed, using known fallbacks')
// Return known good series as fallbacks with basic mapping
const fallbackData = {
'gazpacho': '2026.1', 'epoxy': '2025.1', 'dalmatian': '2024.2', 'caracal': '2024.1'
}
return {
series: ['gazpacho', 'epoxy', 'dalmatian', 'caracal'],
seriesData: fallbackData
}
}
}
exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }) => {
const { createNode } = actions
try {
// Auto-detect the latest release series with dynamic version mapping
const detectionResult = await getLatestReleaseSeries()
let response
let releaseSeries
let seriesVersionMap
if (Array.isArray(detectionResult.series)) {
// Fallback mode - try known series
console.log('🔄 Trying fallback series...')
seriesVersionMap = detectionResult.seriesData
for (const series of detectionResult.series) {
try {
response = await axios.get(`https://raw.githubusercontent.com/openstack/releases/master/deliverables/${series}/ironic.yaml`)
releaseSeries = series
break
} catch (error) {
continue
}
}
if (!response) {
throw new Error('All fallback series failed')
}
} else {
// Auto-detection succeeded
releaseSeries = detectionResult.series
seriesVersionMap = detectionResult.seriesData
response = await axios.get(`https://raw.githubusercontent.com/openstack/releases/master/deliverables/${releaseSeries}/ironic.yaml`)
}
// Parse YAML content (simple parsing for releases section)
const yamlContent = response.data
const releaseMatches = yamlContent.match(/- version: ([\d.]+)/g)
if (!releaseMatches || releaseMatches.length === 0) {
throw new Error('No releases found in YAML')
}
// Get the latest version (last one in the list)
const latestVersionMatch = releaseMatches[releaseMatches.length - 1]
const version = latestVersionMatch.replace('- version: ', '')
// Extract git hash for the latest version to get actual release date
let publishedAt = null
try {
// Find the git hash for this version
const hashPattern = new RegExp(`- version: ${version.replace(/\./g, '\\.')}[\\s\\S]*?hash: ([a-f0-9]+)`, 'i')
const hashMatch = yamlContent.match(hashPattern)
if (hashMatch && hashMatch[1]) {
const gitHash = hashMatch[1]
console.log(`🔍 Found git hash for ${version}: ${gitHash.substring(0, 8)}...`)
// Get commit date from GitHub API
const commitResponse = await axios.get(`https://api.github.com/repos/openstack/ironic/commits/${gitHash}`)
publishedAt = commitResponse.data.commit.committer.date
console.log(`📅 Release date for ${version}: ${publishedAt}`)
}
} catch (error) {
console.log(`⚠️ Could not fetch release date for ${version}: ${error.message}`)
}
// Generate release notes URL using dynamic series mapping
let seriesVersion = seriesVersionMap[releaseSeries]
if (!seriesVersion) {
console.log(`⚠️ Unknown series '${releaseSeries}', using generic release notes URL`)
seriesVersion = 'latest'
}
const releaseNotesUrl = seriesVersion === 'latest'
? `https://docs.openstack.org/releasenotes/ironic/latest.html#relnotes-${version.replace(/\./g, '-')}`
: `https://docs.openstack.org/releasenotes/ironic/${seriesVersion}.html#relnotes-${version.replace(/\./g, '-')}`
const nodeData = {
version,
releaseNotesUrl,
publishedAt,
htmlUrl: `https://github.com/openstack/releases/blob/master/deliverables/${releaseSeries}/ironic.yaml`,
releaseSeries,
}
const nodeContent = JSON.stringify(nodeData)
const nodeMeta = {
id: createNodeId('ironic-latest-release'),
parent: null,
children: [],
internal: {
type: 'IronicRelease',
content: nodeContent,
contentDigest: createContentDigest(nodeData),
},
}
const node = Object.assign({}, nodeData, nodeMeta)
createNode(node)
console.log(`✅ Fetched latest Ironic release: ${version} (${releaseSeries} series)`)
} catch (error) {
console.error('❌ Failed to fetch latest Ironic release:', error.message)
// Fallback to current known version if all APIs fail
const fallbackData = {
version: '34.0.0',
releaseNotesUrl: 'https://docs.openstack.org/releasenotes/ironic/latest.html#relnotes-34-0-0',
publishedAt: null,
htmlUrl: 'https://docs.openstack.org/releasenotes/ironic/',
releaseSeries: 'fallback',
}
const nodeContent = JSON.stringify(fallbackData)
const nodeMeta = {
id: createNodeId('ironic-latest-release'),
parent: null,
children: [],
internal: {
type: 'IronicRelease',
content: nodeContent,
contentDigest: createContentDigest(fallbackData),
},
}
const node = Object.assign({}, fallbackData, nodeMeta)
createNode(node)
console.log('⚠️ Using fallback version: 34.0.0')
}
}
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
if (node.internal.type === `MarkdownRemark`) {
const value = createFilePath({ node, getNode })
createNodeField({
name: `slug`,
node,
value,
})
}
}