Skip to content

Commit

Permalink
Config: Rename theme_url to themes_url, add plugins_url, assets_url a…
Browse files Browse the repository at this point in the history
…nd assets_dir
  • Loading branch information
PhrozenByte committed Jul 14, 2019
1 parent 38bb0a4 commit 33117be
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
7 changes: 6 additions & 1 deletion config/config.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

##
Expand Down
43 changes: 36 additions & 7 deletions lib/Pico.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,16 +910,19 @@ protected function loadConfig()
'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',
'pages_order_by' => 'alpha',
'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']) {
Expand All @@ -943,10 +946,16 @@ protected function loadConfig()
}
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(
Expand Down Expand Up @@ -989,6 +998,18 @@ protected function loadConfig()
} 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']);
}
}

/**
Expand Down Expand Up @@ -1486,8 +1507,13 @@ public function substituteFileContent($markdown, array $meta = array())
}
$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) {
Expand Down Expand Up @@ -2005,8 +2031,11 @@ protected function getTwigVariables()
'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,
Expand Down

0 comments on commit 33117be

Please sign in to comment.