- // Iterate over each directory and process the ones which are
- // dates.
- if (!isDirectory || !/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/u.test(date)) {
- // This isn’t a dated directory.
- continue;
- } else {
- // This is a dated directory.
- for (
- const { name: entryName, isDirectory } of Array.from(
- Deno.readDirSync(`${basePath}/${date}/`),
- ).sort(({ name: a }, { name: b }) =>
- a < b ? -1 : a > b ? 1 : 0
- )
- ) {
- // Iterate over each directory and process the ones which look
- // like entries.
- if (
- !isDirectory ||
- //deno-lint-ignore no-control-regex
- /[\x00-\x20\x22#%/<>?\\^\x60{|}\x7F]/u.test(entryName)
- ) {
- // This isn’t an entry directory.
- continue;
- } else {
- // Process the entry.
- const entry = document.createElement("entry");
- const entryPath =
- `${basePath}/${date}/${entryName}/#entry.rdf`;
- const entryDocument = parser.parseFromString(
- await Deno.readTextFile(entryPath),
- "application/xml",
- );
- const { documentElement: entryRoot } = entryDocument;
- entryDocument.lastModified =
- (await Deno.lstat(entryPath)).mtime;
- if (!entryRoot.hasAttributeNS(RDF, "about")) {
- // The entry doesn’t have an identifier; let’s give it one.
- entryRoot.setAttributeNS(
- RDF,
- "about",
- new URL(`./${date}/${entryName}/`, feedURI),
- );
- } else {
- // The entry already has an identifier.
- /* do nothing */
- }
- const entryMetadata = metadataFromDocument(entryDocument);
- if (entryMetadata.author.length == 0) {
- // The entry metadata did not supply an author.
- entryMetadata.author = feedMetadata.author;
- } else {
- // The entry metadata supplied its own author.
- /* do nothing */
- }
- const entryTemplate = await documentFromTemplate("entry");
- const { documentElement: templateRoot } = entryTemplate;
- const lang = getLanguage(entryRoot);
- if (lang && !getLanguage(templateRoot)) {
- // The root element of the template does not have an
- // assigned language, but the entry does.
- setLanguage(templateRoot, lang);
- } else {
- // Either the template root already has a language, or the
- // entry doesn’t either.
- /* do nothing */
- }
- writes.push(
- Deno.writeTextFile(
- `${basePath}/${date}/${entryName}/index.xhtml`,
- serializer.serializeToString(
- applyMetadata(entryTemplate, entryMetadata),
- ) + "\n",
- ),
- );
- applyMetadata(entry, entryMetadata);
- applyMetadata(feedEntries, entryMetadata);
- feed.appendChild(entry);
- }
+ // Iterate over each dated directory and process its entries.
+ for (
+ const { name: entryName } of Array.from(
+ Deno.readDirSync(`${basePath}/${date}/`),
+ ).filter(({ name: entryName, isDirectory }) =>
+ // Exclude non‐entry directories.
+ isDirectory &&
+ //deno-lint-ignore no-control-regex
+ !/[\x00-\x20\x22#%/<>?\\^\x60{|}\x7F]/u.test(entryName)
+ ).sort(({ name: a }, { name: b }) => a < b ? -1 : a > b ? 1 : 0)
+ ) {
+ // Iterate over each entry directory and process its contents.
+ const entry = document.createElement("entry");
+ const entryPath = `${basePath}/${date}/${entryName}/#entry.rdf`;
+ const entryDocument = parser.parseFromString(
+ await Deno.readTextFile(entryPath),
+ "application/xml",
+ );
+ const { documentElement: entryRoot } = entryDocument;
+ entryDocument.lastModified = (await Deno.lstat(entryPath)).mtime;
+ if (!entryRoot.hasAttributeNS(RDF, "about")) {
+ // The entry doesn’t have an identifier; let’s give it one.
+ entryRoot.setAttributeNS(
+ RDF,
+ "about",
+ new URL(`./${date}/${entryName}/`, feedURI),
+ );
+ } else {
+ // The entry already has an identifier.
+ /* do nothing */