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

Fix featured sponsors SVG (404 error) #192

Merged
merged 3 commits into from
Apr 16, 2024
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
102 changes: 0 additions & 102 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"marked": "^9.0.3",
"mdast-util-to-string": "^4.0.0",
"nanoid": "^5.0.1",
"node-base64-image": "^2.0.6",
"octokit": "^3.1.1",
"postcss-import": "^15.1.0",
"postcss-nested": "^6.0.0",
Expand Down
21 changes: 15 additions & 6 deletions src/pages/resources/featured-sponsors-darkmode.svg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import featuredSponsors from "../../featured-sponsors.json"
import fs from "fs"
import path from "path"
import sizeOf from "image-size"
import {encode} from 'node-base64-image';

const baseUrl = import.meta.env.SITE

Expand Down Expand Up @@ -67,7 +68,7 @@ const buildResponse = () => {
images.map((image) => {
response += `
<a xlink:href="${image.url}" target="_blank">
<image href="${encode(image.path)}" x="${image.x}" y="${image.y}" height="${image.height}" width="${image.width}" />
<image href="${imgToBase64(image.path)}" x="${image.x}" y="${image.y}" height="${image.height}" width="${image.width}" />
</a>
`
})
Expand All @@ -77,6 +78,16 @@ const buildResponse = () => {
return response;
}

function imgToBase64(filePath) {
let extname = path.extname(filePath).slice(1) || 'png';

if (extname === 'svg') {
extname = "svg+xml"
}

return 'data:image/' + extname + ';base64,' + fs.readFileSync(filePath).toString('base64');
}

/**
* Take the original width and height of an image and proportionally scale it
* for optical balance in this layout.
Expand Down Expand Up @@ -117,8 +128,6 @@ const getScaledImageDimensions = (width, height) => {
return [w, h];
}

export async function get({ params, request }) {
return {
body: buildResponse(),
}
export async function GET({ params, request }) {
return new Response(buildResponse())
}
21 changes: 15 additions & 6 deletions src/pages/resources/featured-sponsors.svg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import featuredSponsors from "../../featured-sponsors.json"
import fs from "fs"
import path from "path"
import sizeOf from "image-size"
import {encode} from 'node-base64-image';

const baseUrl = import.meta.env.SITE

Expand Down Expand Up @@ -67,7 +68,7 @@ const buildResponse = () => {
images.map((image) => {
response += `
<a xlink:href="${image.url}" target="_blank">
<image href="${encode(image.path)}" x="${image.x}" y="${image.y}" height="${image.height}" width="${image.width}" />
<image href="${imgToBase64(image.path)}" x="${image.x}" y="${image.y}" height="${image.height}" width="${image.width}" />
</a>
`
})
Expand All @@ -77,6 +78,16 @@ const buildResponse = () => {
return response;
}

function imgToBase64(filePath) {
let extname = path.extname(filePath).slice(1) || 'png';

if (extname === 'svg') {
extname = "svg+xml"
}

return 'data:image/' + extname + ';base64,' + fs.readFileSync(filePath).toString('base64');
}

/**
* Take the original width and height of an image and proportionally scale it
* for optical balance in this layout.
Expand Down Expand Up @@ -117,8 +128,6 @@ const getScaledImageDimensions = (width, height) => {
return [w, h];
}

export async function get({ params, request }) {
return {
body: buildResponse(),
}
export async function GET({ params, request }) {
return new Response(buildResponse())
}
Loading