@rmdes/indiekit-endpoint-micropub 1.0.0-beta.32 → 1.0.0-beta.33
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/lib/utils.js +36 -0
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -22,6 +22,35 @@ export const decodeQueryParameter = (value) => {
|
|
|
22
22
|
: decodeURIComponent(value.replaceAll("+", " "));
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Detect whether a post carries an image — a `photo` property, or an image in
|
|
27
|
+
* its content (markdown `` or an inline `<img>`). Used to stamp a
|
|
28
|
+
* `hasImages` frontmatter flag so the Eleventy theme optimizes only
|
|
29
|
+
* image-bearing pages.
|
|
30
|
+
* @param {object} properties - JF2 properties
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
export const detectHasImages = (properties = {}) => {
|
|
34
|
+
const { photo, content } = properties;
|
|
35
|
+
|
|
36
|
+
// Non-empty photo array / single photo value
|
|
37
|
+
if (Array.isArray(photo) ? photo.length > 0 : Boolean(photo)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Flatten content to a single string regardless of JF2 shape
|
|
42
|
+
const toText = (c) => {
|
|
43
|
+
if (!c) return "";
|
|
44
|
+
if (typeof c === "string") return c;
|
|
45
|
+
if (Array.isArray(c)) return c.map(toText).join(" ");
|
|
46
|
+
// JF2 object shape: { text, html, value } — priority html > text > value;
|
|
47
|
+
// do not invert this order in a future refactor (html is the rendered form).
|
|
48
|
+
return c.html || c.text || c.value || "";
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return /!\[[^\]]*\]\(|<img[\s>/]/i.test(toText(content));
|
|
52
|
+
};
|
|
53
|
+
|
|
25
54
|
/**
|
|
26
55
|
* Get post template properties
|
|
27
56
|
* @param {object} properties - JF2 properties
|
|
@@ -48,6 +77,13 @@ export const getPostTemplateProperties = (properties) => {
|
|
|
48
77
|
}
|
|
49
78
|
}
|
|
50
79
|
|
|
80
|
+
// Stamp hasImages flag when the post contains an image (photo property or
|
|
81
|
+
// inline image in content). Omit entirely when false — absence ≡ false for
|
|
82
|
+
// the Eleventy theme. Detected from original properties before stripping.
|
|
83
|
+
if (detectHasImages(properties)) {
|
|
84
|
+
templateProperties.hasImages = true;
|
|
85
|
+
}
|
|
86
|
+
|
|
51
87
|
return templateProperties;
|
|
52
88
|
};
|
|
53
89
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmdes/indiekit-endpoint-micropub",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.33",
|
|
4
4
|
"description": "Micropub endpoint for Indiekit with custom type-based post discovery. Enables publishing content to your website using the Micropub protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"indiekit",
|