Skip to content

Commit

Permalink
Add pages for each month's releases
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Jan 14, 2025
1 parent 214143f commit 8f7bb77
Show file tree
Hide file tree
Showing 9 changed files with 1,046 additions and 560 deletions.
46 changes: 38 additions & 8 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const {
getStream,
} = require("./src/components/util/pretty-platform")
const { sortableName } = require("./src/components/util/sortable-name")
const { extensionSlug, extensionSlugFromCoordinates } = require("./src/components/util/extension-slugger")
const {
extensionSlug,
extensionSlugFromCoordinates,
slugForExtensionsAddedMonth
} = require("./src/components/util/extension-slugger")
const { generateMavenInfo, initMavenCache, saveMavenCache } = require("./src/maven/maven-info")
const { createRemoteFileNode } = require("gatsby-source-filesystem")
const { rewriteGuideUrl } = require("./src/components/util/guide-url-rewriter")
Expand Down Expand Up @@ -232,6 +236,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {

// Define a template for an extension
const extensionTemplate = path.resolve(`./src/templates/extension-detail.js`)
const releaseMonthTemplate = path.resolve(`./src/templates/extensions-added-list.js`)

// Get all extensions
const result = await graphql(
Expand All @@ -242,6 +247,11 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
id
slug
isSuperseded
metadata {
maven {
sinceMonth
}
}
}
}
}
Expand All @@ -256,27 +266,46 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
return
}

const posts = result.data.allExtension.nodes
const extensionNodes = result.data.allExtension.nodes

// Create extension pages
// `context` is available in the template as a prop and as a variable in GraphQL

if (posts.length > 0) {
posts.forEach((post, index) => {
const previousPostId = getPreviousPost(index, posts)
const nextPostId = getNextPost(index, posts)
if (extensionNodes.length > 0) {
extensionNodes.forEach((extensionNode, index) => {
const previousPostId = getPreviousPost(index, extensionNodes)
const nextPostId = getNextPost(index, extensionNodes)

createPage({
path: post.slug,
path: extensionNode.slug,
component: extensionTemplate,
context: {
id: post.id,
id: extensionNode.id,
previousPostId,
nextPostId,
},
})
})
}

const months = [...new Set(extensionNodes.map(extensionNode => extensionNode.metadata?.maven?.sinceMonth))].sort()

months.forEach((month, index, array) => {


const slug = slugForExtensionsAddedMonth(month)
const previousMonthTimestamp = array[index - 1]
const nextMonthTimestamp = array[index + 1]
createPage({
path: slug,
component: releaseMonthTemplate,
context: {
sinceMonth: month,
previousMonthTimestamp,
nextMonthTimestamp,
},
})
})
}

const getPreviousPost = (index, posts) => {
Expand Down Expand Up @@ -362,6 +391,7 @@ exports.createSchemaCustomization = ({ actions }) => {
version: String
timestamp: String
since: String
sinceMonth: String
relocation: RelocationInfo
}
Expand Down
Loading

0 comments on commit 8f7bb77

Please sign in to comment.