@rmdes/indiekit-endpoint-micropub 1.0.0-beta.31 → 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/config.js CHANGED
@@ -19,12 +19,22 @@ export const getConfig = (application, publication) => {
19
19
  "syndicate-to",
20
20
  ];
21
21
 
22
- // Ensure syndication targets use absolute URLs
23
- const syndicateTo = syndicationTargets.map((target) => target.info);
24
- for (const info of syndicateTo) {
25
- if (info.service && info.service.photo) {
22
+ // Ensure syndication targets use absolute URLs. A misconfigured syndicator
23
+ // whose `info` getter throws (e.g. `new URL("")` on an empty instance URL)
24
+ // must not crash the Micropub config query — omit it from the advertised
25
+ // targets instead of letting it take down `q=config`.
26
+ const syndicateTo = [];
27
+ for (const target of syndicationTargets) {
28
+ let info;
29
+ try {
30
+ info = target.info;
31
+ } catch {
32
+ continue;
33
+ }
34
+ if (info?.service?.photo) {
26
35
  info.service.photo = new URL(info.service.photo, url).href;
27
36
  }
37
+ syndicateTo.push(info);
28
38
  }
29
39
 
30
40
  return {
package/lib/jf2.js CHANGED
@@ -304,7 +304,14 @@ export const getSyndicateToProperty = (properties, syndicationTargets) => {
304
304
  }
305
305
 
306
306
  for (const target of syndicationTargets) {
307
- const { uid } = target.info;
307
+ // A misconfigured syndicator whose `info` getter throws must not crash
308
+ // post creation; skip it when resolving mp-syndicate-to.
309
+ let uid;
310
+ try {
311
+ uid = target.info.uid;
312
+ } catch {
313
+ continue;
314
+ }
308
315
  const syndicateTo = properties["mp-syndicate-to"];
309
316
 
310
317
  if (syndicateTo?.includes(uid)) {
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.31",
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",