Skip to content

Commit 966cac2

Browse files
authored
explode when using an invalid author (GoogleChrome#2295)
1 parent a081355 commit 966cac2

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/site/_collections/paginated-posts-by-author.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ const setdefault = require("../_utils/setdefault");
2121

2222
/**
2323
* Returns all posts as an array of paginated authors.
24-
* It's not as if every element in the array is a single page for an author, rather, its an array that includes every authors page.
25-
* Each element includes n number of posts as well as some basic information of that tag to pump into `_includes/partials/paged.njk`
26-
* This is because we can not paginate something already paginated... Pagination is effectively a loop, and we can't have an embedded loop O^2.
24+
*
25+
* It's not as if every element in the array is a single page for an author, rather, it is an array
26+
* that includes every authors page. Each element includes n number of posts as well as some basic
27+
* information of that tag to pump into `_includes/partials/paged.njk`. This is because we cannot
28+
* paginate something already paginated... Pagination is effectively a loop, and we can't have an
29+
* embedded loop O^2.
2730
*
2831
* @param {any} collection Eleventy collection object
2932
* @return {Array<{ title: string, href: string, description: string, posts: Array<object>, index: number, pages: number }>} An array where each element is a paged tag with some meta data and n posts for the page.
@@ -47,6 +50,19 @@ module.exports = (collection) => {
4750

4851
let authors = [];
4952
authorsMap.forEach((value, key) => {
53+
if (!(key in contributors)) {
54+
// Warn if the contributor ID is missing, including pointing to the paths of the source
55+
// inputs that are invalid.
56+
// This could also be run as part of generating author chips, but it is sufficient to explode
57+
// at only one place.
58+
const posts = authorsMap
59+
.get(key)
60+
.map((post) => post.inputPath)
61+
.join(", ");
62+
throw new Error(
63+
`unknown contributor ${key} [${posts}], are they in _data/contributors.js?`,
64+
);
65+
}
5066
authors = authors.concat(addPagination(value, contributors[key]));
5167
});
5268

0 commit comments

Comments
 (0)