+/**
+ * Fills out the `head` of the provided H·T·M·L document with the
+ * appropriate metadata.
+ */
+const fillOutHead = (document, metadata, type) => {
+ const { documentElement } = document;
+ const LMN = Lemon.bind({ document });
+ const head =
+ Array.from(documentElement.childNodes).find(($) =>
+ hasExpandedName($, XHTML, "head")
+ ) ?? documentElement.insertBefore(
+ LMN.head``,
+ documentElement.childNodes.item(0),
+ );
+ const titleElement =
+ Array.from(head.childNodes).find(($) =>
+ hasExpandedName($, XHTML, "title")
+ ) ?? head.appendChild(LMN.title``);
+ const {
+ title,
+ author,
+ summary,
+ } = metadata;
+ titleElement.textContent = Object(title) instanceof String
+ ? title
+ : Array.from(title ?? []).map(($) => $.textContent).join("");
+ for (const person of author) {
+ // Iterate over authors and add appropriate meta tags.
+ head.appendChild(
+ LMN.meta({
+ name: "author",
+ content: person.name ?? person.uri,
+ })``,
+ );
+ }
+ head.appendChild(
+ LMN.meta({ name: "generator", content: "🧸📔 Bjørn" })``,
+ );
+ if (type == "entry") {
+ // The provided document is an entry document.
+ if (summary) {
+ // The entry has a summary.
+ head.appendChild(
+ LMN.meta({
+ name: "description",
+ content: Object(summary) instanceof String
+ ? summary
+ : Array.from(summary).map(($) => $.textContent).join(""),
+ })``,
+ );
+ } else {
+ /* do nothing */
+ }
+ head.appendChild(
+ LMN.link
+ .rel("alternate")
+ .type("application/atom+xml")
+ .href("../../feed.atom")``,
+ );
+ } else {
+ head.appendChild(
+ LMN.link
+ .rel("alternate")
+ .type("application/atom+xml")
+ .href("./feed.atom")``,
+ );
+ }
+};
+