From 77d0b2acd5a00c642fbbe804eb7ee3edffdaceed Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Thu, 5 Sep 2024 00:14:27 -0600 Subject: Add code for the buttons --- app/page.tsx | 153 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 125 insertions(+), 28 deletions(-) (limited to 'app/page.tsx') diff --git a/app/page.tsx b/app/page.tsx index 507f1d7..229a803 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,43 +1,140 @@ +import fs from 'node:fs/promises' +import path from 'node:path' + import Link from 'next/link' import styles from '~/styles/index.module.css' +import sharp from 'sharp' + +const mimes = { + jpg: 'image/jpeg', + jpeg: 'image/jpeg', + png: 'image/png', + bmp: 'image/bmp', + gif: 'image/gif' +} + +export default async function Index() { + const buttonDir = 'images/buttons/' + const buttonFiles = (await fs.readdir(path.join(process.cwd(), buttonDir)).catch(() => {}) || []) + .filter(buttonName => buttonName.match(/\.(png|gif|jpg|jpeg)$/)) + + const buttonLinks = (await fs.readFile(path.join(process.cwd(), 'images/buttons/urls.txt'), {encoding: 'utf8'}).catch(() => {}) || '') + .split('\n').filter(line => !!line) + .map(line => line.match(/^([^:]+):\s+(.*)$/)) + .filter(match => !!match) + .reduce((acc,[_, name, url]) => ({...acc, [name]: url}), {}) + + const buttons = await Promise.all(buttonFiles.map(async buttonFile => { + const origImageData = await fs.readFile(path.join(process.cwd(), buttonDir, buttonFile)) + let preview = null + + const metadata = await sharp(origImageData, {pages: -1}).metadata() + + // Generate preview if there's more than one frame + if(metadata.pages > 1) { + preview = await sharp(origImageData, {pages: 1}) + .png({quality: 80, force: true}) + .toBuffer() + } + + return { + name: buttonFile.split('.').slice(0, -1).join('.'), + mime: mimes[buttonFile.split('.').at(-1)] || 'image/*', + url: buttonLinks[buttonFile], + data: origImageData.toString('base64'), + preview: preview?.toString('base64') + } + })) + + const friendButtons = buttons.filter(button => button.name !== 'tempest') + const ourButton = buttons.filter(button => button.name === 'tempest')[0] -export default function Index() { return ( -
-

- Hi, we're tempest! We're a median plural - system of six members, but most of the time you'll probably see us - operating as one -

+ <> +
+

+ Hi, we're tempest! We're a median plural + system of six members, but most of the time you'll probably see us + operating as one +

+ +

We like coding, VR, and making CG art

+ +

At a glance

+
+ Pronouns: + they/it + + Cohort: + millenial -

We like coding, VR, and making CG art

+ Orientation: + ace . . . ish -

At a glance

-
- Pronouns: - they/it + Partners: + several - Cohort: - millenial + Children: + two - Orientation: - ace . . . ish + Capitalize name: + not unless we're at work +
- Partners: - several +

+ Note: This is the information for our system in aggregate, + for individual info see our about page +

+
+ {friendButtons.length > 0 && ( +
+

Friends and other neighbors: + {ourButton && + + } +

+
+ {friendButtons.map(button => { + const image = {button.name} - Children: - two + const preview = button.preview ? {button.name} : null - Capitalize name: - not unless we're at work -
+ if(button.url) + return ( + {image}{preview} + ) + else + return ( + {image}{preview} + ) + })} +