Skip to content

Commit 0339e62

Browse files
authored
Merge pull request #17 from sucho-archiving/v2
v2.0
2 parents 80a0c5a + d156e54 commit 0339e62

37 files changed

+5903
-4722
lines changed

.github/workflows/update-media-and-deploy-site.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ jobs:
1515
uses: actions/setup-node@v3
1616
with:
1717
node-version: 18
18-
cache: "yarn"
18+
cache: "pnpm"
1919

2020
- name: Install Dependencies
21-
run: yarn install --frozen-lockfile
21+
run: pnpm install --frozen-lockfile
2222

2323
- name: Update Media Assets
24-
run: yarn update-media
24+
run: pnpm update-media
2525

2626
- name: Check for Changes
2727
id: check
@@ -43,13 +43,6 @@ jobs:
4343
git commit -m "Automated Media Update $(date +"%Y-%m-%d")"
4444
git push --force
4545
46-
# if building the site, graphicsmagick is needed for creating derivative images
47-
- name: Install graphicsmagick
48-
if: steps.check.outputs.has_new_media == 'true'
49-
run: |
50-
sudo apt-get update
51-
sudo apt-get install -y graphicsmagick
52-
5346
- name: Build and Deploy Site
5447
if: steps.check.outputs.has_new_media == 'true'
55-
run: yarn gh-deploy
48+
run: pnpm gh-deploy

.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ dist/
55
node_modules/
66

77
# logs
8-
npm-debug.log*
9-
yarn-debug.log*
10-
yarn-error.log*
118
pnpm-debug.log*
129

13-
14-
# environment variables
15-
.env
16-
.env.production
17-
1810
# macOS-specific files
1911
.DS_Store
2012

21-
2213
.vscode/
14+
*.cpuprofile
15+
16+
# assets generated at build-time
17+
assets/

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoist = true

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ The codebase in this repository uses the [Astro static site builder](https://ast
1818

1919
## Dataset and Asset Generation
2020

21-
When `yarn dev` or `yarn build` is run, the build process will fetch and parse the latest data from the curated "Ready" tab on the submission sheet and synchronize the local media cache with the contents of the submissions folder on Google Drive. The identifiers for the submission sheet and tab, etc. are found in [`src/config.mjs`](src/config.mjs).
21+
When `pnpm dev` or `pnpm build` is run, the build process will fetch and parse the latest data from the curated "Ready" tab on the submission sheet and synchronize the local media cache with the contents of the submissions folder on Google Drive. The identifiers for the submission sheet and tab, etc. are found in [`src/config.mjs`](src/config.mjs).
2222

23-
Running `yarn update-media` will fetch and synchronize the media files and then exit, and `yarn print-dataset` will fetch and parse the data and media files and then output the parsed data to `stdout` (it can take arguments to output different parts of the parsed dataset -- see [`src/dataset.mjs`](src/dataset.mjs) for details).
23+
Running `pnpm update-media` will fetch and synchronize the media files and then exit, and `pnpm print-dataset` will fetch and parse the data and media files and then output the parsed data to `stdout` (it can take arguments to output different parts of the parsed dataset -- see [`src/dataset.mjs`](src/dataset.mjs) for details).
2424

2525

2626
## Development
@@ -30,24 +30,26 @@ Running `yarn update-media` will fetch and synchronize the media files and then
3030

3131
### Live-Updating Development Build
3232

33-
1. Run `yarn` to install dependencies.
34-
1. Run `yarn dev` to start the development server and reflect your changes to the page as you save files.
33+
1. Run `pnpm install` to install dependencies.
34+
1. Run `pnpm dev` to start the development server and reflect your changes to the page as you save files.
3535
1. Visit `http://localhost:3000/` in your browser.
3636

3737

3838
### Static Build
3939

40-
1. Run `yarn build` to create a production build (the deployment url can be set in [`astro.config.mjs`](astro.config.mjs) but only matters for OpenGraph/Twitter metadata etc.).
41-
2. Run `yarn preview` to serve the contents of `dist/` using an http server at `http://localhost:3000/`.
40+
1. Run `pnpm build` to create a production build (the deployment url can be set in [`astro.config.mjs`](astro.config.mjs) but only matters for OpenGraph/Twitter metadata etc.).
41+
2. Run `pnpm preview` to serve the contents of `dist/` using an http server at `http://localhost:3000/`.
4242

4343

4444
### Deploy to GH Pages
4545

46-
1. Users with write permissions to this repository can run `yarn gh-deploy` from the project root to install dependencies, build the static assets, and update and push to the `gh-pages` branch.
46+
1. Users with write permissions to this repository can run `pnpm gh-deploy` from the project root to install dependencies, build the static assets, and update and push to the `gh-pages` branch.
4747
**Note:** the GitHub Actions workflow at [`.github/workflows/update-media-and-deploy-site.yml`](.github/workflows/update-media-and-deploy-site.yml) runs once a day and will automatically acquire new media, update the repository, and build and deploy the site as appropriate -- manual deploys should not generally be required.
4848

4949

5050
### Additional Development Commands
5151

52-
* `yarn update-media` (requires `node >= v18`) will fetch the spreadsheet, update the local working tree with any new (or missing) media files fetched from Google Drive, and delete any media files from `meme_media/` that do not correspond to records in the spreadsheet.
53-
* `yarn print-dataset` (requires `node >= v18`) will fetch the spreadsheet, process the data and media files, and then output the parsed dataset to `stdout` in JSON format.
52+
* `pnpm update-media` (requires `node >= v18`) will fetch the spreadsheet, update the local working tree with any new (or missing) media files fetched from Google Drive, and delete any media files from `meme_media/` that do not correspond to records in the spreadsheet.
53+
* `pnpm print-dataset` (requires `node >= v18`) will fetch the spreadsheet, process the data and media files, and then output the parsed dataset to `stdout` in JSON format.
54+
55+
* All `pnpm` commands can be prepended with `LOG_LEVEL=DEBUG` for additional debugging information on the console.

astro.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { defineConfig } from "astro/config";
2+
import svelte from "@astrojs/svelte";
23
import { astroImageTools } from "astro-imagetools";
34

5+
import { memewallOgImage } from "./integrations/memewall-og-image.ts";
6+
47
// https://astro.build/config
58
export default defineConfig({
69
site: "https://memes.sucho.org/",
710
trailingSlash: "always",
8-
integrations: [astroImageTools],
11+
integrations: [astroImageTools, svelte(), memewallOgImage()],
912
vite: {
1013
ssr: { external: ["neat-csv"] },
1114
optimizeDeps: { exclude: ["neat-csv"] },

bin/astro-gh-deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ current_branch=$(git rev-parse --abbrev-ref HEAD);
1717

1818
unclean=$(git status --porcelain) && [ -n "$unclean" ] && abort "Working directory is not clean -- aborting!";
1919

20-
yarn build;
20+
pnpm build;
2121
[ ! -d "$BUILD_FOLDER" ] && abort "'$BUILD_FOLDER' does not exist -- aborting!";
2222

2323
COMMIT_MESSAGE="Deploy from $(git log -n 1 --format="%h" HEAD) at $(date +"%Y-%m-%d %H:%M:%S %Z")";

integrations/memewall-og-image.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { spawn } from "child_process";
2+
3+
import { pEventIterator } from "p-event";
4+
import { chromium } from "playwright";
5+
6+
import type { AstroIntegration } from "astro";
7+
8+
const delay = (milliseconds: number) =>
9+
new Promise((resolve) => {
10+
setTimeout(resolve, milliseconds);
11+
});
12+
13+
const memewallOgImage = (): AstroIntegration => ({
14+
name: "memewall-og-image",
15+
hooks: {
16+
"astro:build:start": async () => {
17+
const astroServerProcess = spawn("pnpm", ["dev"]);
18+
let astroServerUrl: string | undefined;
19+
20+
const asyncIterator = pEventIterator(astroServerProcess.stdout, "data");
21+
for await (const chunk of asyncIterator) {
22+
// wait for the Astro dev server to be ready and to report its URL
23+
if (
24+
(astroServerUrl = chunk
25+
.toString()
26+
.match(/http:\/\/[\w\d]+:\d+\//)?.[0])
27+
) {
28+
break;
29+
}
30+
}
31+
32+
if (!astroServerUrl) {
33+
throw new Error("Server exited without reporting a URL!");
34+
}
35+
36+
console.log(` --> Spawned Astro server listening at ${astroServerUrl}`);
37+
38+
const browser = await chromium.launch({
39+
args: [
40+
"--no-sandbox",
41+
"--disable-setuid-sandbox",
42+
"--disable-web-security",
43+
],
44+
});
45+
46+
const page = await browser.newPage();
47+
await page.setViewportSize({ width: 1200, height: 630 });
48+
await page.goto(astroServerUrl, { waitUntil: "networkidle" });
49+
50+
// `waitUntil: "networkidle"` seems to be inadequate
51+
console.log(` --> Waiting for the page to render before capturing...`);
52+
await delay(1000);
53+
54+
await page.screenshot({ path: `./assets/open-graph.jpeg` });
55+
56+
await browser.close();
57+
astroServerProcess.kill();
58+
},
59+
},
60+
});
61+
62+
export { memewallOgImage };

package.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sucho/meme-wall",
3-
"version": "1.4.2",
3+
"version": "2.0-rc-1",
44
"private": true,
55
"scripts": {
66
"dev": "astro dev",
@@ -12,22 +12,32 @@
1212
"gh-deploy": "CNAME=memes.sucho.org bin/astro-gh-deploy.sh"
1313
},
1414
"devDependencies": {
15+
"@astrojs/svelte": "^2.0.1",
1516
"astro": "^2.0.4",
16-
"astro-imagetools": "^0.7.6",
17+
"astro-imagetools": "^0.8.1",
1718
"csv-writer": "^1.6.0",
18-
"gm": "^1.25.0",
1919
"image-size": "^1.0.2",
20+
"loglevel": "^1.8.1",
2021
"neat-csv": "^7.0.0",
22+
"p-event": "^5.0.1",
23+
"playwright": "^1.31.2",
2124
"postcss-nested": "^6.0.0",
22-
"prettier-plugin-astro": "^0.8.0"
25+
"prettier-plugin-astro": "^0.8.0",
26+
"svelte": "^3.55.1"
2327
},
2428
"dependencies": {
29+
"@floating-ui/dom": "^1.2.1",
2530
"@fontsource/jost": "^4.5.13",
2631
"charts.css": "^0.9.0"
2732
},
28-
"resolutions": {
29-
"astro-imagetools/file-type": "^17.1.3",
30-
"file-type": "^16.5.4",
31-
"sharp": "^0.30.6"
33+
"pnpm": {
34+
"overrides": {
35+
"astro-imagetools>file-type": "^17.1.3",
36+
"file-type": "^16.5.4",
37+
"sharp": "^0.30.6"
38+
},
39+
"patchedDependencies": {
40+
"astro-imagetools@0.8.1": "patches/astro-imagetools@0.8.1.patch"
41+
}
3242
}
3343
}

patches/astro-imagetools@0.8.1.patch

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
diff --git a/api/utils/getImage.js b/api/utils/getImage.js
2+
index 12bc1a8fe664f77614d46df0619724239c07af60..147d0d012c06ec976eb90aa81883dd272c309971 100644
3+
--- a/api/utils/getImage.js
4+
+++ b/api/utils/getImage.js
5+
@@ -37,7 +37,9 @@ export default async function ({
6+
7+
rest.aspect = `${imageWidth / imageHeight}`;
8+
9+
- if (!fallbackFormat) {
10+
+ if (fallbackFormat === false) {
11+
+ fallbackFormat = format;
12+
+ } else if (!fallbackFormat) {
13+
fallbackFormat = imageFormat;
14+
}
15+
16+
diff --git a/api/utils/getBreakpoints.js b/api/utils/getBreakpoints.js
17+
index 02a098e5d0415ca896b225fe6b235364d08af8f5..e04c2aa4c89d11556b751f82f27f41be177718cb 100644
18+
--- a/api/utils/getBreakpoints.js
19+
+++ b/api/utils/getBreakpoints.js
20+
@@ -1,5 +1,5 @@
21+
// @ts-check
22+
-import printWarning from "../../utils/printWarning.js";
23+
+import log from "loglevel";
24+
25+
export default function getBreakpoints(breakpoints, imageWidth) {
26+
if (Array.isArray(breakpoints)) {
27+
@@ -12,10 +12,7 @@ export default function getBreakpoints(breakpoints, imageWidth) {
28+
if (breakpoints?.maxWidth) return breakpoints.maxWidth;
29+
30+
if (imageWidth > 3840) {
31+
- printWarning({
32+
- message:
33+
- "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.",
34+
- });
35+
+ 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.");
36+
37+
return 3840;
38+
}
39+
diff --git a/api/utils/getImage.js b/api/utils/getImage.js
40+
index 12bc1a8fe664f77614d46df0619724239c07af60..10f404af7f1f2b3553c25f9dda39c1d5649f1a48 100644
41+
--- a/api/utils/getImage.js
42+
+++ b/api/utils/getImage.js
43+
@@ -5,6 +5,8 @@ import getImageSources from "./getImageSources.js";
44+
import getProcessedImage from "./getProcessedImage.js";
45+
import getArtDirectedImages from "./getArtDirectedImages.js";
46+
47+
+import log from "loglevel";
48+
+
49+
const imagesData = new Map();
50+
51+
export default async function ({
52+
@@ -83,7 +85,7 @@ export default async function ({
53+
54+
const end = performance.now();
55+
56+
- console.log(
57+
+ log.debug(
58+
`Responsive Image sets generated for ${type} at ${args[0].src} in ${
59+
end - start
60+
}ms`

0 commit comments

Comments
 (0)