maverick-wave-astro 1.20.0 → 1.21.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.
@@ -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; empty means open-ended.
16
+ // "until" there is no promotion.
17
17
  const { promoFrom, promoUntil } = html.dataset;
18
18
  if (
19
- promoUntil !== undefined &&
20
- (promoUntil === '' || new Date(promoUntil) >= now) &&
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
- if (promo.until) {
56
- const end = visibleUntil(promo.until);
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
- // Empty means open-ended, null means no promotion - then there is nothing in
64
- // the HTML to hide either.
65
- export const promoExpiry = (promo, now = new Date()) => {
66
- if (!promoInHtml(promo, now))
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 means open-ended.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maverick-wave-astro",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Shared frame for static Astro homepages built with MaverickWave: layout, SEO, design variants, schedule, building blocks.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "until": {
29
29
  "title": "Letzter Tag",
30
- "description": "Leer: ohne Ende. Sonst verschwindet die Aktion am Tag danach um 12 Uhr.",
30
+ "description": "Ohne letzten Tag zeigt die Homepage 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}$",