Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

4.8 KB
Raw Blame
---
// The home page's teaser for the latest weekly challenge: its first three winners as thumbnails (the numbered places,
// then runners-up, in the file's order), and a link to the challenge's page.
// The labels are UI strings and the dates follow the page's language; the theme and the artists' names stay as the
// challenge's file gives them.
import ArrowRight from '@lucide/astro/icons/arrow-right';
import type { CollectionEntry } from 'astro:content';
import { Image } from 'astro:assets';

import { withBase } from '../base-path';
import { challengePath, formatChallengeDates } from '../challenges.mjs';
import { pageLang } from './memory/page-lang.mjs';

type Props = {
  challenge: CollectionEntry<'challenges'>;
};

const { challenge } = Astro.props;
const { t } = Astro.locals;
const { week, theme, startDate, endDate } = challenge.data;
const placeLabels: Record<string | number, string> = {
  1: t('home.challenge.first'),
  2: t('home.challenge.second'),
  3: t('home.challenge.third'),
  'runner-up': t('home.challenge.runnerUp'),
  honourable: t('home.challenge.honourable'),
};
// The schema keeps winners in display order.
const top = challenge.data.winners.slice(0, 3);
const when =
  week === undefined
    ? formatChallengeDates(startDate, endDate, pageLang(Astro.locals))
    : t('home.challenge.week', { week });
---

<div class="strip not-content">
  <div class="strip__text">
    <h3>{t('home.challenge.title')}</h3>
    <p>
      {when} · <span lang="en">{theme}</span>
    </p>
    <a class="more" href={withBase(challengePath(challenge.id), import.meta.env.BASE_URL)}>
      {t('home.challenge.link')}
      <ArrowRight class="nudge" size={14} aria-hidden="true" />
    </a>
  </div>
  <ul class="strip__winners" role="list">
    {
      top.map((winner) => (
        <li>
          {/* The caption credits the artwork; the challenge's page describes it. */}
          <Image
            src={winner.image}
            alt=""
            widths={[160, 320, 480].filter((width) => width < winner.image.width).concat(winner.image.width)}
            sizes="(min-width: 50rem) 10rem, 30vw"
          />
          <span class:list={['place', { 'place--first': winner.place === 1 }]}>{placeLabels[winner.place]}</span>
          <span class="artist" lang="en">{winner.artist}</span>
        </li>
      ))
    }
  </ul>
</div>

<style>
  .strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.25rem 2rem;
    padding: 1rem;
    border: 1px solid var(--docs-border);
    border-radius: var(--docs-radius-container);
    background-color: var(--docs-surface);
  }

  .strip__text {
    display: flex;
    flex: 1 1 14rem;
    flex-direction: column;
    gap: 0.375rem;
    padding-inline: 0.5rem;

    h3 {
      margin: 0;
      color: var(--docs-text-strong);
      font-size: 1.25rem;
      font-weight: 600;
      letter-spacing: -0.01em;
      line-height: 1.3;
    }

    p {
      margin: 0;
      color: var(--docs-text-muted);
      font-size: 0.9375rem;
    }
  }

  .more {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.25rem;
    color: var(--docs-accent);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;

    &:hover {
      color: var(--docs-accent-text);
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    .nudge {
      transition: translate 150ms ease;
    }

    .more:is(:hover, :focus-visible) > .nudge {
      translate: 2px 0;
    }
  }

  .strip__winners {
    display: grid;
    flex: 2 1 24rem;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;

    li {
      position: relative;
      display: flex;
      flex-direction: column;
      gap: 0.375rem;
      min-width: 0;
    }

    /* Thumbnails crop to a common shape; the challenge's page shows each artwork whole. */
    img {
      display: block;
      width: 100%;
      height: auto;
      aspect-ratio: 4 / 3;
      object-fit: cover;
      border-radius: var(--docs-radius-lg);
      background-color: var(--docs-control);
    }
  }

  .place {
    position: absolute;
    top: 0.375rem;
    left: 0.375rem;
    display: inline-flex;
    align-items: center;
    height: 1.25rem;
    padding: 0 0.375rem;
    border: 1px solid var(--docs-border-strong);
    border-radius: var(--docs-radius);
    background-color: var(--docs-control);
    color: var(--docs-text-strong);
    font-size: 0.6875rem;
    font-weight: 600;
    white-space: nowrap;
  }

  .place--first {
    border-color: var(--docs-accent);
    background-color: var(--docs-accent);
    color: var(--docs-accent-contrast);
  }

  .artist {
    overflow: hidden;
    color: var(--docs-text-muted);
    font-size: 0.8125rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
</style>