From 33117be981aa9c8acb6b3f91c5513e4a266d7a9d Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 30 Apr 2019 15:34:11 +0200 Subject: [PATCH] Config: Rename theme_url to themes_url, add plugins_url, assets_url and assets_dir --- config/config.yml.template | 7 ++++++- lib/Pico.php | 43 +++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/config/config.yml.template b/config/config.yml.template index bdaa45e..b16cdd7 100644 --- a/config/config.yml.template +++ b/config/config.yml.template @@ -12,7 +12,7 @@ timezone: UTC # Your PHP installation might require you to # Theme # theme: default # The name of your custom theme -theme_url: ~ # Pico will try to guess the URL to the themes dir of your installation; +themes_url: ~ # Pico will try to guess the URL to the themes dir of your installation; # If this fails, override it here. Example: https://example.com/pico/themes/ theme_config: widescreen: false # Default theme: Use more horicontal space (i.e. make the site container wider) @@ -41,10 +41,15 @@ content_config: escape: false # Escape HTML markup in your content files; don't confuse this with some sort of # safe mode, enabling this doesn't allow you to process untrusted user input! auto_urls: true # Automatically link URLs found in your markup +assets_dir: assets/ # The path to Pico's assets directory +assets_url: ~ # Pico will try to guess the URL to the assets dir of your installation; + # If this fails, override it here. Example: https://example.com/pico/assets/ ## # Plugins # +plugins_url: ~ # Pico will try to guess the URL to the plugins dir of your installation; + # If this fails, override it here. Example: https://example.com/pico/plugins/ DummyPlugin.enabled: false # Force the plugin "DummyPlugin" to be disabled ## diff --git a/lib/Pico.php b/lib/Pico.php index f306801..adb1e10 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -910,8 +910,9 @@ class Pico 'rewrite_url' => null, 'debug' => null, 'timezone' => null, + 'plugins_url' => null, 'theme' => 'default', - 'theme_url' => null, + 'themes_url' => null, 'twig_config' => null, 'date_format' => '%D %T', 'pages_order_by_meta' => 'author', @@ -919,7 +920,9 @@ class Pico 'pages_order' => 'asc', 'content_dir' => null, 'content_ext' => '.md', - 'content_config' => null + 'content_config' => null, + 'assets_dir' => 'assets/', + 'assets_url' => null ); if (!$this->config['base_url']) { @@ -943,10 +946,16 @@ class Pico } date_default_timezone_set($this->config['timezone']); - if (!$this->config['theme_url']) { - $this->config['theme_url'] = $this->getUrlFromPath($this->getThemesDir()); + if (!$this->config['plugins_url']) { + $this->config['plugins_url'] = $this->getUrlFromPath($this->getPluginsDir()); } else { - $this->config['thems_url'] = $this->getAbsoluteUrl($this->config['theme_url']); + $this->config['plugins_url'] = $this->getAbsoluteUrl($this->config['plugins_url']); + } + + if (!$this->config['themes_url']) { + $this->config['themes_url'] = $this->getUrlFromPath($this->getThemesDir()); + } else { + $this->config['themes_url'] = $this->getAbsoluteUrl($this->config['themes_url']); } $defaultTwigConfig = array( @@ -989,6 +998,18 @@ class Pico } else { $this->config['content_config'] += $defaultContentConfig; } + + if (!$this->config['assets_dir']) { + $this->config['assets_dir'] = $this->getRootDir() . 'assets/'; + } else { + $this->config['assets_dir'] = $this->getAbsolutePath($this->config['assets_dir']); + } + + if (!$this->config['assets_url']) { + $this->config['assets_url'] = $this->getUrlFromPath($this->config['assets_dir']); + } else { + $this->config['assets_url'] = $this->getAbsoluteUrl($this->config['assets_url']); + } } /** @@ -1486,8 +1507,13 @@ class Pico } $variables['%base_url%'] = rtrim($this->getBaseUrl(), '/'); + // replace %plugins_url%, %themes_url% and %assets_url% + $variables['%plugins_url%'] = rtrim($this->getConfig('plugins_url'), '/'); + $variables['%themes_url%'] = rtrim($this->getConfig('themes_url'), '/'); + $variables['%assets_url%'] = rtrim($this->getConfig('assets_url'), '/'); + // replace %theme_url% - $variables['%theme_url%'] = $this->getConfig('theme_url') . $this->getConfig('theme'); + $variables['%theme_url%'] = $this->getConfig('themes_url') . $this->getConfig('theme'); // replace %meta.*% if ($meta) { @@ -2005,8 +2031,11 @@ class Pico 'config' => $this->getConfig(), 'base_dir' => rtrim($this->getRootDir(), '/'), 'base_url' => rtrim($this->getBaseUrl(), '/'), + 'plugins_url' => rtrim($this->getConfig('plugins_url'), '/'), + 'themes_url' => rtrim($this->getConfig('themes_url'), '/'), + 'assets_url' => rtrim($this->getConfig('assets_url'), '/'), 'theme_dir' => $this->getThemesDir() . $this->getConfig('theme'), - 'theme_url' => $this->getConfig('theme_url') . $this->getConfig('theme'), + 'theme_url' => $this->getConfig('themes_url') . $this->getConfig('theme'), 'site_title' => $this->getConfig('site_title'), 'meta' => $this->meta, 'content' => $this->content,