Per-theme config, default attributes, and bump BS ver

This commit is contained in:
Belle Aerni 2023-03-26 23:29:17 -07:00
parent acb00af6f7
commit 70ff0a106f
6 changed files with 61 additions and 8 deletions

View File

@ -25,6 +25,7 @@ class AntCMS
{
$start_time = microtime(true);
$content = $this->getPage($page);
$themeConfig = Self::getThemeConfig();
if (!$content || !is_array($content)) {
$this->renderException("404");
@ -38,8 +39,9 @@ class AntCMS
'AntCMSAuthor' => $content['author'],
'AntCMSKeywords' => $content['keywords'],
'AntCMSBody' => AntMarkdown::renderMarkdown($content['content']),
'DisplayAuthor' => true,
'ThemeConfig' => $themeConfig['config'] ?? [],
];
$pageTemplate = $this->antTwig->renderWithTiwg($pageTemplate, $params);
$end_time = microtime(true);
@ -240,4 +242,20 @@ class AntCMS
header("Location: $url");
exit;
}
public static function getThemeConfig(string|null $theme = null)
{
$theme = $theme ?? AntConfig::currentConfig('activeTheme');
if (!is_dir(antThemePath . '/' . $theme)) {
$theme = 'Default';
}
$configPath = AntTools::repairFilePath(antThemePath . '/' . $theme . '/' . 'Config.yaml');
if (file_exists($configPath)) {
$config = AntYaml::parseFile($configPath);
}
return $config ?? [];
}
}

View File

@ -14,6 +14,7 @@ class AntConfig
'enableCache',
'debug',
'baseURL',
'embed',
];
/**
@ -31,6 +32,9 @@ class AntConfig
'enableCache' => true,
'debug' => true,
'baseURL' => $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']),
'embed' => [
'allowed_domains' => ['youtube.com', 'twitter.com', 'github.com', 'vimeo.com', 'flickr.com', 'instagram.com', 'facebook.com'],
]
];
Self::saveConfig($defaultOptions);

View File

@ -3,6 +3,8 @@
namespace AntCMS;
use AntCMS\AntCache;
use AntCMS\AntConfig;
use AntCMS\AntCMS;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\Autolink\AutolinkExtension;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
@ -15,6 +17,7 @@ use ElGigi\CommonMarkEmoji\EmojiExtension;
use League\CommonMark\Extension\Embed\Bridge\OscaroteroEmbedAdapter;
use League\CommonMark\Extension\Embed\EmbedExtension;
use SimonVomEyser\CommonMarkExtension\LazyImageExtension;
use League\CommonMark\Extension\DefaultAttributes\DefaultAttributesExtension;
class AntMarkdown
{
@ -25,6 +28,7 @@ class AntMarkdown
{
$antCache = new AntCache();
$cacheKey = $antCache->createCacheKey($md, 'markdown');
$config = AntConfig::currentConfig();
if ($antCache->isCached($cacheKey)) {
$cachedContent = $antCache->getCache($cacheKey);
@ -34,13 +38,23 @@ class AntMarkdown
}
}
$defaultAttributes = [];
$themeConfig = AntCMS::getThemeConfig();
foreach ($themeConfig['defaultAttributes'] as $class => $attributes) {
$reflectionClass = new \ReflectionClass($class);
$fqcn = $reflectionClass->getName();
$defaultAttributes[$fqcn] = $attributes;
}
$mdConfig = [
'embed' => [
'adapter' => new OscaroteroEmbedAdapter(),
'allowed_domains' => ['youtube.com', 'twitter.com', 'github.com', 'vimeo.com', 'flickr.com', 'instagram.com', 'facebook.com'],
'allowed_domains' => $config['embed']['allowed_domains'] ?? [],
'fallback' => 'link',
],
'default_attributes' => $defaultAttributes,
];
$environment = new Environment($mdConfig);
$environment->addExtension(new CommonMarkCoreExtension());
@ -52,6 +66,7 @@ class AntMarkdown
$environment->addExtension(new EmojiExtension());
$environment->addExtension(new EmbedExtension());
$environment->addExtension(new LazyImageExtension());
$environment->addExtension(new DefaultAttributesExtension());
$markdownConverter = new MarkdownConverter($environment);

View File

@ -108,9 +108,14 @@ class AdminPlugin extends AntPlugin
if (is_bool($subvalue)) {
$currentConfig[$key][$subkey] = ($subvalue) ? 'true' : 'false';
}
if (is_array($subvalue)) {
$currentConfig[$key][$subkey] = implode(', ', $subvalue);
}
}
} else if (is_bool($value)) {
$currentConfig[$key] = ($value) ? 'true' : 'false';
} else if (is_array($value)) {
$currentConfig[$key] = implode(', ', $value);
}
}

View File

@ -0,0 +1,14 @@
config:
showAuthor: false
defaultAttributes:
\League\CommonMark\Extension\Table\Table:
class: table table-hover
\League\CommonMark\Extension\CommonMark\Node\Inline\Image:
class: img-fluid
\League\CommonMark\Extension\CommonMark\Node\Block\BlockQuote:
class: blockquote
\League\CommonMark\Extension\CommonMark\Node\Block\ListBlock:
class:
\League\CommonMark\Extension\CommonMark\Node\Block\ListItem:
class:

View File

@ -8,11 +8,8 @@
<meta name="author" content="{{ AntCMSAuthor }}">
<meta name="keywords" content="{{ AntCMSKeywords }}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-aFq/bzH65dt+w6FI2ooMVUpc+21e0SRygnTpmBvdBgSdnuTN7QbdgL+OapgHtvPp" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha2/dist/js/bootstrap.bundle.min.js" integrity="sha384-qKXV1j0HvMUeCBQ+QVp7JcfGl760yU08IQ+GpUo5hlbpg51QRiuqHAJz8+BrxE/N" crossorigin="anonymous"></script>
<title>{{ AntCMSTitle }}</title>
</head>
@ -39,7 +36,7 @@
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
{% if DisplayAuthor and false %}
{% if AntCMSAuthor is defined and ThemeConfig.showAuthor %}
<p>This content was written by {{ AntCMSAuthor }}</p>
{% endif %}
{{ AntCMSBody | raw }}