Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom CSS Capability #315

Merged
merged 10 commits into from
Oct 11, 2023
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ architecture model:
| `generatr.style.colors.secondary` | Secondary site color, used for font color in header bar and for active menu. | `#cccccc` | `#ffffff` |
| `generatr.style.faviconPath` | Site logo location relative to the configured `assets` folder. When configured, the logo image will be place on the left side in the header bar. This requires the `--assets-dir` switch when generating the site and the corresponding file to be available in the `assets` folder. | | `site/favicon.ico` |
| `generatr.style.logoPath` | Site favicon location relative to the configured `assets` folder. When configured, the favicon will be set for all generated pages. This requires the `--assets-dir` switch when generating the site and the corresponding file to be available in the `assets` folder. | | `site/logo.png` |
| `generatr.style.customCSSPath` | Site custom css location relative to the configured `assets` folder. When configured this css file will be loaded for all pages. This requires the `--assets-dir` switch when generating the site and the corresponding file to be available in the `assets` folder. | | `site/custom.css` |
qtzar marked this conversation as resolved.
Show resolved Hide resolved
| `generatr.search.language` | Indexing/stemming language for the search index. See [Lunr language support](https://github.com/olivernn/lunr-languages) | `en` | `nl` |
| `generatr.markdown.flexmark.extensions` | Additional extensions to the markdown generator to add new markdown capabilities. [More Details](https://avisi-cloud.github.io/structurizr-site-generatr/main/extended-markdown-features/) | Tables | `Tables,Admonition` |
| `generatr.svglink.target` | Specifies the link target for element links in the exported svg | `_top` | `_self` |
Expand Down
12 changes: 12 additions & 0 deletions docs/example/assets/site/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
svg g g[id^="link"]:hover path {
stroke:#FF0000 !important;
stroke-width: 2.0;
}

svg g g[id^="link"]:hover polygon {
stroke:#FF0000 !important;
}

svg g g[id^="link"]:hover text {
fill:#FF0000 !important;
}
1 change: 1 addition & 0 deletions docs/example/workspace.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ workspace "Big Bank plc" "This is an example workspace to illustrate the key fea
"generatr.style.colors.secondary" "#ffffff"
"generatr.style.faviconPath" "site/favicon.ico"
"generatr.style.logoPath" "site/logo.png"
"generatr.style.customCSSPath" "site/custom.css"
"generatr.svglink.target" "_self"

// full list of available "generatr.markdown.flexmark.extensions"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package nl.avisi.structurizr.site.generatr.site.model

import nl.avisi.structurizr.site.generatr.site.GeneratorContext
import nl.avisi.structurizr.site.generatr.site.asUrlToFile
import java.io.File

class CustomCSSViewModel(generatorContext: GeneratorContext, pageViewModel: PageViewModel) {
val url = customCSSPath(generatorContext)?.let { "/$it".asUrlToFile(pageViewModel.url) }
val type = extractType()
qtzar marked this conversation as resolved.
Show resolved Hide resolved
val includecustomCSS = url != null

private fun customCSSPath(generatorContext: GeneratorContext) =
generatorContext.workspace.views.configuration.properties
.getOrDefault(
"generatr.style.customCSSPath",
null
)

private fun extractType(): String? {
return url?.let {
val extension = File(it).extension.lowercase()
if (extension.isBlank() || !arrayOf("css").contains(extension))
throw IllegalArgumentException("Custom CSS must be a valid *.css file")

"image/$extension"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ abstract class PageViewModel(protected val generatorContext: GeneratorContext) {
pageSubTitle
}
val favicon by lazy { FaviconViewModel(generatorContext, this) }
val customCSS by lazy { CustomCSSViewModel(generatorContext, this) }
val headerBar by lazy { HeaderBarViewModel(this, generatorContext) }
val menu by lazy { MenuViewModel(generatorContext, this) }
val includeAutoReloading = generatorContext.serving

val flexmarkConfig by lazy {
buildFlexmarkConfig(generatorContext)
}
val flexmarkConfig by lazy { buildFlexmarkConfig(generatorContext) }
val includeAdmonition = flexmarkConfig.selectedExtensionMap.containsKey("Admonition")
val includeKatex = flexmarkConfig.selectedExtensionMap.containsKey("GitLab")

val configuration = generatorContext.workspace.views.configuration.properties

abstract val url: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ private fun HTML.headFragment(viewModel: PageViewModel) {
meta(name = "viewport", content = "width=device-width, initial-scale=1")
title { +viewModel.pageTitle }
link(rel = "stylesheet", href = "https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css")
link(
rel = "stylesheet",
href = "../" + "/style.css".asUrlToFile(viewModel.url)
)
link(
rel = "stylesheet",
href = "./" + "/style-branding.css".asUrlToFile(viewModel.url)
)
link(rel = "stylesheet", href = "../" + "/style.css".asUrlToFile(viewModel.url))
link(rel = "stylesheet", href = "./" + "/style-branding.css".asUrlToFile(viewModel.url))

if (viewModel.includeAdmonition)
if (viewModel.includeAdmonition)
markdownAdmonitionStylesheet(viewModel)

if (viewModel.includeKatex)
Expand All @@ -42,6 +36,10 @@ private fun HTML.headFragment(viewModel: PageViewModel) {

if (viewModel.includeAutoReloading)
autoReloadScript(viewModel)

if (viewModel.customCSS.includecustomCSS){
link(rel = "stylesheet", href = "./" + viewModel.customCSS.url)
}
}
}

Expand Down