Allow configuring Parsedown
This commit is contained in:
parent
5429a3a932
commit
d4c65fa523
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
site_title: Pico # The title of your website
|
site_title: Pico # The title of your website
|
||||||
base_url: ~ # Pico will try to guess its base URL, if this fails, override it here
|
base_url: ~ # Pico will try to guess its base URL, if this fails, override it here
|
||||||
# Example: http://example.com/pico/
|
# Example: http://example.com/pico/
|
||||||
rewrite_url: ~ # A boolean (true or false) indicating whether URL rewriting is forced
|
rewrite_url: ~ # A boolean (true or false) indicating whether URL rewriting is forced
|
||||||
timezone: UTC # Your PHP installation might require you to manually specify a timezone
|
timezone: UTC # Your PHP installation might require you to manually specify a timezone
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ timezone: UTC # Your PHP installation might require you to
|
|||||||
#
|
#
|
||||||
theme: default # The name of your custom 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
|
theme_url: ~ # Pico will try to guess the URL to the themes dir of your installation
|
||||||
# If this fails, override it here. Example: http://example.com/pico/themes/
|
# If this fails, override it here. Example: http://example.com/pico/themes/
|
||||||
theme_config:
|
theme_config:
|
||||||
widescreen: false # Default theme: Use more horicontal space (i.e. make the site container wider)
|
widescreen: false # Default theme: Use more horicontal space (i.e. make the site container wider)
|
||||||
twig_config:
|
twig_config:
|
||||||
@ -24,11 +24,18 @@ twig_config:
|
|||||||
# Content
|
# Content
|
||||||
#
|
#
|
||||||
date_format: %D %T # Pico's default date format
|
date_format: %D %T # Pico's default date format
|
||||||
# List of available variables: http://php.net/manual/en/function.strftime.php
|
# See http://php.net/manual/en/function.strftime.php for more info
|
||||||
pages_order_by: alpha # Change how Pico sorts pages ("alpha" for alphabetical order, or "date")
|
pages_order_by: alpha # Change how Pico sorts pages ("alpha" for alphabetical order, or "date")
|
||||||
pages_order: asc # Sort pages in ascending ("asc") or descending ("desc") order
|
pages_order: asc # Sort pages in ascending ("asc") or descending ("desc") order
|
||||||
content_dir: content/ # The path to Pico's content directory
|
content_dir: content/ # The path to Pico's content directory
|
||||||
content_ext: .md # The file extension of your Markdown files
|
content_ext: .md # The file extension of your Markdown files
|
||||||
|
content_config:
|
||||||
|
extra: true # Use the Parsedown Extra parser to support extended markup
|
||||||
|
# See https://michelf.ca/projects/php-markdown/extra/ for more info
|
||||||
|
breaks: false # A boolean indicating whether breaks in the markup should be reflected in the
|
||||||
|
# parsed contents of the page
|
||||||
|
escape: false # Escape HTML markup in your content files
|
||||||
|
auto_urls: true # Automatically link URLs found in your markup
|
||||||
|
|
||||||
##
|
##
|
||||||
# Plugins
|
# Plugins
|
||||||
|
52
lib/Pico.php
52
lib/Pico.php
@ -695,15 +695,16 @@ class Pico
|
|||||||
'site_title' => 'Pico',
|
'site_title' => 'Pico',
|
||||||
'base_url' => '',
|
'base_url' => '',
|
||||||
'rewrite_url' => null,
|
'rewrite_url' => null,
|
||||||
|
'timezone' => null,
|
||||||
'theme' => 'default',
|
'theme' => 'default',
|
||||||
'theme_url' => null,
|
'theme_url' => null,
|
||||||
|
'twig_config' => null,
|
||||||
'date_format' => '%D %T',
|
'date_format' => '%D %T',
|
||||||
'twig_config' => array('cache' => false, 'autoescape' => false, 'debug' => false),
|
|
||||||
'pages_order_by' => 'alpha',
|
'pages_order_by' => 'alpha',
|
||||||
'pages_order' => 'asc',
|
'pages_order' => 'asc',
|
||||||
'content_dir' => null,
|
'content_dir' => null,
|
||||||
'content_ext' => '.md',
|
'content_ext' => '.md',
|
||||||
'timezone' => null
|
'content_config' => null
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$this->config['base_url']) {
|
if (!$this->config['base_url']) {
|
||||||
@ -716,6 +717,29 @@ class Pico
|
|||||||
$this->config['rewrite_url'] = $this->isUrlRewritingEnabled();
|
$this->config['rewrite_url'] = $this->isUrlRewritingEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->config['timezone']) {
|
||||||
|
// explicitly set a default timezone to prevent a E_NOTICE
|
||||||
|
// when no timezone is set; the `date_default_timezone_get()`
|
||||||
|
// function always returns a timezone, at least UTC
|
||||||
|
$this->config['timezone'] = @date_default_timezone_get();
|
||||||
|
}
|
||||||
|
date_default_timezone_set($this->config['timezone']);
|
||||||
|
|
||||||
|
if (!$this->config['theme_url']) {
|
||||||
|
$this->config['theme_url'] = $this->getBaseThemeUrl();
|
||||||
|
} elseif (preg_match('#^[A-Za-z][A-Za-z0-9+\-.]*://#', $this->config['theme_url'])) {
|
||||||
|
$this->config['theme_url'] = rtrim($this->config['theme_url'], '/') . '/';
|
||||||
|
} else {
|
||||||
|
$this->config['theme_url'] = $this->getBaseUrl() . rtrim($this->config['theme_url'], '/') . '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
$defaultTwigConfig = array('cache' => false, 'autoescape' => false, 'debug' => false);
|
||||||
|
if (!is_array($this->config['twig_config'])) {
|
||||||
|
$this->config['twig_config'] = $defaultTwigConfig;
|
||||||
|
} else {
|
||||||
|
$this->config['twig_config'] += $defaultTwigConfig;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->config['content_dir']) {
|
if (!$this->config['content_dir']) {
|
||||||
// try to guess the content directory
|
// try to guess the content directory
|
||||||
if (is_dir($this->getRootDir() . 'content')) {
|
if (is_dir($this->getRootDir() . 'content')) {
|
||||||
@ -727,21 +751,12 @@ class Pico
|
|||||||
$this->config['content_dir'] = $this->getAbsolutePath($this->config['content_dir']);
|
$this->config['content_dir'] = $this->getAbsolutePath($this->config['content_dir']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->config['theme_url']) {
|
$defaultContentConfig = array('extra' => true, 'breaks' => false, 'escape' => false, 'auto_urls' => true);
|
||||||
$this->config['theme_url'] = $this->getBaseThemeUrl();
|
if (!is_array($this->config['content_config'])) {
|
||||||
} elseif (preg_match('#^[A-Za-z][A-Za-z0-9+\-.]*://#', $this->config['theme_url'])) {
|
$this->config['content_config'] = $defaultContentConfig;
|
||||||
$this->config['theme_url'] = rtrim($this->config['theme_url'], '/') . '/';
|
|
||||||
} else {
|
} else {
|
||||||
$this->config['theme_url'] = $this->getBaseUrl() . rtrim($this->config['theme_url'], '/') . '/';
|
$this->config['content_config'] += $defaultContentConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->config['timezone']) {
|
|
||||||
// explicitly set a default timezone to prevent a E_NOTICE
|
|
||||||
// when no timezone is set; the `date_default_timezone_get()`
|
|
||||||
// function always returns a timezone, at least UTC
|
|
||||||
$this->config['timezone'] = @date_default_timezone_get();
|
|
||||||
}
|
|
||||||
date_default_timezone_set($this->config['timezone']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1139,7 +1154,12 @@ class Pico
|
|||||||
public function getParsedown()
|
public function getParsedown()
|
||||||
{
|
{
|
||||||
if ($this->parsedown === null) {
|
if ($this->parsedown === null) {
|
||||||
$this->parsedown = new ParsedownExtra();
|
$className = $this->config['content_config']['extra'] ? 'ParsedownExtra' : 'Parsedown';
|
||||||
|
$this->parsedown = new $className();
|
||||||
|
|
||||||
|
$this->parsedown->setBreaksEnabled((bool) $this->config['content_config']['breaks']);
|
||||||
|
$this->parsedown->setMarkupEscaped((bool) $this->config['content_config']['escape']);
|
||||||
|
$this->parsedown->setUrlsLinked((bool) $this->config['content_config']['auto_urls']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->parsedown;
|
return $this->parsedown;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user