Skip to content

Commit

Permalink
feat(endpoint-posts): featured field
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Dec 2, 2024
1 parent 9f53c92 commit 6fcbdb5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/endpoint-posts/includes/post-types/featured-field.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% call fieldset({
classes: "fieldset--group",
legend: __("posts.form.featured.label"),
optional: not field.required
}) %}
{{ fileInput({
field: {
attributes: {
endpoint: application.mediaEndpoint
}
},
name: "featured[url]",
type: "url",
value: fieldData("featured.url").value,
label: __("posts.form.media.label"),
accept: "image/*",
attributes: {
placeholder: "https://"
},
errorMessage: fieldData("featured.url").errorMessage
}) | indent(2) }}

{{ textarea({
name: "featured[alt]",
value: fieldData("featured.alt").value,
label: __("posts.form.featured.alt"),
rows: 1,
errorMessage: fieldData("featured.alt").errorMessage
}) | indent(2) }}
{% endcall %}
8 changes: 8 additions & 0 deletions packages/endpoint-posts/includes/post-types/featured.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% set html %}
<figure>
<img src="{{ item.url | url(publication.me) }}" alt="{{ item.alt }}">
</figure>
{% endset -%}
{{- prose({
html: html
}) if property }}
12 changes: 12 additions & 0 deletions packages/endpoint-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ export default class PostsEndpoint {
exists: { if: (value, { req }) => isRequired(req, "content") },
notEmpty: true,
},
"featured.url": {
errorMessage: (value, { req }) =>
req.__(`posts.error.media.empty`, "/photos/image.jpg"),
exists: { if: (value, { req }) => isRequired(req, "featured") },
notEmpty: true,
},
"featured.alt": {
errorMessage: (value, { req }) =>
req.__(`posts.error.featured-alt.empty`),
exists: { if: (value, { req }) => req.body?.featured.url },
notEmpty: true,
},
geo: {
errorMessage: (value, { req }) => req.__(`posts.error.geo.invalid`),
exists: { if: (value, { req }) => req.body?.geo },
Expand Down
7 changes: 7 additions & 0 deletions packages/endpoint-posts/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"content": {
"empty": "Enter some content"
},
"featured-alt": {
"empty": "Enter a description of this image"
},
"geo": {
"invalid": "Enter valid coordinates"
},
Expand Down Expand Up @@ -68,6 +71,10 @@
"content": {
"label": "Content"
},
"featured": {
"label": "Featured image",
"alt": "Accessible description"
},
"geo": {
"label": "Location coordinates",
"hint": "Latitude and longitude, for example %s"
Expand Down

0 comments on commit 6fcbdb5

Please sign in to comment.