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

Genuary: 2023 artwork showcase #761

Merged
merged 19 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 18 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
50 changes: 50 additions & 0 deletions .github/workflows/update_genuary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Update Genuary

on:
workflow_dispatch:
schedule:
# We want '0 9 * 1 *' in Pacific Time, but GitHub Actions doesn't support timezones.
# So we use '0 17 * 1 *' in UTC, which is 9 AM in Pacific Time.
- cron: '0 17 * * *'

jobs:
update-genuary:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- run: |
go run github.com/ethanthatonekid/pins@latest \
get -o /tmp/pins $GUILD_ID "channel_parent_id == $CHANNEL_ID"
env:
GUILD_ID: ${{ secrets.GUILD_ID }}
CHANNEL_ID: ${{ secrets.GENUARY_CHANNEL_ID }}
DISCORD_TOKEN: ${{ secrets.GENUARY_DISCORD_TOKEN }}

- id: transform-genuary
run: |
year=$(date +%Y)
echo "year=$year" >> $GITHUB_OUTPUT

node scripts/transform-genuary.js /tmp/pins/*.json \
> "src/routes/(site)/genuary/$year/data.json"

if git diff --exit-code --quiet; then
echo "updated=0" >> $GITHUB_OUTPUT
else
echo "updated=1" >> $GITHUB_OUTPUT
fi

- if: steps.transform-genuary.outputs.updated == 1
uses: peter-evans/create-pull-request@v4
with:
title: |-
Update Genuary ${{ steps.transform-genuary.outputs.year }} :calendar: :sparkles: :art:
body: |-
This pull request was automatically generated by GitHub Actions.

:sparkles: :sparkles: :sparkles:
commit-message: |-
Update Genuary ${{ steps.transform-genuary.outputs.year }} :calendar: :sparkles: :art:
labels: genuary
branch: genuary
50 changes: 50 additions & 0 deletions scripts/transform-genuary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as fs from 'node:fs/promises';

async function main() {
const year = new Date().getFullYear();
const filepath = process.argv[2];
const content = JSON.parse(await fs.readFile(filepath));

let out = [];
for (const pin of content.pins) {
if (!pin.attachments) {
continue;
}

const attachment = pin.attachments[0];
const src = attachment.proxy_url || null;
const alt = content.channel_names[pin.channel_id] || '';
if (!/^(\d+) /.test(alt)) {
continue;
}

let view = 'normal';
switch (true) {
case attachment.width * 1.2 > attachment.height: {
view = 'wide';
break;
}
case attachment.height * 1.2 > attachment.width: {
view = 'tall';
break;
}
}

out.push({
src,
alt,
view,
during_challenge: pin.timestamp.startsWith(`${year}-01-`),
});
}

out.sort((a, b) => {
const na = a.alt.match(/^(\d+) /);
const nb = b.alt.match(/^(\d+) /);
return parseInt(na) - parseInt(nb);
});

console.log(JSON.stringify(out, null, 2));
}

main();
33 changes: 33 additions & 0 deletions src/routes/(site)/genuary/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { RequestEvent } from '@sveltejs/kit';

/**
* The server-side load function for Genuary.
*
* Redirects to the latest year on file.
*/
export async function GET({ url }: RequestEvent) {
const years = await import.meta.glob('./*/+page.svelte', { eager: true, as: 'raw' });
const latest = findLatest(Object.keys(years).map(fromKey));
const destination = new URL(`/genuary/${latest}`, url);
return Response.redirect(destination, 302);
}

/** Example: key === "./2023/+page.svelte" */
function fromKey(key: string): number {
const match = key.match(/\/(\d{4})\//);
if (!match) {
return -Infinity;
}
return Number(match[1]);
}

function findLatest(items: number[]): number {
const found = items.sort((a, b) => a - b).pop();
if (found === undefined) {
return EARLIEST;
}

return found;
}

const EARLIEST = 2023;
8 changes: 8 additions & 0 deletions src/routes/(site)/genuary/2023/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script lang="ts">
import type { PageData } from './$types';
import GenuaryPage from '../genuary-page.svelte';

export let data: PageData;
</script>

<GenuaryPage data={data.pieces} year="2023" />
10 changes: 10 additions & 0 deletions src/routes/(site)/genuary/2023/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { CollagePageData } from '../collage';
import { pageDataFrom } from '../collage';

import { default as GENUARY_2023_PIECES } from './data.json' assert { type: 'json' };

const GENUARY_2023_PAGE_DATA = pageDataFrom(GENUARY_2023_PIECES as CollagePageData['pieces']);

export async function load(): Promise<CollagePageData> {
return GENUARY_2023_PAGE_DATA;
}
Loading