Skip to content

Commit

Permalink
Adds featured-sponsors-darkmode.svg to fix darkmode sponsors on ddev/…
Browse files Browse the repository at this point in the history
…ddev (#134)
  • Loading branch information
bmartinez287 authored Nov 8, 2023
1 parent fdb0828 commit 0929497
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ It’s used to display sponsor details in a few places:

1. The [homepage](https://ddev.com) “Featured Sponsors” list.
2. The leading bubbles on the [Support DDEV page](https://ddev.com/support-ddev/)’s “Sponsor Development” grid.
3. The [procedurally-generated](https://github.com/ddev/ddev.com-front-end/blob/main/src/pages/resources/featured-sponsors.svg.js) featured sponsors [SVG](https://ddev.com/resources/featured-sponsors.svg) used in the [main project readme](https://github.com/ddev/ddev#wonderful-sponsors).
3. The [procedurally-generated](https://github.com/ddev/ddev.com-front-end/blob/main/src/pages/resources/featured-sponsors.svg.js) featured sponsors [light](https://ddev.com/resources/featured-sponsors.svg) and [dark](https://ddev.com/resources/featured-sponsors-darkmode.svg) SVG images used in the [main project readme](https://github.com/ddev/ddev#wonderful-sponsors).

If you’re adding a new item to the array, choose whichever position it should appear in and use the following format:

Expand Down
55 changes: 55 additions & 0 deletions public/logos/b13-darkmode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/logos/drupaleasy-darkmode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions public/logos/platform.sh-darkmode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions public/logos/undpaul-darkmode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions src/components/FeaturedSponsors.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import featuredSponsors from "../featured-sponsors.json"
* you need to add one.
*/
const nudges = {
"Platform.sh": "mt-12 h-11 dark:invert",
"Platform.sh": "mt-12 h-11",
Tag1: "h-9",
"Oliver Wand": "h-12 w-12",
DrupalEasy: "h-10 dark:invert",
b13: "dark:invert",
DrupalEasy: "h-10",
"Redfin Solutions": "h-16 w-16",
MacStadium: "h-15",
Lullabot: "h-9",
"Craft CMS": "h-11",
undpaul: "h-9 dark:invert",
undpaul: "h-9",
"1xINTERNET": "h-11",
}
Expand Down
8 changes: 4 additions & 4 deletions src/featured-sponsors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Platform.sh",
"type": "major",
"logo": "/logos/platform.sh.svg",
"darklogo": "/logos/platform.sh.svg",
"darklogo": "/logos/platform.sh-darkmode.svg",
"squareLogo": "/logos/platform.sh-square.svg",
"url": "https://platform.sh"
},
Expand Down Expand Up @@ -55,7 +55,7 @@
"name": "b13",
"type": "standard",
"logo": "/logos/b13.svg",
"darklogo": "/logos/b13.svg",
"darklogo": "/logos/b13-darkmode.svg",
"squareLogo": "/logos/b13.svg",
"url": "https://b13.com/",
"github": "b13"
Expand Down Expand Up @@ -91,7 +91,7 @@
"name": "DrupalEasy",
"type": "standard",
"logo": "/logos/drupaleasy.png",
"darklogo": "/logos/drupaleasy.png",
"darklogo": "/logos/drupaleasy-darkmode.png",
"squareLogo": "/logos/drupaleasy-square.svg",
"url": "https://www.drupaleasy.com/",
"github": "drupaleasy"
Expand Down Expand Up @@ -153,7 +153,7 @@
"name": "undpaul",
"type": "standard",
"logo": "/logos/undpaul.svg",
"darklogo": "/logos/undpaul.svg",
"darklogo": "/logos/undpaul-darkmode.svg",
"squareLogo": "/logos/undpaul-square.svg",
"url": "https://undpaul.de",
"github": "undpaul"
Expand Down
124 changes: 124 additions & 0 deletions src/pages/resources/featured-sponsors-darkmode.svg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import featuredSponsors from "../../featured-sponsors.json"
import sizeOf from "image-size"
import base64Img from "base64-img"

const baseUrl = import.meta.env.SITE

// Width of the composed SVG
const overallWidth = 814
// Maximum height a darklogo may have
const maxHeight = 50
// Maximum width a darklogo may have
const maxWidth = 200
// Horizontal padding between darklogos
const xPadding = 40
// Vertical padding between rows of darklogos
const yPadding = 20

/**
* Build an SVG response body with rows of evenly-spaced sponsor darklogos wrapped in anchors.
* @returns string
*/
const buildResponse = () => {
let images = []
let totalHeight = 0
let currentX = 0
let currentY = 0
let rowCount = 1

featuredSponsors.map((sponsor, index) => {
const dimensions = sizeOf("./public/" + sponsor.darklogo)

let [w, h] = getScaledImageDimensions(dimensions.width, dimensions.height)

if (currentX + w + xPadding > overallWidth) {
currentX = 0
currentY += maxHeight + yPadding
rowCount += 1
}

let yOffset = (maxHeight - h) / 2

images.push({
href: baseUrl + sponsor.darklogo,
path: `./public/${sponsor.darklogo}`,
x: currentX,
y: currentY + yOffset,
height: h,
width: w,
url: sponsor.url,
})

currentX += w + xPadding
})

totalHeight = (maxHeight + yPadding) * rowCount

let response = `
<svg
width="${overallWidth}"
height="${totalHeight}"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
>
`

images.map((image) => {
response += `
<a xlink:href="${image.url}" target="_blank">
<image href="${base64Img.base64Sync(image.path)}" x="${image.x}" y="${image.y}" height="${image.height}" width="${image.width}" />
</a>
`
})

response += `</svg>`

return response;
}

/**
* Take the original width and height of an image and proportionally scale it
* for optical balance in this layout.
* @param {*} width
* @param {*} height
* @returns [w, h]
*/
const getScaledImageDimensions = (width, height) => {
let h = height
let w = width
const ratio = w / h

if (ratio < 1) {
h = maxHeight
w = (maxHeight / height) * width
}

if (ratio === 1) {
h = maxHeight
w = maxHeight
}

if (ratio > 1) {
h = maxHeight
w = (maxHeight / height) * width
}

if (ratio > 2) {
h = maxHeight * 0.75
w = ((maxHeight * 0.75) / height) * width
}

if (ratio > 3) {
w = maxWidth
h = (maxWidth / width) * height
}

return [w, h];
}

export async function get({ params, request }) {
return {
body: buildResponse(),
}
}

0 comments on commit 0929497

Please sign in to comment.