Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for dynamic blog banner generation #764

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/release_post.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Eclipse Temurin 8uxxx, 11.x.x, 17.x.x and 21.x.x Available
date: ""
author: pmc
about: Create a new release post
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8uxxx, 11.x.x, 17.x.x and 21.x.x. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8uxxx, 11.x.x, 17.x.x and 21.x.x.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: A month after EclipseCon - Adoptium Community day summary, and more.
date: "2022-11-24T12:00:00+00:00"
author: carmendelgado
description: Our Community Manager gives us a summary of Eclipse Adoptium activities around the EclipseCon event.
featuredImage: "./community-day.jpg"
tags:
- "adoptium"
---
Expand Down
2 changes: 1 addition & 1 deletion content/blog/eclipse-temurin-11020.1-and-1708.1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 11.0.20.1, 17.0.8.1 now available
date: "2023-08-30T12:00:00+00:00"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 11.0.20.1 and 17.0.8.1. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 11.0.20.1 and 17.0.8.1.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u312, 11.0.13, and 17.0.1 Available
date: "2021-11-05T12:00:00+00:00"
author: georgeadams
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u312, 11.0.13, and 17.0.1. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u312, 11.0.13, and 17.0.1.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u342, 11.0.16, 17.0.4 and 18.0.2 Available
date: "2022-08-03T12:00:00+00:00"
author: georgeadams
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u342, 11.0.16, 17.0.4 and 18.0.2. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u342, 11.0.16, 17.0.4 and 18.0.2.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u362, 11.0.18, 17.0.6 and 19.0.2 Available
date: "2023-01-27T12:00:00+00:00"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u362, 11.0.18, 17.0.6 and 19.0.2. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u362, 11.0.18, 17.0.6 and 19.0.2.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u372, 11.0.19, 17.0.7 and 20.0.1 Available
date: "2023-05-04T12:00:00+00:00"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u372, 11.0.19, 17.0.7 and 20.0.1. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u372, 11.0.19, 17.0.7 and 20.0.1.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u382, 11.0.20, 17.0.8 and 20.0.2 Available
date: "2023-08-04T12:00:00+00:00"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u382, 11.0.20, 17.0.8 and 20.0.2. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u382, 11.0.20, 17.0.8 and 20.0.2.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u392, 11.0.21, 17.0.9 and 21.0.1 Available
date: "2023-11-21T12:00:00+00:00"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u392, 11.0.21, 17.0.9 and 21.0.1. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u392, 11.0.21, 17.0.9 and 21.0.1.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u402, 11.0.22, 17.0.10 and 21.0.2 Available
date: "2024-01-26"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u402, 11.0.22, 17.0.10 and 21.0.2. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u402, 11.0.22, 17.0.10 and 21.0.2.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u412, 11.0.23, 17.0.11, 21.0.3 and 22.0.1 Available
date: "2024-04-25"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u412, 11.0.23, 17.0.11 21.0.3 and 22.0.1 - our biggest release set so far. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u412, 11.0.23, 17.0.11 21.0.3 and 22.0.1 - our biggest release set so far.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u422, 11.0.24, 17.0.12, 21.0.4 and 22.0.2 Available
date: "2024-07-26"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u422, 11.0.24, 17.0.12 21.0.4 and 22.0.2 - surpassing April's release as the largest set of platforms published. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u422, 11.0.24, 17.0.12 21.0.4 and 22.0.2 - surpassing April's release as the largest set of platforms published.
tags:
- temurin
- announcement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 8u432, 11.0.25, 17.0.13, 21.0.5 and 23.0.1 Available
date: "2024-11-04"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u432, 11.0.25, 17.0.13, 21.0.5 and 23.0.1. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 8u432, 11.0.25, 17.0.13, 21.0.5 and 23.0.1.
tags:
- temurin
- announcement
Expand Down
3 changes: 3 additions & 0 deletions content/blog/external_audit/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ title: External audit of Temurin build and distribution processes
date: "2024-06-17T17:00:00+00:00"
author: pmc
description:
Last year, the Eclipse Foundation engaged the Open Source Technology Improvement Fund to
perform an independent audit of the build and distribution processes for
Eclipse Temurin.
tags:
- temurin
- security
Expand Down
2 changes: 1 addition & 1 deletion content/blog/march-2024-jdk22-release/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Eclipse Temurin 22 Available
date: "2024-03-28"
author: pmc
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 22.0.0+36. As always, all binaries are thoroughly tested and available free of charge without usage restrictions on a wide range of platforms.
description: Adoptium is happy to announce the immediate availability of Eclipse Temurin 22.0.0+36.
tags:
- temurin
- announcement
Expand Down
109 changes: 78 additions & 31 deletions gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createFilePath } from "gatsby-source-filesystem"
import locales from "./locales/i18n"
import authors from "./src/json/authors.json"
import type { GatsbyNode, Node } from "gatsby"
import { generateFeaturedImage } from './src/util/generateFeaturedImage';

import {
localizedSlug,
Expand All @@ -35,6 +36,9 @@ interface AdoptiumData {
interface MdxNode extends Node {
frontmatter: {
date: string
featuredImage: string
title: string
description: string
}
fields: {
slug: string
Expand Down Expand Up @@ -313,6 +317,27 @@ export const onCreateNode: GatsbyNode["onCreateNode"] = async ({
const date = new Date(mdxNode.frontmatter.date)
const year = date.getFullYear()
const zeroPaddedMonth = `${date.getMonth() + 1}`.padStart(2, "0")
const title: string = mdxNode.frontmatter.title;
const description: string = mdxNode.frontmatter.description;
const featuredImage: string | undefined = mdxNode.frontmatter.featuredImage;

// If no featured image is provided and both title and subtitle exist:
if (!featuredImage && title && description) {
const outputFileName = "banner.png";
const outputDir = path.join(`static/images/blog/${slug}`);
const outputPath = path.join(outputDir, outputFileName);

try {
await generateFeaturedImage(title, description, outputPath);
createNodeField({
node,
name: 'generatedFeaturedImage',
value: `/images/blog/${slug}/${outputFileName}`,
});
} catch (error) {
console.error(`Error generating featured image for ${title}: ${error}`);
}
}

createNodeField({
name: "slug",
Expand All @@ -322,7 +347,7 @@ export const onCreateNode: GatsbyNode["onCreateNode"] = async ({
createNodeField({
name: "postPath",
node,
value: `/blog/${year}/${zeroPaddedMonth}${slug}`,
value: `/news/${year}/${zeroPaddedMonth}${slug}`,
})
}
}
Expand Down Expand Up @@ -461,7 +486,7 @@ export const createPages: GatsbyNode["createPages"] = async ({
},
)

// Query all blog posts by author to determine the number of pages needed
// Query all news posts by author to determine the number of pages needed
const authorPosts = await graphql<{
allMdx: {
totalCount: number
Expand Down Expand Up @@ -497,8 +522,8 @@ export const createPages: GatsbyNode["createPages"] = async ({
createPage({
path:
index === 0
? `/blog/author/${author}`
: `/blog/author/${author}/page/${index + 1}`,
? `/news/author/${author}`
: `/news/author/${author}/page/${index + 1}`,
component: authorPage,
context: {
author,
Expand All @@ -516,11 +541,11 @@ export const createPages: GatsbyNode["createPages"] = async ({
})
}

// Create blog posts pages.
// Create news posts pages.
const tagTemplate = path.resolve("./src/templates/tagPage.tsx")
const blogPost = path.resolve("./src/templates/blogPost.tsx")
const newsPost = path.resolve("./src/templates/newsPost.tsx")

const blogPostResults = await graphql<{
const newsPostResults = await graphql<{
allMdx: {
edges: Array<{
node: {
Expand All @@ -541,6 +566,7 @@ export const createPages: GatsbyNode["createPages"] = async ({
tagsGroup: {
group: Array<{
fieldValue: string
totalCount: number
}>
}
}>(`
Expand All @@ -565,28 +591,29 @@ export const createPages: GatsbyNode["createPages"] = async ({
tagsGroup: allMdx(limit: 2000) {
group(field: { frontmatter: { tags: SELECT } }) {
fieldValue
totalCount
}
}
}
`)

if (blogPostResults.errors) {
throw blogPostResults.errors
if (newsPostResults.errors) {
throw newsPostResults.errors
}

if (!blogPostResults.data) {
throw new Error("Error retrieving blog posts")
if (!newsPostResults.data) {
throw new Error("Error retrieving news posts")
}

const posts = blogPostResults.data.allMdx.edges
const posts = newsPostResults.data.allMdx.edges

posts.forEach((post, index) => {
const previous = index === posts.length - 1 ? null : posts[index + 1].node
const next = index === 0 ? null : posts[index - 1].node

createPage({
path: `${post.node.fields.postPath}`,
component: `${blogPost}?__contentFilePath=${post.node.internal.contentFilePath}`,
component: `${newsPost}?__contentFilePath=${post.node.internal.contentFilePath}`,
context: {
slug: post.node.fields.slug,
postPath: `${post.node.fields.postPath}`,
Expand All @@ -597,38 +624,58 @@ export const createPages: GatsbyNode["createPages"] = async ({
})

// Extract tag data from query
const tags = blogPostResults.data.tagsGroup.group
const tags = newsPostResults.data.tagsGroup.group

// Make tag pages
tags.forEach(tag => {
createPage({
path: `/news/tags/${tag.fieldValue}/`,
component: tagTemplate,
context: {
tag: tag.fieldValue,
},
// Calculate how many pages we need for this tag.
const numTagPages = Math.ceil(tag.totalCount / postsPerPage)

Array.from({ length: numTagPages }).forEach((_, index) => {
const currentPageNumber = index + 1
const previousPageNumber =
currentPageNumber === 1 ? null : currentPageNumber - 1
const nextPageNumber =
currentPageNumber === numTagPages ? null : currentPageNumber + 1

createPage({
// Use a friendly URL for the first page; then add /page/2, etc.
path:
index === 0
? `/news/tags/${tag.fieldValue}/`
: `/news/tags/${tag.fieldValue}/page/${index + 1}`,
component: tagTemplate,
context: {
tag: tag.fieldValue,
limit: postsPerPage,
skip: index * postsPerPage,
numTagPages,
currentPageNumber,
previousPageNumber,
nextPageNumber,
},
})
})
})

const numPages = Math.ceil(posts.length / postsPerPage)
Array.from({ length: numPages }).forEach((_, index) => {
const currentPageNumber = index + 1
const previousPageNumber =
currentPageNumber === 1 ? null : currentPageNumber - 1
const nextPageNumber =
currentPageNumber === numPages ? null : currentPageNumber + 1

const currentPage = index + 1;
const previousPageNumber = currentPage === 1 ? null : currentPage - 1;
const nextPageNumber = currentPage === numPages ? null : currentPage + 1;

createPage({
path: `/news/page/${index + 1}`,
path: currentPage === 1 ? `/news` : `/news/page/${currentPage}`,
component: path.resolve("./src/templates/newsPage.tsx"),
context: {
limit: postsPerPage,
skip: index * postsPerPage,
numPages,
currentPageNumber,
currentPage,
totalPages: numPages,
previousPageNumber,
nextPageNumber,
baseUrl: "/news",
},
})
})
});
});
}
Loading
Loading