Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,9 @@ object LaikaCustomizations {
}

val Icons = {
def loadFaIcon(prefix: String, name: String) = {
val resourcePath =
"/META-INF/resources/webjars/fortawesome__fontawesome-free/7.2.0"
val inputStream =
getClass.getResourceAsStream(s"$resourcePath/svgs/$prefix/$name.svg")
String(inputStream.readAllBytes())
}
val fa = WebJar("fortawesome__fontawesome-free")
def loadFaIcon(prefix: String, name: String) =
fa.load(s"svgs/$prefix/$name.svg")

Map(
// brands
Expand Down Expand Up @@ -439,11 +435,9 @@ object KaTeX {
import org.graalvm.polyglot.*
import scala.jdk.CollectionConverters.*

private def loadKaTeX(): String = {
val resourcePath = "/META-INF/resources/webjars/katex/0.16.44/dist/katex.js"
val inputStream = getClass.getResourceAsStream(resourcePath)
String(inputStream.readAllBytes())
}
private val katexJar = WebJar("katex")

private def loadKaTeX(): String = katexJar.load("dist/katex.js")

private lazy val katex = {
val ctx = Context
Expand Down Expand Up @@ -476,6 +470,32 @@ object KaTeX {

}

// Provides access to resources of a bundled WebJar.
class WebJar(artifactId: String) {
private val classLoader = classOf[WebJar].getClassLoader

private val version: String =
val propsPath = s"META-INF/maven/org.webjars.npm/$artifactId/pom.properties"
val stream = classLoader.getResourceAsStream(propsPath)
if stream == null then
throw IllegalStateException(
s"Could not find pom.properties for webjar '$artifactId' on the classpath."
)
val props = java.util.Properties()
props.load(stream)
props.getProperty("version")

// Load a resource from this WebJar as a String, uses relative paths.
def load(path: String): String =
val resourcePath = s"META-INF/resources/webjars/$artifactId/$version/$path"
val stream = classLoader.getResourceAsStream(resourcePath)
if stream == null then
throw IllegalStateException(
s"Could not find resource '$path' in webjar '$artifactId' ($version)."
)
String(stream.readAllBytes())
}

object Redirects {
import laika.io.model.InputTree
import laika.ast.Path.Root
Expand Down
Loading