maverick-wave-astro 1.20.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Price.astro +7 -1
- package/components/Schedule.astro +3 -3
- package/dist/schedule.js +9 -16
- package/package.json +1 -1
- package/schemas/promo.schema.json +2 -2
package/components/Price.astro
CHANGED
|
@@ -15,10 +15,12 @@ interface Props {
|
|
|
15
15
|
amount: string | number;
|
|
16
16
|
// Only prices that take part in the promotion get it.
|
|
17
17
|
promo?: Promo | null;
|
|
18
|
+
// "ab 350 Euro": the amount is a starting price.
|
|
19
|
+
from?: boolean;
|
|
18
20
|
size?: 'xs' | 'sm' | 'lg';
|
|
19
21
|
currency?: string;
|
|
20
22
|
period?: string;
|
|
21
|
-
labels?: { free?: string; regular?: string; now?: string };
|
|
23
|
+
labels?: { free?: string; regular?: string; now?: string; from?: string };
|
|
22
24
|
class?: string;
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -27,6 +29,7 @@ const german = config.site.lang.startsWith('de');
|
|
|
27
29
|
const {
|
|
28
30
|
amount,
|
|
29
31
|
promo,
|
|
32
|
+
from = false,
|
|
30
33
|
size,
|
|
31
34
|
currency = 'Euro',
|
|
32
35
|
period,
|
|
@@ -38,6 +41,7 @@ const {
|
|
|
38
41
|
free = german ? 'kostenlos' : 'free',
|
|
39
42
|
regular = german ? 'Regulärer Preis:' : 'Regular price:',
|
|
40
43
|
now = german ? 'Jetzt:' : 'Now:',
|
|
44
|
+
from: fromWord = german ? 'ab' : 'from',
|
|
41
45
|
} = labels;
|
|
42
46
|
|
|
43
47
|
// Checked against '' instead of truthiness - a 0 has to stay a price.
|
|
@@ -54,12 +58,14 @@ const { whole, fraction } = priceParts(value, siteLocale);
|
|
|
54
58
|
withDiscount && (
|
|
55
59
|
<span class="mw-price-original mwa-promo-only">
|
|
56
60
|
<span class="mw-sr-only">{regular}</span>
|
|
61
|
+
{from && `${fromWord} `}
|
|
57
62
|
{whole}
|
|
58
63
|
{fraction} {currency}
|
|
59
64
|
</span>
|
|
60
65
|
)
|
|
61
66
|
}
|
|
62
67
|
{withDiscount && <span class="mw-sr-only mwa-promo-only">{now}</span>}
|
|
68
|
+
{isAmount && from && <span class="mw-price-word">{fromWord}</span>}
|
|
63
69
|
{
|
|
64
70
|
isAmount && (
|
|
65
71
|
<span class:list={['mw-price-amount', withDiscount && 'mwa-no-promo']}>
|
|
@@ -13,11 +13,11 @@ import '../styles/schedule.css';
|
|
|
13
13
|
const now = new Date();
|
|
14
14
|
|
|
15
15
|
// Promotion: data-promo-from and data-promo-until on <html>. Without
|
|
16
|
-
// "until" there is no promotion
|
|
16
|
+
// "until" there is no promotion.
|
|
17
17
|
const { promoFrom, promoUntil } = html.dataset;
|
|
18
18
|
if (
|
|
19
|
-
promoUntil
|
|
20
|
-
|
|
19
|
+
promoUntil &&
|
|
20
|
+
new Date(promoUntil) >= now &&
|
|
21
21
|
(!promoFrom || new Date(promoFrom) <= now)
|
|
22
22
|
) {
|
|
23
23
|
html.classList.add('mwa-promo-active');
|
package/dist/schedule.js
CHANGED
|
@@ -47,27 +47,20 @@ export const eventDateText = (entry, locale = 'de-DE') => {
|
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
49
|
// A planned promotion is in the HTML before its first day already - only the
|
|
50
|
-
// script makes it visible.
|
|
50
|
+
// script makes it visible. Without a last day there is none: an open-ended
|
|
51
|
+
// discount strikes through a price nobody ever pays (UWG, PAngV).
|
|
51
52
|
export const promoInHtml = (promo, now = new Date()) => {
|
|
52
53
|
const percent = Number(promo?.percent);
|
|
53
54
|
if (!promo || !Number.isFinite(percent) || percent <= 0)
|
|
54
55
|
return false;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!end || now > end)
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
56
|
+
const end = visibleUntil(promo.until ?? '');
|
|
57
|
+
return end !== null && now <= end;
|
|
61
58
|
};
|
|
62
59
|
// Value for data-promo-until on <html>: the moment the promotion is gone.
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return null;
|
|
68
|
-
const end = promo.until ? visibleUntil(promo.until) : null;
|
|
69
|
-
return end ? end.toISOString() : '';
|
|
70
|
-
};
|
|
60
|
+
// Null means no promotion - then there is nothing in the HTML to hide either.
|
|
61
|
+
export const promoExpiry = (promo, now = new Date()) => promoInHtml(promo, now)
|
|
62
|
+
? (visibleUntil(promo.until ?? '')?.toISOString() ?? null)
|
|
63
|
+
: null;
|
|
71
64
|
// Value for data-promo-from on <html>: the moment the promotion starts. Null
|
|
72
65
|
// means it applies right away, or there is none.
|
|
73
66
|
export const promoStart = (promo, now = new Date()) => {
|
|
@@ -82,7 +75,7 @@ export const discountText = (promo) => `-${Number(promo.percent)}\u2009%`;
|
|
|
82
75
|
// promised percentage. In whole cents, because 90 * 0.7 is 62.999... in
|
|
83
76
|
// floating point.
|
|
84
77
|
export const discountedPrice = (promo, amount) => Math.floor((Math.round(amount * 100) * (100 - Number(promo.percent))) / 10_000);
|
|
85
|
-
// Last day of the promotion, formatted. Null
|
|
78
|
+
// Last day of the promotion, formatted. Null without a valid last day.
|
|
86
79
|
export const promoEndDate = (promo, locale = 'de-DE') => {
|
|
87
80
|
const end = promo.until ? endOfDay(promo.until) : null;
|
|
88
81
|
return end
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "Ein Band ganz oben auf deiner Homepage. Wo die Aktion gilt, erscheinen die Preise reduziert. 0 Prozent schaltet die Aktion aus.",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"additionalProperties": false,
|
|
7
|
-
"required": ["percent", "text"],
|
|
7
|
+
"required": ["percent", "text", "until"],
|
|
8
8
|
"properties": {
|
|
9
9
|
"percent": {
|
|
10
10
|
"title": "Rabatt in Prozent",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"until": {
|
|
29
29
|
"title": "Letzter Tag",
|
|
30
|
-
"description": "
|
|
30
|
+
"description": "Pflicht - ohne letzten Tag gibt es keinen Rabatt. Die Aktion verschwindet am Tag danach um 12 Uhr.",
|
|
31
31
|
"type": "string",
|
|
32
32
|
"format": "date",
|
|
33
33
|
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
|