maverick-wave-astro 1.4.0 → 1.6.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/Breadcrumbs.astro +6 -0
- package/dist/structured-data.d.ts +15 -0
- package/dist/structured-data.js +11 -0
- package/dist/text.d.ts +2 -0
- package/dist/text.js +66 -11
- package/package.json +1 -1
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
|
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
import { config } from '../dist/config.js';
|
|
5
5
|
import { PACKAGE_ICONS } from '../dist/icons.js';
|
|
6
6
|
import { withBase } from '../dist/path.js';
|
|
7
|
+
import { breadcrumbList } from '../dist/structured-data.js';
|
|
7
8
|
import Icon from './Icon.astro';
|
|
9
|
+
import JsonLd from './JsonLd.astro';
|
|
8
10
|
|
|
9
11
|
interface Props {
|
|
10
12
|
items: readonly { label: string; href: string }[];
|
|
@@ -27,6 +29,9 @@ const {
|
|
|
27
29
|
small = false,
|
|
28
30
|
class: className = 'mw-mt-8 mw-mb-8',
|
|
29
31
|
} = Astro.props;
|
|
32
|
+
const trail = Astro.site
|
|
33
|
+
? breadcrumbList([{ label: homeLabel, href: homeHref }, ...items], Astro.site)
|
|
34
|
+
: null;
|
|
30
35
|
---
|
|
31
36
|
|
|
32
37
|
<nav
|
|
@@ -67,3 +72,4 @@ const {
|
|
|
67
72
|
}
|
|
68
73
|
</ol>
|
|
69
74
|
</nav>
|
|
75
|
+
{trail && <JsonLd data={trail} />}
|
|
@@ -1 +1,16 @@
|
|
|
1
1
|
export declare const jsonLdText: (data: unknown) => string;
|
|
2
|
+
export type Crumb = {
|
|
3
|
+
label: string;
|
|
4
|
+
href: string;
|
|
5
|
+
};
|
|
6
|
+
/** The trail the Breadcrumbs component shows, start page first, as absolute URLs. */
|
|
7
|
+
export declare const breadcrumbList: (crumbs: readonly Crumb[], site: URL | string) => {
|
|
8
|
+
'@context': string;
|
|
9
|
+
'@type': string;
|
|
10
|
+
itemListElement: {
|
|
11
|
+
'@type': string;
|
|
12
|
+
position: number;
|
|
13
|
+
name: string;
|
|
14
|
+
item: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
package/dist/structured-data.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
// Without the escape a "</script>" inside any text ends the block early.
|
|
2
2
|
export const jsonLdText = (data) => JSON.stringify(data).replace(/</g, '\\u003c');
|
|
3
|
+
/** The trail the Breadcrumbs component shows, start page first, as absolute URLs. */
|
|
4
|
+
export const breadcrumbList = (crumbs, site) => ({
|
|
5
|
+
'@context': 'https://schema.org',
|
|
6
|
+
'@type': 'BreadcrumbList',
|
|
7
|
+
itemListElement: crumbs.map((crumb, index) => ({
|
|
8
|
+
'@type': 'ListItem',
|
|
9
|
+
position: index + 1,
|
|
10
|
+
name: crumb.label,
|
|
11
|
+
item: new URL(crumb.href, site).href,
|
|
12
|
+
})),
|
|
13
|
+
});
|
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