]> Lady’s Gitweb - Beorn/commitdiff
Better feed language handling 0.1.0
authorLady <redacted>
Tue, 9 Aug 2022 03:22:57 +0000 (20:22 -0700)
committerLady <redacted>
Sat, 29 Apr 2023 03:43:42 +0000 (20:43 -0700)
build.js

index af75d5b06308e62687cf8d8f6631150eaf7f0766..024698acde71ebcb1fc22b8dd789320ec8cf0425 100755 (executable)
--- a/build.js
+++ b/build.js
@@ -910,12 +910,11 @@ await (async () => { // this is the run script
   const writes = [];
 
   // Set up the feed metadata and Atom feed document.
-  const feedMetadata = metadataFromDocument(
-    parser.parseFromString(
-      await Deno.readTextFile(`${basePath}/#feed.rdf`),
-      "application/xml",
-    ),
+  const feedDocument = parser.parseFromString(
+    await Deno.readTextFile(`${basePath}/#feed.rdf`),
+    "application/xml",
   );
+  const feedMetadata = metadataFromDocument(feedDocument);
   const feedURI = new URL(feedMetadata.id);
   const document = parser.parseFromString(
     `<?xml version="1.0" encoding="utf-8"?>
@@ -926,10 +925,28 @@ await (async () => { // this is the run script
     "application/xml",
   );
   const { documentElement: feed } = document;
+  const feedLanguage = getLanguage(feedDocument);
+  if (feedLanguage) {
+    // The feed element has a language.
+    setLanguage(feed, feedLanguage);
+  } else {
+    // There is no language for the feed.
+    /* do nothing */
+  }
   applyMetadata(feed, feedMetadata);
 
   // Set up the index page.
   const feedTemplate = await documentFromTemplate("feed");
+  const { documentElement: feedTemplateRoot } = feedTemplate;
+  if (feedLanguage && !getLanguage(feedTemplateRoot)) {
+    // The root element of the template does not have an
+    // assigned language, but the feed does.
+    setLanguage(feedTemplateRoot, feedLanguage);
+  } else {
+    // Either the template root already has a language, or the
+    // entry doesn’t either.
+    /* do nothing */
+  }
   const feedEntries = feedTemplate.createDocumentFragment();
 
   // Process entries and save the resulting index files.
@@ -1022,8 +1039,7 @@ await (async () => { // this is the run script
 
   // Apply the feed metadata to the feed template and save the
   // resulting index file.
-  const { documentElement: feedRoot } = feedTemplate;
-  if (hasExpandedName(feedRoot, XHTML, "html")) {
+  if (hasExpandedName(feedTemplateRoot, XHTML, "html")) {
     // This is an XHTML template.
     const LMN = Lemon.bind({ document: feedTemplate });
     const {
This page took 0.025546 seconds and 4 git commands to generate.