-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Genuary: 2023 artwork showcase (#761)
* Add Genuary page with Placekitten data * Add update_genuary workflow (#764) * Update Genuary 2023 📆 ✨ 🎨 * Add video support * Support users with disabled JS
- Loading branch information
1 parent
32a1c49
commit b80d3c2
Showing
16 changed files
with
948 additions
and
1 deletion.
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
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 |
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,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(); |
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,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; |
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,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" /> |
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,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; | ||
} |
Oops, something went wrong.