Finally finish this enough to post

From here I will actually track changed with git but I just needed a base to work from.

RIP this attomic ass commit
This commit is contained in:
BuyMyMojo 2024-12-17 01:01:43 +11:00
parent 079e48c94e
commit 4bdb2ca436
Signed by: aria
GPG key ID: 19AB7AA462B8AB3B
48 changed files with 4693 additions and 657 deletions

View file

@ -0,0 +1,70 @@
> I use @11ty/eleventy-fetch for downloading the button images
> I have a `buttons_.yml` file in the same directory as this file, the root is an array of arrays so all buttons are split into tiers. plus the files that go into the build directory get a hash sum in their filename
```js
import * as crypto from 'node:crypto'
import * as fs from 'node:fs/promises'
import * as path from 'node:path'
import * as yaml from 'yaml'
import eleventyFetch from '@11ty/eleventy-fetch'
import { getURLHostname } from '../utils'
import buttonsFile from './buttons_.yml?raw'
async function process(buttons) {
buttons = await Promise.all(buttons.map(async button => {
let image
if (button.image.startsWith('./')) {
image = await fs.readFile(button.image)
} else {
image = await eleventyFetch(button.image, {
duration: '1w',
})
}
let hash = crypto.createHash('sha512')
hash.update(image)
let suffix = hash.digest('hex').slice(0, 12)
let imageURL = `/buttons/${button.ident}-${suffix}`
let imagePath = `public/${imageURL}`
await fs.mkdir(path.dirname(imagePath), { recursive: true })
await fs.writeFile(imagePath, image)
return {
width: 88,
height: 31,
...button,
alt: button.alt,
image: imageURL,
originalImage: button.image,
}
}))
buttons = buttons.toSorted((a, b) => {
if (a.priority !== b.priority) {
return a.priority - b.priority
}
let aHost = getURLHostname(a.url)
let bHost = getURLHostname(b.url)
if (aHost < bHost) {
return -1
} else if (aHost > bHost) {
return 1
} else {
return 0
}
})
return buttons
}
let tiers = yaml.parse(buttonsFile)
export const buttons = await Promise.all(
tiers.map(tier => process(tier)),
)
export const buttonsFlattened = buttons.flat()
``

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB