From: Lady Date: Tue, 9 Aug 2022 03:22:57 +0000 (-0700) Subject: Better feed language handling X-Git-Tag: 0.1.0^0 X-Git-Url: https://git.ladys.computer/Beorn/commitdiff_plain/3a19eb936ebc72b3fb1d8757eefcc59bbb194b01 Better feed language handling --- diff --git a/build.js b/build.js index af75d5b..024698a 100755 --- 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( ` @@ -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 {