Skip to content

Commit 7516856

Browse files
feat(endpoint-posts): channels
1 parent de0183c commit 7516856

File tree

18 files changed

+89
-2
lines changed

18 files changed

+89
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{ tag({
2+
label: __("posts.form.mp-channel.label"),
3+
items: publication.channels[property].name
4+
}) if property }}

packages/endpoint-posts/lib/middleware/post-data.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "node:path";
22
import { IndiekitError } from "@indiekit/error";
33
import { statusTypes } from "../status-types.js";
44
import {
5+
getChannelItems,
56
getGeoValue,
67
getPostName,
78
getPostProperties,
@@ -26,6 +27,7 @@ export const postData = {
2627
response.locals = {
2728
accessToken: access_token,
2829
action: "create",
30+
channelItems: getChannelItems(publication),
2931
fields,
3032
name,
3133
postsPath: path.dirname(request.baseUrl + request.path),
@@ -68,6 +70,7 @@ export const postData = {
6870
accessToken: access_token,
6971
action: action || "create",
7072
allDay,
73+
channelItems: getChannelItems(publication),
7174
draftMode: scope?.includes("draft"),
7275
fields,
7376
geo,

packages/endpoint-posts/lib/utils.js

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ import formatcoords from "formatcoords";
55
import { endpoint } from "./endpoint.js";
66
import { statusTypes } from "./status-types.js";
77

8+
/**
9+
* Get channel `items` for checkboxes component
10+
* @param {object} publication - Publication configuration
11+
* @returns {object} Items for checkboxes component
12+
*/
13+
export const getChannelItems = (publication) => {
14+
return Object.entries(publication.channels).map(([uid, channel]) => ({
15+
label: channel.name,
16+
value: uid,
17+
}));
18+
};
19+
820
/**
921
* Get geographic coordinates property
1022
* @param {string} geo - Latitude and longitude, comma separated

packages/endpoint-posts/locales/de.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Dateipfad oder URL"
6060
},
61+
"mp-channel": {
62+
"label": "Kanal"
63+
},
6164
"mp-slug": {
6265
"label": "Slug"
6366
},

packages/endpoint-posts/locales/en.json

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
"media": {
8787
"label": "File path or URL"
8888
},
89+
"mp-channel": {
90+
"label": "Channel"
91+
},
8992
"mp-slug": {
9093
"label": "URL slug"
9194
},

packages/endpoint-posts/locales/es-419.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Ruta o URL del archivo"
6060
},
61+
"mp-channel": {
62+
"label": "Canal"
63+
},
6164
"mp-slug": {
6265
"label": "Babosa de URL"
6366
},

packages/endpoint-posts/locales/es.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Ruta o URL del archivo"
6060
},
61+
"mp-channel": {
62+
"label": "Canal"
63+
},
6164
"mp-slug": {
6265
"label": "URL slug"
6366
},

packages/endpoint-posts/locales/fr.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Chemin du fichier ou URL"
6060
},
61+
"mp-channel": {
62+
"label": "Canal"
63+
},
6164
"mp-slug": {
6265
"label": "Identifiant unique d’URL (slug)"
6366
},

packages/endpoint-posts/locales/hi.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "फ़ाइल पथ या URL"
6060
},
61+
"mp-channel": {
62+
"label": "चैनल"
63+
},
6164
"mp-slug": {
6265
"label": "URL स्लग"
6366
},
@@ -114,4 +117,4 @@
114117
"title": "%s पोस्ट अपडेट करें"
115118
}
116119
}
117-
}
120+
}

packages/endpoint-posts/locales/id.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Jalur file atau URL"
6060
},
61+
"mp-channel": {
62+
"label": "Saluran"
63+
},
6164
"mp-slug": {
6265
"label": "URL siput"
6366
},

packages/endpoint-posts/locales/nl.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Bestandspad of URL"
6060
},
61+
"mp-channel": {
62+
"label": "Kanaal"
63+
},
6164
"mp-slug": {
6265
"label": "URL-slug"
6366
},

packages/endpoint-posts/locales/pl.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Ścieżka pliku lub adres URL"
6060
},
61+
"mp-channel": {
62+
"label": "Kanał"
63+
},
6164
"mp-slug": {
6265
"label": "Ślimak URL"
6366
},

packages/endpoint-posts/locales/pt.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Caminho do arquivo ou URL"
6060
},
61+
"mp-channel": {
62+
"label": "Canal"
63+
},
6164
"mp-slug": {
6265
"label": "Slug de URL"
6366
},

packages/endpoint-posts/locales/sr.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Putanja ili URL datoteke"
6060
},
61+
"mp-channel": {
62+
"label": "Kanal"
63+
},
6164
"mp-slug": {
6265
"label": "URL slag"
6366
},

packages/endpoint-posts/locales/sv.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "Filsökväg eller URL"
6060
},
61+
"mp-channel": {
62+
"label": "Kanal"
63+
},
6164
"mp-slug": {
6265
"label": "URL-slug"
6366
},
@@ -114,4 +117,4 @@
114117
"title": "Uppdatera %s inlägg"
115118
}
116119
}
117-
}
120+
}

packages/endpoint-posts/locales/zh-Hans-CN.json

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"media": {
5959
"label": "文件路径或 URL"
6060
},
61+
"mp-channel": {
62+
"label": "频道"
63+
},
6164
"mp-slug": {
6265
"label": "网址 slug"
6366
},

packages/endpoint-posts/test/unit/utils.js

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { strict as assert } from "node:assert";
22
import { describe, it } from "node:test";
33
import { mockResponse } from "mock-req-res";
44
import {
5+
getChannelItems,
56
getGeoProperty,
67
getGeoValue,
78
getLocationProperty,
@@ -14,6 +15,14 @@ import {
1415

1516
const publication = {
1617
me: "https://website.example",
18+
channels: {
19+
posts: {
20+
name: "Posts",
21+
},
22+
pages: {
23+
name: "Pages",
24+
},
25+
},
1726
postTypes: {
1827
article: {
1928
name: "Journal entry",
@@ -43,6 +52,16 @@ const publication = {
4352
};
4453

4554
describe("endpoint-posts/lib/utils", () => {
55+
it("Gets channel `items` for checkboxes component", () => {
56+
const result = getChannelItems(publication);
57+
58+
assert.equal(result.length, 2);
59+
assert.equal(result[0].label, "Posts");
60+
assert.equal(result[0].value, "posts");
61+
assert.equal(result[1].label, "Pages");
62+
assert.equal(result[1].value, "pages");
63+
});
64+
4665
it("Gets geographic coordinates property", () => {
4766
assert.deepEqual(getGeoProperty("50.8252, -0.1383"), {
4867
type: "geo",

packages/endpoint-posts/views/post-form.njk

+10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@
5252
}]
5353
}) }}
5454

55+
{{ checkboxes({
56+
name: "mp-channel",
57+
values: properties["mp-channel"],
58+
fieldset: {
59+
legend: __("posts.form.mp-channel.label"),
60+
optional: true
61+
},
62+
items: channelItems
63+
}) | indent(2) if publication.channels }}
64+
5565
{{ radios({
5666
inline: true,
5767
name: "visibility",

0 commit comments

Comments
 (0)