Sfoglia il codice sorgente

Config: Rename theme_url to themes_url, add plugins_url, assets_url and assets_dir

Daniel Rudolf 6 anni fa
parent
commit
33117be981
2 ha cambiato i file con 42 aggiunte e 8 eliminazioni
  1. 6 1
      config/config.yml.template
  2. 36 7
      lib/Pico.php

+ 6 - 1
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
 
 ##

+ 36 - 7
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,