feat: randomize greeting from pool on homepage

This commit is contained in:
Benjamin Singleton 2026-02-09 21:23:28 -06:00 committed by Sheldon Cooper
parent 59674292be
commit 169ef685ce
3 changed files with 33 additions and 4 deletions

View file

@ -1,19 +1,20 @@
<script setup lang="ts">
import HomeSectionWrapper from "@/components/molecules/HomeSectionWrapper.vue";
import { useLocale } from "@/i18n";
import { GREETINGS, type Greeting } from "@/i18n/greeting";
import { localizeLayout } from "@/utils/localizeLayout";
import { randomElement } from "@/utils/random";
const locale = useLocale();
const greeting: Greeting = randomElement(GREETINGS);
</script>
<template>
<div>
<section class="hero is-primary">
<div class="hero-body">
<div class="title">BRÅTULA VIOSSA.NET MÅDE</div>
<div class="subtitle">
Hadjiplas per lera para Viossa glossa fu vi
</div>
<div class="title">{{ greeting.title }}</div>
<div class="subtitle">{{ greeting.subtitle }}</div>
</div>
</section>

View file

@ -0,0 +1,15 @@
export interface Greeting {
title: string;
subtitle: string;
}
export const GREETINGS = [
{
title: "BRÅTULA VIOSSA.NET MÅDE",
subtitle: "Hadjiplas per lera para Viossa glossa fu vi",
},
{
title: "akka po viossa.net!",
subtitle: "kenomasufobo o gen wi tropos o viosox",
},
] as const satisfies Greeting[];

View file

@ -0,0 +1,13 @@
export function randomMaybeElement<Elements extends unknown[]>(
elements: Elements,
): Elements[number] | undefined {
const index = Math.floor(Math.random() * elements.length);
return elements[index];
}
export function randomElement<Elements extends [unknown, ...unknown[]]>(
elements: Elements,
): Elements[number] {
// SAFETY: because there is always at least one element, undefined will never be returned
return randomMaybeElement(elements) as Elements[number];
}