Skip to content

Commit

Permalink
fix(docker): embedded fonts would not load properly
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Jan 27, 2025
1 parent 4a17eab commit e5e534a
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import kotlin.io.path.isReadable
import kotlin.io.path.isRegularFile
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.name
import kotlin.io.path.toPath

private val logger = KotlinLogging.logger {}

Expand All @@ -42,11 +41,9 @@ class FontsController(
resolver
.getResources("/embeddedFonts/**/*.*")
.filterNot { it.filename == null }
.filter { supportedExtensions.contains(it.uri.toPath().extension, true) }
.filter { supportedExtensions.contains(Path(it.uri.toString()).extension, true) }
.groupBy {
it.uri
.toPath()
.parent.name
Path(it.uri.toString()).parent.name
}
} catch (e: Exception) {
logger.error(e) { "Could not load embedded fonts" }
Expand Down Expand Up @@ -92,7 +89,7 @@ class FontsController(
@PathVariable fontFile: String,
): ResponseEntity<Resource> {
fonts[fontFamily]?.let { resources ->
val resource = resources.firstOrNull { it.uri.toPath().name == fontFile } ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
val resource = resources.firstOrNull { it.filename == fontFile } ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
return ResponseEntity
.ok()
.headers {
Expand All @@ -111,7 +108,7 @@ class FontsController(
@PathVariable fontFamily: String,
): ResponseEntity<Resource> {
fonts[fontFamily]?.let { files ->
val groups = files.groupBy { getFontCharacteristics(it.uri.toPath().name) }
val groups = files.groupBy { getFontCharacteristics(Path(it.uri.toString()).name) }

val css =
groups
Expand All @@ -137,7 +134,7 @@ class FontsController(
): String {
val srcBlock =
fonts.joinToString(separator = ",", postfix = ";") { resource ->
val path = resource.uri.toPath()
val path = Path(resource.uri.toString())
"""url('${path.name}') format('${path.extension}')"""
}
// language=CSS
Expand Down

0 comments on commit e5e534a

Please sign in to comment.