maverick-wave-astro 1.3.0 → 1.5.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/README.md +6 -6
- package/bin/check.mjs +1 -0
- package/components/BlogPost.astro +5 -2
- package/components/Device.astro +60 -0
- package/components/Devices.astro +29 -0
- package/dist/text.d.ts +2 -0
- package/dist/text.js +66 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -125,12 +125,12 @@ every entry. Needs maverick-wave 5.34 or later.
|
|
|
125
125
|
`schemas/occasions.schema.json` ship with the package. Put
|
|
126
126
|
`mwa-check && astro build` in the build script so a broken file stops the
|
|
127
127
|
build - it knows the formats `date`, `email`, `uri` and the keywords `x-widget`,
|
|
128
|
-
`x-item-title`, `x-labels`, `x-empty`, `x-not-before`, `x-groups
|
|
129
|
-
uploaded in the contentmanager land in
|
|
130
|
-
derives their sizes before the build
|
|
131
|
-
file sharp cannot read and removes the
|
|
132
|
-
carry EXIF and GPS. Tooling: re-export
|
|
133
|
-
`/prettier`.
|
|
128
|
+
`x-item-title`, `x-labels`, `x-empty`, `x-not-before`, `x-groups`,
|
|
129
|
+
`x-newest-first`. Photos uploaded in the contentmanager land in
|
|
130
|
+
`public/images/uploads/`; the integration derives their sizes before the build
|
|
131
|
+
(`maverick-wave-astro/uploads`), skips a file sharp cannot read and removes the
|
|
132
|
+
originals from `dist/`, since they still carry EXIF and GPS. Tooling: re-export
|
|
133
|
+
`maverick-wave-astro/eslint` and `/prettier`.
|
|
134
134
|
|
|
135
135
|
## Releasing
|
|
136
136
|
|
package/bin/check.mjs
CHANGED
|
@@ -19,7 +19,8 @@ interface Props {
|
|
|
19
19
|
// Already worded, e.g. "3 Min. Lesezeit"
|
|
20
20
|
readingTime?: string;
|
|
21
21
|
tags?: readonly string[];
|
|
22
|
-
//
|
|
22
|
+
// A file from public/. An uploaded photo goes into the image slot as a
|
|
23
|
+
// Picture with class mw-blog-post-featured-image instead.
|
|
23
24
|
image?: { src: string; alt: string };
|
|
24
25
|
older?: Link;
|
|
25
26
|
back?: Link;
|
|
@@ -97,13 +98,15 @@ const withFooter = older || back || newer;
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
{
|
|
100
|
-
image
|
|
101
|
+
image ? (
|
|
101
102
|
<img
|
|
102
103
|
class="mw-blog-post-featured-image"
|
|
103
104
|
{...publicImage(image.src)}
|
|
104
105
|
alt={image.alt}
|
|
105
106
|
decoding="async"
|
|
106
107
|
/>
|
|
108
|
+
) : (
|
|
109
|
+
<slot name="image" />
|
|
107
110
|
)
|
|
108
111
|
}
|
|
109
112
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
// One device frame drawn by the framework - a laptop or a phone - with a page
|
|
3
|
+
// on the glass: a full-page screenshot from public/, or the live page in an
|
|
4
|
+
// iframe laid out at the device's width and scaled to fit. Both frames
|
|
5
|
+
// together are Devices.
|
|
6
|
+
import { config } from '../dist/config.js';
|
|
7
|
+
import { publicImage } from '../dist/image-size.js';
|
|
8
|
+
import { linkTo } from '../dist/path.js';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
kind: 'laptop' | 'phone';
|
|
12
|
+
// 1280px wide for the laptop, 390px for the phone, as tall as the page
|
|
13
|
+
image?: string;
|
|
14
|
+
alt?: string;
|
|
15
|
+
// The page itself instead of a picture
|
|
16
|
+
src?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
// As a button: a tap scrolls the screenshot to its end and back
|
|
19
|
+
tour?: boolean;
|
|
20
|
+
tourLabel?: string;
|
|
21
|
+
class?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const german = config.site.lang.startsWith('de');
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
kind,
|
|
28
|
+
image,
|
|
29
|
+
alt = '',
|
|
30
|
+
src,
|
|
31
|
+
title,
|
|
32
|
+
tour = false,
|
|
33
|
+
tourLabel = german ? 'Seite durchscrollen' : 'Scroll through the page',
|
|
34
|
+
class: className,
|
|
35
|
+
} = Astro.props;
|
|
36
|
+
|
|
37
|
+
// A live page scrolls by itself - the tour needs a picture to move
|
|
38
|
+
const button = tour && Boolean(image);
|
|
39
|
+
const Frame = button ? 'button' : 'div';
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
<Frame
|
|
43
|
+
class:list={['mw-device', `mw-device-${kind}`, className]}
|
|
44
|
+
{...button ? { type: 'button', 'aria-label': tourLabel } : {}}
|
|
45
|
+
>
|
|
46
|
+
<span class="mw-device-screen">
|
|
47
|
+
{
|
|
48
|
+
image ? (
|
|
49
|
+
<img
|
|
50
|
+
{...publicImage(image)}
|
|
51
|
+
alt={alt}
|
|
52
|
+
loading="lazy"
|
|
53
|
+
decoding="async"
|
|
54
|
+
/>
|
|
55
|
+
) : (
|
|
56
|
+
src && <iframe src={linkTo(src)} title={title} loading="lazy" />
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
</span>
|
|
60
|
+
</Frame>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Laptop and phone together: the phone stands over the laptop's lower right
|
|
3
|
+
// corner, below it once the container gets narrow. Each screen takes what
|
|
4
|
+
// Device takes.
|
|
5
|
+
import Device from './Device.astro';
|
|
6
|
+
|
|
7
|
+
interface Screen {
|
|
8
|
+
image?: string;
|
|
9
|
+
alt?: string;
|
|
10
|
+
src?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
laptop: Screen;
|
|
16
|
+
phone: Screen;
|
|
17
|
+
// The phone scrolls its screenshot on a tap - only with an image on it
|
|
18
|
+
tour?: boolean;
|
|
19
|
+
tourLabel?: string;
|
|
20
|
+
class?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { laptop, phone, tour = true, tourLabel, class: className } = Astro.props;
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
<div class:list={['mw-devices', className]}>
|
|
27
|
+
<Device kind="laptop" {...laptop} />
|
|
28
|
+
<Device kind="phone" {...phone} tour={tour} tourLabel={tourLabel} />
|
|
29
|
+
</div>
|
package/dist/text.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const emphasize: (value: string) => string;
|
|
2
2
|
export declare const markdown: (value: string | undefined) => string;
|
|
3
|
+
/** A title as a URL segment: "Über den Tellerrand" becomes "ueber-den-tellerrand". */
|
|
4
|
+
export declare const slug: (value: string) => string;
|
|
3
5
|
export declare const readingTime: (body: string | undefined) => number;
|
package/dist/text.js
CHANGED
|
@@ -11,18 +11,73 @@ const inline = (value) => escape(value)
|
|
|
11
11
|
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
|
|
12
12
|
.replace(/(^|[^*])\*([^*\s](?:[^*]*[^*\s])?)\*/g, '$1<em>$2</em>')
|
|
13
13
|
.replace(/\n/g, '<br>');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
const HEADING = /^(#{1,3})\s+(.+)$/;
|
|
15
|
+
const ORDERED = /^(\d+)[.)]\s+/;
|
|
16
|
+
const kind = (line) => {
|
|
17
|
+
if (HEADING.test(line))
|
|
18
|
+
return 'heading';
|
|
19
|
+
if (line.startsWith('- '))
|
|
20
|
+
return 'bullets';
|
|
21
|
+
if (ORDERED.test(line))
|
|
22
|
+
return 'numbers';
|
|
23
|
+
if (line.startsWith('>'))
|
|
24
|
+
return 'quote';
|
|
25
|
+
return 'text';
|
|
26
|
+
};
|
|
27
|
+
// Customers type "Text" and "- Punkt" on the next line and expect a list, so a
|
|
28
|
+
// new kind of line starts a new block without an empty line in between.
|
|
29
|
+
const blocks = (value) => {
|
|
30
|
+
const result = [];
|
|
31
|
+
let previous = '';
|
|
32
|
+
for (const line of value.replace(/\r\n/g, '\n').split('\n')) {
|
|
33
|
+
const text = line.trim();
|
|
34
|
+
const current = text ? kind(text) : '';
|
|
35
|
+
if (current && current === previous && current !== 'heading') {
|
|
36
|
+
result[result.length - 1].push(text);
|
|
37
|
+
}
|
|
38
|
+
else if (current) {
|
|
39
|
+
result.push([text]);
|
|
40
|
+
}
|
|
41
|
+
previous = current;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
const items = (lines, marker) => lines.map(line => `<li>${inline(line.replace(marker, ''))}</li>`).join('');
|
|
46
|
+
const block = (lines) => {
|
|
47
|
+
switch (kind(lines[0])) {
|
|
48
|
+
case 'heading': {
|
|
49
|
+
const [, hashes, text] = HEADING.exec(lines[0]) ?? [];
|
|
50
|
+
// "#" as well: the page title is the only h1.
|
|
51
|
+
const level = Math.max(2, hashes.length);
|
|
52
|
+
return `<h${level}>${inline(text)}</h${level}>`;
|
|
53
|
+
}
|
|
54
|
+
case 'bullets':
|
|
55
|
+
return `<ul>${items(lines, /^- /)}</ul>`;
|
|
56
|
+
case 'numbers': {
|
|
57
|
+
const first = Number(ORDERED.exec(lines[0])?.[1]);
|
|
58
|
+
const start = first === 1 ? '' : ` start="${first}"`;
|
|
59
|
+
return `<ol${start}>${items(lines, ORDERED)}</ol>`;
|
|
60
|
+
}
|
|
61
|
+
case 'quote': {
|
|
62
|
+
const quoted = lines.map(line => line.replace(/^>\s?/, '')).join('\n');
|
|
63
|
+
return `<blockquote>${markdown(quoted)}</blockquote>`;
|
|
64
|
+
}
|
|
65
|
+
default:
|
|
66
|
+
return `<p>${inline(lines.join('\n'))}</p>`;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export const markdown = (value) => blocks(value ?? '')
|
|
70
|
+
.map(block)
|
|
25
71
|
.join('');
|
|
72
|
+
const UMLAUTS = { ä: 'ae', ö: 'oe', ü: 'ue', ß: 'ss' };
|
|
73
|
+
/** A title as a URL segment: "Über den Tellerrand" becomes "ueber-den-tellerrand". */
|
|
74
|
+
export const slug = (value) => value
|
|
75
|
+
.toLowerCase()
|
|
76
|
+
.replace(/[äöüß]/g, char => UMLAUTS[char])
|
|
77
|
+
.normalize('NFKD')
|
|
78
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
79
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
80
|
+
.replace(/^-|-$/g, '');
|
|
26
81
|
const WORDS_PER_MINUTE = 190;
|
|
27
82
|
export const readingTime = (body) => {
|
|
28
83
|
const words = (body ?? '').trim().split(/\s+/).length;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maverick-wave-astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"astro": "^7.2.0",
|
|
54
|
-
"maverick-wave": "^5.
|
|
54
|
+
"maverick-wave": "^5.39.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@astrojs/sitemap": "^3.7.3",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"eslint-plugin-astro": "^1.5.0",
|
|
67
67
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
68
68
|
"globals": "^16.5.0",
|
|
69
|
-
"maverick-wave": "^5.
|
|
69
|
+
"maverick-wave": "^5.39.0",
|
|
70
70
|
"prettier": "^3.6.2",
|
|
71
71
|
"prettier-plugin-astro": "^0.14.1",
|
|
72
72
|
"typescript": "^6.0.3",
|