feat: randomize greeting from pool on homepage
This commit is contained in:
parent
59674292be
commit
169ef685ce
3 changed files with 33 additions and 4 deletions
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
15
apps/vdn-static/src/i18n/greeting.ts
Normal file
15
apps/vdn-static/src/i18n/greeting.ts
Normal 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[];
|
||||
13
apps/vdn-static/src/utils/random.ts
Normal file
13
apps/vdn-static/src/utils/random.ts
Normal 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];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue