diff --git a/docs/10_For_Developers/Creating_a_Theme.md b/docs/10_For_Developers/Creating_a_Theme.md index 09608f7..4174a66 100644 --- a/docs/10_For_Developers/Creating_a_Theme.md +++ b/docs/10_For_Developers/Creating_a_Theme.md @@ -2,6 +2,11 @@ In its simplest form, a theme is an empty folder with a `config.json` file conta After that, every setting is optional, but you can override everything if you'd like to. +> **Overriding styles** +> +> If you want to tweak a few styles, you can create a `style.css` file at the root of your documentation +> directory and it will be included automatically. By doing this, you don't need to create a new theme. + ## `config.json` options Here is an example `config.json` file : diff --git a/libs/DauxHelper.php b/libs/DauxHelper.php index c429f00..79431f1 100644 --- a/libs/DauxHelper.php +++ b/libs/DauxHelper.php @@ -32,11 +32,18 @@ class DauxHelper */ protected static function getTheme(Config $config, $current_url) { + static $cache = []; + $htmlTheme = $config->getHTML()->getTheme(); $theme_folder = $config->getThemesPath() . DIRECTORY_SEPARATOR . $htmlTheme; $theme_url = $config->getBaseUrl() . 'themes/' . $htmlTheme . '/'; + $cache_key = "$current_url-$htmlTheme"; + if (array_key_exists($cache_key, $cache)) { + return $cache[$cache_key]; + } + $theme = []; if (is_file($theme_folder . DIRECTORY_SEPARATOR . 'config.json')) { $theme = json_decode(file_get_contents($theme_folder . DIRECTORY_SEPARATOR . 'config.json'), true); @@ -45,7 +52,7 @@ class DauxHelper } } - //Default parameters for theme + // Default parameters for theme $theme += [ 'name' => $htmlTheme, 'css' => [], @@ -54,6 +61,7 @@ class DauxHelper 'favicon' => 'themes/daux/img/favicon.png', 'templates' => $theme_folder . DIRECTORY_SEPARATOR . 'templates', 'variants' => [], + 'with_search' => $config->getHTML()->hasSearch() ]; if ($config->getHTML()->hasThemeVariant()) { @@ -77,6 +85,14 @@ class DauxHelper } } + if ($theme['with_search']) { + $theme['css'][] = 'daux_libraries/search.css'; + } + + if (is_file($config->getDocumentationDirectory() . DIRECTORY_SEPARATOR . 'style.css')) { + $theme['css'][]= 'style.css'; + } + $substitutions = [ '' => $config->getLocalBase(), '' => $current_url, @@ -93,6 +109,8 @@ class DauxHelper } } + $cache[$cache_key] = $theme; + return $theme; } diff --git a/templates/layout/00_layout.php b/templates/layout/00_layout.php index c4f7297..82ebd5b 100755 --- a/templates/layout/00_layout.php +++ b/templates/layout/00_layout.php @@ -48,11 +48,6 @@ getTheme()->getCSS() as $css) { ?> - - getHTML()->hasSearch()) { ?> - - - section('content'); ?>