@rmdes/indiekit-endpoint-posts 1.0.0 → 1.1.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.
@@ -97,9 +97,9 @@ export const formController = {
97
97
  // Easy MDE appends `image` value to formData for last image uploaded
98
98
  delete values.image;
99
99
 
100
- // Remove empty layout selection (user chose "Default")
101
- if (!values.layout) {
102
- delete values.layout;
100
+ // Remove empty layout-intent selection (user chose "Site default")
101
+ if (!values["layout-intent"]) {
102
+ delete values["layout-intent"];
103
103
  }
104
104
 
105
105
  // Remove empty pinned/featured flag
@@ -62,7 +62,6 @@ export const postsController = async (request, response, next) => {
62
62
  item.icon = item["post-type"];
63
63
  item.locale = application.locale;
64
64
  item.photo = getPhotoUrl(publication, item);
65
-
66
65
  item.description = {
67
66
  text:
68
67
  item.summary ||
@@ -5,7 +5,6 @@ import { IndiekitError } from "@indiekit/error";
5
5
  import { statusTypes } from "../status-types.js";
6
6
  import {
7
7
  getGeoValue,
8
- getLayoutItems,
9
8
  getPostName,
10
9
  getPostProperties,
11
10
  getSyndicateToItems,
@@ -55,7 +54,6 @@ export const postData = {
55
54
  accessToken: access_token,
56
55
  action: "create",
57
56
  fields,
58
- layoutItems: getLayoutItems(publication),
59
57
  name,
60
58
  postsPath: path.dirname(request.baseUrl + request.path),
61
59
  postType,
@@ -97,7 +95,6 @@ export const postData = {
97
95
  fields,
98
96
  geo,
99
97
  h,
100
- layoutItems: getLayoutItems(publication),
101
98
  name,
102
99
  postName: getPostName(publication, properties),
103
100
  postsPath: path.dirname(request.baseUrl + request.path),
package/lib/utils.js CHANGED
@@ -9,25 +9,6 @@ import formatcoords from "formatcoords";
9
9
  import { endpoint } from "./endpoint.js";
10
10
  import { statusTypes } from "./status-types.js";
11
11
 
12
- /**
13
- * Get layout `items` for select component
14
- * @param {object} publication - Publication configuration
15
- * @returns {Array} Items for select component, or empty array if no layouts configured
16
- */
17
- export const getLayoutItems = (publication) => {
18
- if (!publication.layouts || !Array.isArray(publication.layouts)) {
19
- return [];
20
- }
21
-
22
- return [
23
- { text: "Default", value: "", selected: true },
24
- ...publication.layouts.map((layout) => ({
25
- text: layout.name,
26
- value: layout.path,
27
- })),
28
- ];
29
- };
30
-
31
12
  /**
32
13
  * Get geographic coordinates property
33
14
  * @param {string} geo - Latitude and longitude, comma separated
@@ -370,19 +351,37 @@ export const getPostUrl = (id) => {
370
351
  * @returns {object} Items for checkboxes component
371
352
  */
372
353
  export const getSyndicateToItems = (publication, checkTargets = false) => {
373
- return publication.syndicationTargets.map((target) => ({
374
- label: target.info.service.name,
375
- ...(target?.info?.error
376
- ? {
377
- disabled: true,
378
- hint: target?.info?.error || false,
379
- }
380
- : {
381
- hint: target?.info.uid,
382
- value: target?.info.uid,
383
- ...(checkTargets && { checked: target.options.checked }),
384
- }),
385
- }));
354
+ return publication.syndicationTargets.map((target) => {
355
+ // A misconfigured syndicator must never crash a core feature (the post
356
+ // editor). Reading `target.info` can throw — the getter builds URLs from
357
+ // plugin config (e.g. `new URL(MASTODON_INSTANCE)` throws on an empty
358
+ // value). Contain it and surface the target as a disabled item with a
359
+ // hint, exactly as we do for a target that reports `info.error`.
360
+ let info;
361
+ try {
362
+ info = target.info;
363
+ } catch (error) {
364
+ return {
365
+ label: target?.options?.name || target?.name || "Syndication target",
366
+ disabled: true,
367
+ hint: error.message || "Syndicator is not configured correctly",
368
+ };
369
+ }
370
+
371
+ return {
372
+ label: info?.service?.name || target?.name || "Syndication target",
373
+ ...(info?.error
374
+ ? {
375
+ disabled: true,
376
+ hint: info.error || false,
377
+ }
378
+ : {
379
+ hint: info?.uid,
380
+ value: info?.uid,
381
+ ...(checkTargets && { checked: target.options?.checked }),
382
+ }),
383
+ };
384
+ });
386
385
  };
387
386
 
388
387
  /** Directory name → post-type mapping */
package/locales/en.json CHANGED
@@ -113,6 +113,13 @@
113
113
  "layout": {
114
114
  "label": "Layout"
115
115
  },
116
+ "layout-intent": {
117
+ "label": "Layout width",
118
+ "hint": "Controls how wide this post renders. Leave unset to use your site’s configured default.",
119
+ "default": "Site default",
120
+ "fullwidth": "Full width",
121
+ "minimal": "Minimal (narrow reading column)"
122
+ },
116
123
  "mp-slug": {
117
124
  "label": "URL slug"
118
125
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-posts",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Post management endpoint for Indiekit with syndicate form fix. View posts published by your Micropub endpoint and publish new posts to it.",
5
5
  "keywords": [
6
6
  "indiekit",
@@ -98,22 +98,17 @@
98
98
  optional: true
99
99
  }) | indent(4) }}
100
100
 
101
- {% if layoutItems and layoutItems.length %}
102
- {% set layoutSelectItems = [] %}
103
- {% for item in layoutItems %}
104
- {% set _ = layoutSelectItems.push({
105
- text: item.text,
106
- value: item.value,
107
- selected: item.value === properties.layout
108
- }) %}
109
- {% endfor %}
110
101
  {{ select({
111
- name: "layout",
112
- label: __("posts.form.layout.label"),
102
+ name: "layout-intent",
103
+ label: __("posts.form.layout-intent.label"),
104
+ hint: __("posts.form.layout-intent.hint"),
113
105
  optional: true,
114
- items: layoutSelectItems
106
+ items: [
107
+ { text: __("posts.form.layout-intent.default"), value: "", selected: not properties["layout-intent"] },
108
+ { text: __("posts.form.layout-intent.fullwidth"), value: "fullwidth", selected: properties["layout-intent"] === "fullwidth" },
109
+ { text: __("posts.form.layout-intent.minimal"), value: "minimal", selected: properties["layout-intent"] === "minimal" }
110
+ ]
115
111
  }) | indent(4) }}
116
- {% endif %}
117
112
 
118
113
  {{ select({
119
114
  name: "pinned",