This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-fluido-skin.git
commit bd88de12206e710db307eb96d66b8b315ef7ebd7 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Tue Nov 3 21:41:54 2026 +0100 Show the theme switch only when the dark theme is enabled The switch was on by default, so every site got a theme button and the theme script even when it never meant to offer a dark theme. Pages are now light with no switch and no theme script unless darkThemeEnabled is set; then the switch shows too, and themeSwitch=false still removes it while the page keeps following the browser's colour scheme. --- src/it/mskins-255/verify.groovy | 4 ++++ src/it/mskins-255_default/verify.groovy | 4 ++++ src/it/sidebar/verify.groovy | 14 ++++++-------- src/it/theme-switch_false/src/site/site.xml | 1 + src/it/theme-switch_false/verify.groovy | 7 ++++--- src/main/resources/META-INF/maven/site.vm | 7 ++++--- src/main/resources/META-INF/maven/skin.xml | 2 +- src/site/markdown/index.md.vm | 12 ++++++------ 8 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/it/mskins-255/verify.groovy b/src/it/mskins-255/verify.groovy index 73b5325..2278d2f 100644 --- a/src/it/mskins-255/verify.groovy +++ b/src/it/mskins-255/verify.groovy @@ -25,3 +25,7 @@ assert new File( basedir, "target/site/js/fluido-theme.js" ).exists() // no separate dark stylesheet any more assert !html.contains( 'dark-theme.css' ) assert !new File( basedir, "target/site/css/dark-theme.css" ).exists() + +// with the dark theme enabled the switch shows (fluido-theme.js unhides it) in the page tools of the menu +assert html.contains( '<button type="button" class="theme-switch btn btn-sm border" title="Theme" aria-label="Theme" hidden>' ) +assert html.indexOf( 'class="theme-switch' ) > html.indexOf( 'id="sidebarMenu"' ) diff --git a/src/it/mskins-255_default/verify.groovy b/src/it/mskins-255_default/verify.groovy index 0af6da1..37f995a 100644 --- a/src/it/mskins-255_default/verify.groovy +++ b/src/it/mskins-255_default/verify.groovy @@ -22,3 +22,7 @@ String html = new File( basedir, "target/site/index.html" ).text assert !html.contains( 'dark-theme.css' ) assert !new File( basedir, "target/site/css/dark-theme.css" ).exists() assert !html.contains( 'data-bs-theme' ) +// and so is the switch: without darkThemeEnabled there is neither a switch nor the theme script +assert !html.contains( 'theme-switch' ) +assert !html.contains( 'fluido-theme.js' ) +assert !new File( basedir, "target/site/js/fluido-theme.js" ).exists() diff --git a/src/it/sidebar/verify.groovy b/src/it/sidebar/verify.groovy index ded5add..ed9b74f 100644 --- a/src/it/sidebar/verify.groovy +++ b/src/it/sidebar/verify.groovy @@ -54,13 +54,11 @@ assert new File( basedir, "target/site/js/bootstrap-5.3.8.bundle.min.js" ).exist assert html.contains( '<main id="bodyColumn" class="col-lg-9 col-xl-10">' ) assert html.contains( '<header id="leftColumn" class="col-lg-3 col-xl-2">' ) assert html.indexOf( 'id="leftColumn"' ) < html.indexOf( 'id="bodyColumn"' ) -// the theme switch is on by default: light until the reader chooses, script in the head -assert html.contains( '<button type="button" class="theme-switch btn btn-sm border" title="Theme" aria-label="Theme" hidden>' ) -assert html.contains( 'class="theme-icon-dark"' ) -// the switch sits in the menu, after the panel's header -assert html.indexOf( 'class="theme-switch' ) > html.indexOf( 'id="sidebarMenu"' ) +// the dark theme is not enabled: no theme switch, no theme script, the page stays light +assert !html.contains( 'theme-switch' ) assert !html.contains( 'data-fluido-theme=' ) -assert html.contains( '<script src="./js/fluido-theme.js"></script>' ) +assert !html.contains( 'fluido-theme.js' ) +assert !new File( basedir, "target/site/js/fluido-theme.js" ).exists() // wide tables scroll in their own focusable box (and stack on phones); code blocks are focusable too String deps = new File( basedir, "target/site/dependencies.html" ).text @@ -70,8 +68,8 @@ assert html =~ /<pre tabindex="0" class="prettyprint linenums">/ for ( String icon : [ 'error', 'help', 'info', 'success', 'warning' ] ) { assert new File( basedir, "target/site/images/icon_${icon}_sml.gif" ).exists() } -// the Edit icon sits next to the theme switch in the menu -assert html =~ /(?s)<div class="page-tools d-flex align-items-center gap-2 mb-2 px-3"><button type="button" class="theme-switch[^>]*>.*?<\/button>\s*<a class="edit-link btn btn-sm border" href="[^"]+"/ +// the Edit icon sits at the top of the menu +assert html =~ /<div class="page-tools d-flex align-items-center gap-2 mb-2 px-3"><a class="edit-link btn btn-sm border" href="[^"]+"/ // pages listed in sideBarSkipped render without the side menu, the others keep it String summary = new File( basedir, "target/site/summary.html" ).text diff --git a/src/it/theme-switch_false/src/site/site.xml b/src/it/theme-switch_false/src/site/site.xml index b5ce6f9..98880a2 100644 --- a/src/it/theme-switch_false/src/site/site.xml +++ b/src/it/theme-switch_false/src/site/site.xml @@ -39,6 +39,7 @@ <custom> <fluidoSkin> + <darkThemeEnabled>true</darkThemeEnabled> <themeSwitch>false</themeSwitch> </fluidoSkin> </custom> diff --git a/src/it/theme-switch_false/verify.groovy b/src/it/theme-switch_false/verify.groovy index 7f7fa0e..ef62612 100644 --- a/src/it/theme-switch_false/verify.groovy +++ b/src/it/theme-switch_false/verify.groovy @@ -19,7 +19,8 @@ String html = new File( basedir, "target/site/index.html" ).text -// themeSwitch false: no switch and no theme script, so the page stays light +// darkThemeEnabled with themeSwitch false: no switch, but the theme script still follows the OS colour scheme assert !html.contains( 'theme-switch' ) -assert !html.contains( 'fluido-theme.js' ) -assert !html.contains( 'data-bs-theme' ) +assert html.contains( 'data-fluido-theme="auto"' ) +assert html.indexOf( 'js/fluido-theme.js' ) < html.indexOf( '</head>' ) +assert new File( basedir, "target/site/js/fluido-theme.js" ).exists() diff --git a/src/main/resources/META-INF/maven/site.vm b/src/main/resources/META-INF/maven/site.vm index ab304dc..ae40aab 100644 --- a/src/main/resources/META-INF/maven/site.vm +++ b/src/main/resources/META-INF/maven/site.vm @@ -29,9 +29,10 @@ | Rendered using Apache Maven Fluido Skin @project.version@ --> ## -## colour theme: light by default; darkThemeEnabled makes Auto (follow the OS) the default; themeSwitch adds the switch +## colour theme: light, with no switch and no theme script, unless darkThemeEnabled makes Auto (follow the OS) the +## default; then the switch shows too, unless themeSwitch is false #set( $darkThemeEnabled = $convert.toBoolean( $site.getCustomValue( 'fluidoSkin.darkThemeEnabled', 'false' ) ) ) -#set( $themeSwitch = $convert.toBoolean( $site.getCustomValue( 'fluidoSkin.themeSwitch', 'true' ) ) ) +#set( $themeSwitch = $darkThemeEnabled && $convert.toBoolean( $site.getCustomValue( 'fluidoSkin.themeSwitch', 'true' ) ) ) <html xmlns="http://www.w3.org/1999/xhtml" lang="#if ( $locale.toString() )$locale.toLanguageTag()#{else}en#end"#if( $darkThemeEnabled ) data-fluido-theme="auto"#end> <head> <meta charset="${outputEncoding}" /> @@ -55,7 +56,7 @@ <link rel="stylesheet" href="$relativePath/css/[email protected][email protected]" /> <link rel="stylesheet" href="$relativePath/css/[email protected][email protected]" /> ## sets Bootstrap's colour mode before the first paint; without it the page stays light -#if( $themeSwitch || $darkThemeEnabled ) +#if( $darkThemeEnabled ) <script src="$relativePath/js/fluido-theme.js"></script> #end <link rel="stylesheet" href="$relativePath/css/site.css" /> diff --git a/src/main/resources/META-INF/maven/skin.xml b/src/main/resources/META-INF/maven/skin.xml index a88e98b..6e5e51f 100644 --- a/src/main/resources/META-INF/maven/skin.xml +++ b/src/main/resources/META-INF/maven/skin.xml @@ -36,7 +36,7 @@ under the License. </resource-condition> <resource-condition> <resource-name>js/fluido-theme.js</resource-name> - <vtl-condition><![CDATA[#if( !$site.getCustomValue( 'fluidoSkin.themeSwitch', 'true' ).equalsIgnoreCase( 'false' ) || $site.getCustomValue( 'fluidoSkin.darkThemeEnabled', 'false' ).equalsIgnoreCase( 'true' ) )true#end]]></vtl-condition> + <vtl-condition><![CDATA[#if( $site.getCustomValue( 'fluidoSkin.darkThemeEnabled', 'false' ).equalsIgnoreCase( 'true' ) )true#end]]></vtl-condition> </resource-condition> <resource-condition> <resource-name>images/profiles/pre-release.svg</resource-name> diff --git a/src/site/markdown/index.md.vm b/src/site/markdown/index.md.vm index d9d2925..23129cf 100644 --- a/src/site/markdown/index.md.vm +++ b/src/site/markdown/index.md.vm @@ -427,12 +427,11 @@ Since version **1\.3\.1**, you can configure the breadcrumb divider (default is ${esc.h}${esc.h}${esc.h} <a id="Dark_Theme"></a>Dark Theme -Pages are light by default. A theme switch in the breadcrumbs bar lets the reader choose Light, Dark or Auto (follows -the operating system) and keeps the choice for the next pages; it maps the choice onto Bootstrap's colour modes. Without -JavaScript the switch does not show and pages stay light. +Pages are light by default, with no theme switch and no theme script. -With `darkThemeEnabled` (since **2\.2\.0**), Auto is the default, so the dark theme activates based on the browser -preferences until the reader chooses otherwise: +With `darkThemeEnabled` (since **2\.2\.0**), the dark theme activates based on the browser preferences (Auto), and a +theme switch at the top of the menu lets the reader choose Light, Dark or Auto; the choice is kept for the next pages. +Both map onto Bootstrap's colour modes and need JavaScript: without it pages stay light and the switch does not show. ```xml <site xmlns="http://maven.apache.org/SITE/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" @@ -447,7 +446,7 @@ preferences until the reader chooses otherwise: </site> ``` -To remove the switch, set `themeSwitch` to `false`: +To keep the dark theme following the browser but remove the switch, also set `themeSwitch` to `false`: ```xml <site xmlns="http://maven.apache.org/SITE/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" @@ -455,6 +454,7 @@ To remove the switch, set `themeSwitch` to `false`: [...] <custom> <fluidoSkin> + <darkThemeEnabled>true</darkThemeEnabled> <themeSwitch>false</themeSwitch> </fluidoSkin> </custom>
