Skip to content

Commit

Permalink
adjust artwork for shows after midnight so they have artwork for the …
Browse files Browse the repository at this point in the history
…previous day (#166)
  • Loading branch information
antiantivirus authored Jan 24, 2025
1 parent 625a1a6 commit 3dd5e3b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,19 @@ export const showArtworkURL = (

formattedArtists = encodeURIComponent(formattedArtists);

const startDate = dayjs(values.datetime).utc();
const endDate = dayjs(values.datetimeEnd).utc();

// adjusted date ensures that shows in the early hours have previous days date and colour
const adjustedDate = startDate.subtract(4, "hours");

const showDate = adjustedDate.format("ddd DD MMM");
const startTime = startDate.format("HH:mm");
const endTime = endDate.format("HH:mm");

// Format the date and time
const date = encodeURIComponent(
`${dayjs(values.datetime).utc().format("ddd DD MMM / HH:mm")}-${dayjs(
values.datetimeEnd
)
.utc()
.format("HH:mm")} (CET)`
const uriEncodedDate = encodeURIComponent(
showDate + " / " + startTime + "-" + endTime
);

const colours = [
Expand Down Expand Up @@ -249,19 +255,19 @@ export const showArtworkURL = (
];

// Get the day of the month
const dayOfMonth = dayjs(values.datetime).utc().date();
const dayOfMonth = adjustedDate.date();

// Get a color from the colours array based on the day of the month
const colour = colours[dayOfMonth % colours.length];

// Determine the base URL based on the environment
const baseUrl =
process.env.NODE_ENV === "development"
? "https://055a-2a02-8109-b68b-5000-a93d-b89a-5989-3996.ngrok-free.app/"
? "https://7a2a-194-126-177-76.ngrok-free.app/"
: process.env.NEXT_PUBLIC_SITE_URL;

// Set URL for social image
const url = `${baseUrl}/api/automated-artwork?title=${title}&artists=${formattedArtists}&date=${date}&images=${images}&colour=${encodeURIComponent(
const url = `${baseUrl}/api/automated-artwork?title=${title}&artists=${formattedArtists}&date=${uriEncodedDate}&images=${images}&colour=${encodeURIComponent(
colour
)}`;

Expand Down

0 comments on commit 3dd5e3b

Please sign in to comment.