1 #!/usr/bin
/env 
-S deno run 
--allow
-read 
--allow
-write
 
   3 // Copyright © 2023 Lady [@ Lady’s Computer]. 
   5 // This Source Code Form is subject to the terms of the Mozilla Public 
   6 // License, v. 2.0. If a copy of the MPL was not distributed with this 
   7 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>. 
   9 import hljs 
from "npm:highlight.js@11.8.0"; 
  11 const contentLinks 
= new WeakMap(); 
  13 const processContent = function (content
) { 
  14   if (content 
== null || Object(content
) instanceof String
) { 
  15     // The provided content is nullish or a string. 
  17   } else if (Array
.isArray(content
)) { 
  18     // The provided content is an array. 
  19     content
.forEach(processContent
.bind(this)); 
  21     // The provided content is a NodeList. 
  22     for (const child 
of Array
.from(content
)) { 
  23       applyTransforms
.call(this, child
); 
  28 const applyTransforms = function (node
) { 
  30     node
.localName 
== "pre" && node
.childNodes
.length 
== 1 && 
  31     node
.firstChild
.localName 
== "code" 
  33     // This is a code block and should be highlighted. 
  34     const code 
= node
.firstChild
; 
  35     const language 
= /language-(.*)/u.exec(code
.getAttribute("class")) 
  39         const { value: highlight 
} = hljs
.highlight( 
  40           node
.firstChild
.textContent
, 
  43         const nodes 
= new DOMParser().parseFromString( 
  44           `<!DOCTYPE html><html><body>${highlight}</body></html>`, 
  46         ).documentElement
.lastChild
.childNodes
; 
  49           `hljs ${code.getAttribute("class")}`, 
  51         code
.textContent 
= ""; 
  52         for (const node 
of Array
.from(nodes
)) { 
  53           code
.appendChild(code
.ownerDocument
.importNode(node
, true)); 
  55         return; // don’t continue processing this node 
  60   } else if (node
.localName 
== "a") { 
  61     const href 
= node
.getAttribute("href"); 
  62     const title 
= node
.getAttribute("title"); 
  64       contentLinks
.get(this)[title
] = href
; 
  67   if (node
.nodeType 
== 1) { 
  68     // This is an element; process its children. 
  69     Array
.from(node
.childNodes
).forEach(applyTransforms
.bind(this)); 
  70   } else if (node
.nodeType 
== 3) { 
  71     // This is a text node; apply replacements. 
  72     node
.textContent 
= node
.textContent
.replaceAll(":—", ":\u2060—"); 
  76 globalThis
.bj
ørnTransformMetadata 
= (metadata
, _type
) => { 
  77   contentLinks
.set(metadata
, {}); 
  78   processContent
.call(metadata
, metadata
.content
); 
  79   processContent
.call(metadata
, metadata
.summary
); 
  82 globalThis
.bj
ørnTransformFeedHTML 
= (document
, _metadata
) => { 
  83   const LMN 
= Lemon
.bind({ document 
}); 
  84   const h1 
= document
.getElementsByTagNameNS( 
  85     "http://www.w3.org/1999/xhtml", 
  88   const link 
= LMN
.a
.href("/")``; 
  89   for (const child 
of Array
.from(h1
.childNodes
)) { 
  90     link
.appendChild(child
); 
  95 globalThis
.bj
ørnTransformEntryHTML 
= (document
, metadata
) => { 
  96   const LMN 
= Lemon
.bind({ document 
}); 
  97   const links 
= Object
.entries(contentLinks
.get(metadata
)); 
  99     document
.getElementById("entry.content").appendChild( 
 100       LMN
.footer
`${LMN.nav`${[ 
 101         LMN
.h2
`This post contains links.`, 
 103           links.map(([name, href]) => 
 104             LMN.li`${LMN.a.href(href)`${name}
`}` 
 113   "https://git.ladys.computer/Beorn/blob_plain/0.2.3:/build.js"