Compare commits

..

2 Commits

6 changed files with 35 additions and 30 deletions

View File

@ -3,6 +3,7 @@
import Recipes from '$lib/components/Recipes.svelte';
import Search from './Search.svelte';
export let icons
export let active_icon
</script>
<style>
@ -15,10 +16,12 @@
box-shadow: 0em 0em 0.5em 0.2em rgba(0, 0, 0, 0.2);
}
a:hover,
a:focus-visible
a:focus-visible,
.active
{
--angle: 15deg;
animation: shake 0.5s ease forwards;
background-color: var(--nord2);
}
.flex{
display:flex;
@ -61,11 +64,10 @@
}
</style>
<slot name="test"></slot>
<div class=flex>
{#each icons as icon}
<a href="/rezepte/icon/{icon}">{icon}</a>
{#each icons as icon, i}
<a class:active={active_icon == icon} href="/rezepte/icon/{icon}">{icon}</a>
{/each}
</div>
<section>

View File

@ -58,18 +58,22 @@ function findGCD(a, b) {
return findGCD(b, a % b);
}
// For portions, not sure whether to keep or let it be
function multiplyFirstNumberInString(inputString, constant) {
const firstNumberRegex = /\d+(?:[\.,]\d+)?/;
const match = inputString.match(firstNumberRegex);
if (match) {
const number = match[0].includes(',') ? match[0].replace(/\./g, '').replace(',', '.') : match[0];
// "1-2 Kuchen (Durchmesser: 26cm", constant=2 -> "2-4 Kuchen (Durchmesser: 26cm)"
function multiplyFirstAndSecondNumbers(inputString, constant) {
const regex = /(\d+(?:[\.,]\d+)?)(\s*-\s*\d+(?:[\.,]\d+)?)?/;
return inputString.replace(regex, (match, firstNumber, secondNumber) => {
const numbersToMultiply = [firstNumber];
if (secondNumber) {
numbersToMultiply.push(secondNumber.replace(/-\s*/, ''));
}
const multipliedNumbers = numbersToMultiply.map(number => {
const multiplied = (parseFloat(number) * constant).toString();
const rounded = parseFloat(multiplied).toString();
const result = match[0].includes(',') ? rounded.replace('.', ',') : rounded;
return inputString.replace(firstNumberRegex, result);
}
return inputString;
const result = number.includes(',') ? rounded.replace('.', ',') : rounded;
return result;
});
return multipliedNumbers.join('-')
});
}
function adjust_amount(string, multiplier){
@ -130,7 +134,7 @@ button.selected{
<div class=ingredients>
{#if data.portions}
<h3>Portionen:</h3>
{@html convertFloatingPointToFraction(multiplyFirstNumberInString(data.portions, multiplier))}
{@html convertFloatingPointToFraction(multiplyFirstAndSecondNumbers(data.portions, multiplier))}
{/if}
<h3>Menge anpassen:</h3>

View File

@ -4,8 +4,10 @@
import Search from './Search.svelte';
let months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]
let month : number;
</script>
export let active_index;
console.log(active_index)
</script>
<style>
a.month{
text-decoration: unset;
@ -18,9 +20,11 @@ a.month{
min-width: 4em;
text-align: center;
}
a.month:hover{
transform: scale(1.1,1.1);
background-color: var(--red);
a.month:hover,
.active
{
transform: scale(1.1,1.1) !important;
background-color: var(--red) !important;
}
.months{
display:flex;
@ -32,11 +36,9 @@ a.month:hover{
}
</style>
<slot name="test"></slot>
<div class=months>
{#each months as month, i}
<a class=month href="/rezepte/season/{i+1}">{month}</a>
<a class:active={i == active_index} class=month href="/rezepte/season/{i+1}">{month}</a>
{/each}
</div>
<section>

View File

@ -8,8 +8,7 @@
export let data: PageData;
import { rand_array } from '$lib/js/randomize';
</script>
<IconLayout icons={data.icons}>
<h2 slot=test>Rezepte mit {data.icon}</h2>
<IconLayout icons={data.icons} active_icon={data.icon} >
<Recipes slot=recipes>
{#each rand_array(data.season) as recipe}
<Card {recipe} icon_override=true></Card>

View File

@ -11,8 +11,7 @@
import { rand_array } from '$lib/js/randomize';
</script>
<SeasonLayout>
<h2 slot=test>Rezepte des Monats </h2>
<SeasonLayout active_index={current_month-1}>
<Recipes slot=recipes>
{#each rand_array(data.season) as recipe}
<Card {recipe} {current_month}></Card>

View File

@ -9,8 +9,7 @@
let months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]
import { rand_array } from '$lib/js/randomize';
</script>
<SeasonLayout>
<h2 slot=test>Rezepte die im {months[data.month-1]} in Saison sind</h2>
<SeasonLayout active_index={data.month -1}>
<Recipes slot=recipes>
{#each rand_array(data.season) as recipe}
<Card {recipe} icon_override=true></Card>