Skip to content

Commit

Permalink
feat(endpoint-posts): channels
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Nov 16, 2024
1 parent 4868945 commit decc3dc
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/endpoint-posts/includes/post-types/mp-channel.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ tag({
label: __("posts.form.mp-channel.label"),
items: publication.channels[property].name
}) if property }}
3 changes: 3 additions & 0 deletions packages/endpoint-posts/lib/middleware/post-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "node:path";
import { IndiekitError } from "@indiekit/error";
import { statusTypes } from "../status-types.js";
import {
getChannelItems,
getGeoValue,
getPostName,
getPostProperties,
Expand All @@ -26,6 +27,7 @@ export const postData = {
response.locals = {
accessToken: access_token,
action: "create",
channelItems: getChannelItems(publication),
fields,
name,
postsPath: path.dirname(request.baseUrl + request.path),
Expand Down Expand Up @@ -68,6 +70,7 @@ export const postData = {
accessToken: access_token,
action: action || "create",
allDay,
channelItems: getChannelItems(publication),
draftMode: scope?.includes("draft"),
fields,
geo,
Expand Down
12 changes: 12 additions & 0 deletions packages/endpoint-posts/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import formatcoords from "formatcoords";
import { endpoint } from "./endpoint.js";
import { statusTypes } from "./status-types.js";

/**
* Get channel `items` for checkboxes component
* @param {object} publication - Publication configuration
* @returns {object} Items for checkboxes component
*/
export const getChannelItems = (publication) => {
return Object.entries(publication.channels).map(([uid, channel]) => ({
label: channel.name,
value: uid,
}));
};

/**
* Get geographic coordinates property
* @param {string} geo - Latitude and longitude, comma separated
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Dateipfad oder URL"
},
"mp-channel": {
"label": "Kanal"
},
"mp-slug": {
"label": "Slug"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
"media": {
"label": "File path or URL"
},
"mp-channel": {
"label": "Channel"
},
"mp-slug": {
"label": "URL slug"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Ruta o URL del archivo"
},
"mp-channel": {
"label": "Canal"
},
"mp-slug": {
"label": "Babosa de URL"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Ruta o URL del archivo"
},
"mp-channel": {
"label": "Canal"
},
"mp-slug": {
"label": "URL slug"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Chemin du fichier ou URL"
},
"mp-channel": {
"label": "Canal"
},
"mp-slug": {
"label": "Identifiant unique d’URL (slug)"
},
Expand Down
5 changes: 4 additions & 1 deletion packages/endpoint-posts/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "फ़ाइल पथ या URL"
},
"mp-channel": {
"label": "चैनल"
},
"mp-slug": {
"label": "URL स्लग"
},
Expand Down Expand Up @@ -114,4 +117,4 @@
"title": "%s पोस्ट अपडेट करें"
}
}
}
}
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Jalur file atau URL"
},
"mp-channel": {
"label": "Saluran"
},
"mp-slug": {
"label": "URL siput"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Bestandspad of URL"
},
"mp-channel": {
"label": "Kanaal"
},
"mp-slug": {
"label": "URL-slug"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Ścieżka pliku lub adres URL"
},
"mp-channel": {
"label": "Kanał"
},
"mp-slug": {
"label": "Ślimak URL"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Caminho do arquivo ou URL"
},
"mp-channel": {
"label": "Canal"
},
"mp-slug": {
"label": "Slug de URL"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/sr.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Putanja ili URL datoteke"
},
"mp-channel": {
"label": "Kanal"
},
"mp-slug": {
"label": "URL slag"
},
Expand Down
5 changes: 4 additions & 1 deletion packages/endpoint-posts/locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "Filsökväg eller URL"
},
"mp-channel": {
"label": "Kanal"
},
"mp-slug": {
"label": "URL-slug"
},
Expand Down Expand Up @@ -114,4 +117,4 @@
"title": "Uppdatera %s inlägg"
}
}
}
}
3 changes: 3 additions & 0 deletions packages/endpoint-posts/locales/zh-Hans-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"media": {
"label": "文件路径或 URL"
},
"mp-channel": {
"label": "频道"
},
"mp-slug": {
"label": "网址 slug"
},
Expand Down
19 changes: 19 additions & 0 deletions packages/endpoint-posts/test/unit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { strict as assert } from "node:assert";
import { describe, it } from "node:test";
import { mockResponse } from "mock-req-res";
import {
getChannelItems,
getGeoProperty,
getGeoValue,
getLocationProperty,
Expand All @@ -14,6 +15,14 @@ import {

const publication = {
me: "https://website.example",
channels: {
posts: {
name: "Posts",
},
pages: {
name: "Pages",
},
},
postTypes: {
article: {
name: "Journal entry",
Expand Down Expand Up @@ -43,6 +52,16 @@ const publication = {
};

describe("endpoint-posts/lib/utils", () => {
it("Gets channel `items` for checkboxes component", () => {
const result = getChannelItems(publication);

assert.equal(result.length, 2);
assert.equal(result[0].label, "Posts");
assert.equal(result[0].value, "posts");
assert.equal(result[1].label, "Pages");
assert.equal(result[1].value, "pages");
});

it("Gets geographic coordinates property", () => {
assert.deepEqual(getGeoProperty("50.8252, -0.1383"), {
type: "geo",
Expand Down
10 changes: 10 additions & 0 deletions packages/endpoint-posts/views/post-form.njk
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
}]
}) }}

{{ checkboxes({
name: "mp-channel",
values: properties["mp-channel"],
fieldset: {
legend: __("posts.form.mp-channel.label"),
optional: true
},
items: channelItems
}) | indent(2) if publication.channels }}

{{ radios({
inline: true,
name: "visibility",
Expand Down

0 comments on commit decc3dc

Please sign in to comment.