Skip to content

Commit 96fdf72

Browse files
committed
About Page Img Alt Support
Add support for `image-alt` in about page images
1 parent 725b736 commit 96fdf72

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

news/changelog-1.3.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- Improve the performance of extremely large documents with margin elements by improving the efficiency of positioning the elements.
66

7+
## About Pages
8+
9+
- Add support for `image-alt` which provides alternate text for the about page image. (#3010)
10+
711
## Listings
812

913
- Listings now support `template-params`, which will be passed to custom EJS templates when a listing is rendered.

src/project/types/website/about/website-about.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const kType = "type";
4040
const kLinks = "links";
4141

4242
const kImageWidth = "image-width";
43-
43+
const kImageAlt = "image-alt";
4444
const kImageShape = "image-shape";
4545
const kImageShapeRound = "round";
4646
const kImageShapeRounded = "rounded";
@@ -70,13 +70,15 @@ interface AboutPage {
7070
options: Record<string, unknown>;
7171
custom: boolean;
7272
image?: Href;
73+
[kImageAlt]?: string;
7374
links?: Array<NavItem>;
7475
}
7576

7677
interface AboutPageEjsData {
7778
title: string;
7879
body: string;
7980
image?: string;
81+
[kImageAlt]?: string;
8082
links?: NavItem[];
8183
options: Record<string, unknown>;
8284
}
@@ -147,7 +149,7 @@ async function readAbout(
147149
aboutObj: Record<string, unknown>,
148150
aboutPage: AboutPage,
149151
) => {
150-
const knownFieldList = ["image", "template", "links"];
152+
const knownFieldList = ["image", kImageAlt, "template", "links"];
151153
for (const key of Object.keys(aboutObj)) {
152154
if (!knownFieldList.includes(key)) {
153155
aboutPage.options[key] = aboutObj[key];
@@ -194,6 +196,9 @@ async function readAbout(
194196
if (format.metadata[kImage]) {
195197
aboutPage.image = format.metadata[kImage] as Href;
196198
}
199+
if (format.metadata[kImageAlt]) {
200+
aboutPage[kImageAlt] = format.metadata[kImageAlt] as string;
201+
}
197202

198203
// Resolve any options
199204
resolveOptions(about, {}, aboutPage);
@@ -222,6 +227,15 @@ async function readAbout(
222227
}
223228
}
224229

230+
const aboutImageAlt = aboutObj[kImageAlt];
231+
if (aboutImageAlt) {
232+
aboutPage[kImageAlt] = aboutImageAlt as Href;
233+
} else {
234+
if (format.metadata[kImageAlt]) {
235+
aboutPage[kImageAlt] = format.metadata[kImageAlt] as Href;
236+
}
237+
}
238+
225239
const aboutLinks = aboutObj[kLinks] as Array<string | NavItem>;
226240
if (aboutLinks) {
227241
const links: NavItem[] = [];
@@ -284,6 +298,7 @@ const aboutPagePostProcessor = (
284298
title,
285299
body,
286300
image: aboutPage.image,
301+
[kImageAlt]: aboutPage[kImageAlt],
287302
links: aboutPage.links,
288303
options: aboutPage.options,
289304
};

src/resources/projects/website/about/_image.ejs.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@
1515
}
1616
}
1717

18+
const altText = () => {
19+
if (about['image-alt']) {
20+
return `alt="${about['image-alt']}" `;
21+
} else {
22+
return "";
23+
}
24+
}
25+
1826
const customClz = imgOpts.classes !== undefined ? imgOpts.classes : "";
27+
%>
1928

20-
%>
2129
<% if (about.image) { %>
22-
<img src="<%= about.image %>" class="about-image<%= imgClz %> <%= customClz %>" <%= imageSize() %> />
30+
<img src="<%= about.image %>" <%= altText() %>class="about-image<%= imgClz %> <%= customClz %>" <%= imageSize() %> />
2331
<%}%>

0 commit comments

Comments
 (0)