From e41de5f50943315c3fa8596cc284f0c234311a7b Mon Sep 17 00:00:00 2001 From: Adam Pardyl Date: Sun, 23 Jun 2019 19:56:02 +0200 Subject: [PATCH] Better page titles --- .../controllers/FilesystemController.kt | 22 ++++++++++++++----- .../resources/templates/preview_code.html | 2 +- .../resources/templates/preview_image.html | 2 +- .../resources/templates/preview_page.html | 2 +- .../templates/preview_too_large.html | 2 +- src/main/resources/templates/tree.html | 2 +- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/controllers/FilesystemController.kt b/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/controllers/FilesystemController.kt index ad03e5a..0b08598 100644 --- a/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/controllers/FilesystemController.kt +++ b/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/controllers/FilesystemController.kt @@ -51,13 +51,18 @@ class FilesystemController( return pathBreadcrumb } + private fun createTitle(path: String): String { + return path.trim('/').replace("/", " / ") + (if (path.isNotEmpty()) " - " else "") + "Mordor" + } + private fun urlEncodePath(path: String): String { return UriUtils.encodePath(path, "UTF-8") } - private fun previewText(entity: RepositoryFile): ModelAndView { + private fun previewText(entity: RepositoryFile, path: String): ModelAndView { if (entity.file.length() > maxTextBytes) { return ModelAndView("preview_too_large", mapOf( + "title" to createTitle(path), "path" to createBreadcrumb(entity), "download" to "/download/${entity.relativePath}" )) @@ -65,20 +70,23 @@ class FilesystemController( val text = FileUtils.readFileToString(entity.file, "utf-8") // TODO: detect encoding return ModelAndView("preview_code", mapOf( + "title" to createTitle(path), "text" to text, "path" to createBreadcrumb(entity), "download" to "/download/${entity.relativePath}" )) } - private fun previewImage(entity: RepositoryFile): ModelAndView { + private fun previewImage(entity: RepositoryFile, path: String): ModelAndView { if (entity.file.length() > maxImageBytes) { return ModelAndView("preview_too_large", mapOf( + "title" to createTitle(path), "path" to createBreadcrumb(entity), "download" to "/download/${entity.relativePath}" )) } return ModelAndView("preview_image", mapOf( + "title" to createTitle(path), "path" to createBreadcrumb(entity), "download" to "/download/${entity.relativePath}" )) @@ -86,6 +94,7 @@ class FilesystemController( private fun previewPage(entity: RepositoryFile, path: String): ModelAndView { return ModelAndView("preview_page", mapOf( + "title" to createTitle(path), "raw" to "/raw/$path", "path" to createBreadcrumb(entity), "download" to "/download/${entity.relativePath}" @@ -111,12 +120,15 @@ class FilesystemController( if (entry is RepositoryDirectory) "/" else "", entry.name, iconNameProvider.getIconName(entry)) } - return ModelAndView("tree", mapOf("children" to sortedChildren, "path" to createBreadcrumb(entity))) + return ModelAndView("tree", mapOf( + "title" to createTitle(path), + "children" to sortedChildren, + "path" to createBreadcrumb(entity))) } else if (entity is RepositoryFile) { when { entity.isPage -> return previewPage(entity, path) - entity.mimeType.startsWith("text/") || entity.isCode -> return previewText(entity) - entity.isDisplayableImage -> return previewImage(entity) + entity.mimeType.startsWith("text/") || entity.isCode -> return previewText(entity, path) + entity.isDisplayableImage -> return previewImage(entity, path) } } return ModelAndView(RedirectView(urlEncodePath("/download/${entity.relativePath}"))) diff --git a/src/main/resources/templates/preview_code.html b/src/main/resources/templates/preview_code.html index 094ba5d..ff3a24d 100644 --- a/src/main/resources/templates/preview_code.html +++ b/src/main/resources/templates/preview_code.html @@ -2,7 +2,7 @@ - Mordor + Mordor diff --git a/src/main/resources/templates/preview_image.html b/src/main/resources/templates/preview_image.html index f1b0519..800e821 100644 --- a/src/main/resources/templates/preview_image.html +++ b/src/main/resources/templates/preview_image.html @@ -2,7 +2,7 @@ - Mordor + Mordor
diff --git a/src/main/resources/templates/preview_page.html b/src/main/resources/templates/preview_page.html index f467090..f88c0e6 100644 --- a/src/main/resources/templates/preview_page.html +++ b/src/main/resources/templates/preview_page.html @@ -2,7 +2,7 @@ - Mordor + Mordor
diff --git a/src/main/resources/templates/preview_too_large.html b/src/main/resources/templates/preview_too_large.html index 030b65f..22ac682 100644 --- a/src/main/resources/templates/preview_too_large.html +++ b/src/main/resources/templates/preview_too_large.html @@ -2,7 +2,7 @@ - Mordor + Mordor
diff --git a/src/main/resources/templates/tree.html b/src/main/resources/templates/tree.html index 8cdb5dc..978866e 100644 --- a/src/main/resources/templates/tree.html +++ b/src/main/resources/templates/tree.html @@ -2,7 +2,7 @@ - Mordor + Mordor