-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from sucho-archiving/v2
v2.0
- Loading branch information
Showing
37 changed files
with
5,903 additions
and
4,722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
shamefully-hoist = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { spawn } from "child_process"; | ||
|
||
import { pEventIterator } from "p-event"; | ||
import { chromium } from "playwright"; | ||
|
||
import type { AstroIntegration } from "astro"; | ||
|
||
const delay = (milliseconds: number) => | ||
new Promise((resolve) => { | ||
setTimeout(resolve, milliseconds); | ||
}); | ||
|
||
const memewallOgImage = (): AstroIntegration => ({ | ||
name: "memewall-og-image", | ||
hooks: { | ||
"astro:build:start": async () => { | ||
const astroServerProcess = spawn("pnpm", ["dev"]); | ||
let astroServerUrl: string | undefined; | ||
|
||
const asyncIterator = pEventIterator(astroServerProcess.stdout, "data"); | ||
for await (const chunk of asyncIterator) { | ||
// wait for the Astro dev server to be ready and to report its URL | ||
if ( | ||
(astroServerUrl = chunk | ||
.toString() | ||
.match(/http:\/\/[\w\d]+:\d+\//)?.[0]) | ||
) { | ||
break; | ||
} | ||
} | ||
|
||
if (!astroServerUrl) { | ||
throw new Error("Server exited without reporting a URL!"); | ||
} | ||
|
||
console.log(` --> Spawned Astro server listening at ${astroServerUrl}`); | ||
|
||
const browser = await chromium.launch({ | ||
args: [ | ||
"--no-sandbox", | ||
"--disable-setuid-sandbox", | ||
"--disable-web-security", | ||
], | ||
}); | ||
|
||
const page = await browser.newPage(); | ||
await page.setViewportSize({ width: 1200, height: 630 }); | ||
await page.goto(astroServerUrl, { waitUntil: "networkidle" }); | ||
|
||
// `waitUntil: "networkidle"` seems to be inadequate | ||
console.log(` --> Waiting for the page to render before capturing...`); | ||
await delay(1000); | ||
|
||
await page.screenshot({ path: `./assets/open-graph.jpeg` }); | ||
|
||
await browser.close(); | ||
astroServerProcess.kill(); | ||
}, | ||
}, | ||
}); | ||
|
||
export { memewallOgImage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
diff --git a/api/utils/getImage.js b/api/utils/getImage.js | ||
index 12bc1a8fe664f77614d46df0619724239c07af60..147d0d012c06ec976eb90aa81883dd272c309971 100644 | ||
--- a/api/utils/getImage.js | ||
+++ b/api/utils/getImage.js | ||
@@ -37,7 +37,9 @@ export default async function ({ | ||
|
||
rest.aspect = `${imageWidth / imageHeight}`; | ||
|
||
- if (!fallbackFormat) { | ||
+ if (fallbackFormat === false) { | ||
+ fallbackFormat = format; | ||
+ } else if (!fallbackFormat) { | ||
fallbackFormat = imageFormat; | ||
} | ||
|
||
diff --git a/api/utils/getBreakpoints.js b/api/utils/getBreakpoints.js | ||
index 02a098e5d0415ca896b225fe6b235364d08af8f5..e04c2aa4c89d11556b751f82f27f41be177718cb 100644 | ||
--- a/api/utils/getBreakpoints.js | ||
+++ b/api/utils/getBreakpoints.js | ||
@@ -1,5 +1,5 @@ | ||
// @ts-check | ||
-import printWarning from "../../utils/printWarning.js"; | ||
+import log from "loglevel"; | ||
|
||
export default function getBreakpoints(breakpoints, imageWidth) { | ||
if (Array.isArray(breakpoints)) { | ||
@@ -12,10 +12,7 @@ export default function getBreakpoints(breakpoints, imageWidth) { | ||
if (breakpoints?.maxWidth) return breakpoints.maxWidth; | ||
|
||
if (imageWidth > 3840) { | ||
- printWarning({ | ||
- message: | ||
- "The width of the source image is greater than 3840px. The generated breakpoints will be capped at 3840px. If you need breakpoints larger than this, please pass the maxWidth option to the breakpoints property.", | ||
- }); | ||
+ log.debug("The width of the source image is greater than 3840px. The generated breakpoints will be capped at 3840px. If you need breakpoints larger than this, please pass the maxWidth option to the breakpoints property."); | ||
|
||
return 3840; | ||
} | ||
diff --git a/api/utils/getImage.js b/api/utils/getImage.js | ||
index 12bc1a8fe664f77614d46df0619724239c07af60..10f404af7f1f2b3553c25f9dda39c1d5649f1a48 100644 | ||
--- a/api/utils/getImage.js | ||
+++ b/api/utils/getImage.js | ||
@@ -5,6 +5,8 @@ import getImageSources from "./getImageSources.js"; | ||
import getProcessedImage from "./getProcessedImage.js"; | ||
import getArtDirectedImages from "./getArtDirectedImages.js"; | ||
|
||
+import log from "loglevel"; | ||
+ | ||
const imagesData = new Map(); | ||
|
||
export default async function ({ | ||
@@ -83,7 +85,7 @@ export default async function ({ | ||
|
||
const end = performance.now(); | ||
|
||
- console.log( | ||
+ log.debug( | ||
`Responsive Image sets generated for ${type} at ${args[0].src} in ${ | ||
end - start | ||
}ms` |
Oops, something went wrong.