Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Nov 25, 2024
1 parent 7c80f49 commit 253637e
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 114 deletions.
148 changes: 74 additions & 74 deletions config/default.php

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public function __construct(Builder $builder, string|array $paths, array|null $o
];

// handles options
$fingerprint = (bool) $this->config->get('assets.fingerprint.enabled', default: ['enabled' => true]);
$minify = (bool) $this->config->get('assets.minify.enabled', default: ['enabled' => true]);
$optimize = (bool) $this->config->get('assets.images.optimize.enabled', default: ['enabled' => false]);
$fingerprint = (bool) $this->config->get('assets.fingerprint.enabled');
$minify = (bool) $this->config->get('assets.minify.enabled');
$optimize = (bool) $this->config->get('assets.images.optimize.enabled');
$filename = '';
$ignore_missing = false;
$remote_fallback = null;
Expand Down Expand Up @@ -179,7 +179,7 @@ public function __construct(Builder $builder, string|array $paths, array|null $o
$this->fingerprint();
}
// compiling (Sass files)
if ((bool) $this->config->get('assets.compile.enabled', default: ['enabled' => true])) {
if ((bool) $this->config->get('assets.compile.enabled')) {
$this->compile();
}
// minifying (CSS and JavScript files)
Expand Down Expand Up @@ -259,7 +259,7 @@ public function compile(): self
$importDir = [];
$importDir[] = Util::joinPath($this->config->getStaticPath());
$importDir[] = Util::joinPath($this->config->getAssetsPath());
$scssDir = $this->config->get('assets.compile.import', default: []);
$scssDir = $this->config->get('assets.compile.import');
$themes = $this->config->getTheme() ?? [];
foreach ($scssDir as $dir) {
$importDir[] = Util::joinPath($this->config->getStaticPath(), $dir);
Expand All @@ -272,9 +272,9 @@ public function compile(): self
}
$scssPhp->setImportPaths(array_unique($importDir));
// source map
if ($this->builder->isDebug() && (bool) $this->config->get('assets.compile.sourcemap', default: false)) {
if ($this->builder->isDebug() && (bool) $this->config->get('assets.compile.sourcemap')) {
$importDir = [];
$assetDir = (string) $this->config->get('assets.dir', default: 'assets');
$assetDir = (string) $this->config->get('assets.dir');
$assetDirPos = strrpos($this->data['file'], DIRECTORY_SEPARATOR . $assetDir . DIRECTORY_SEPARATOR);
$fileRelPath = substr($this->data['file'], $assetDirPos + 8);
$filePath = Util::joinFile($this->config->getOutputPath(), $fileRelPath);
Expand All @@ -291,13 +291,13 @@ public function compile(): self
}
// output style
$outputStyles = ['expanded', 'compressed'];
$outputStyle = strtolower((string) $this->config->get('assets.compile.style', default: 'expanded'));
$outputStyle = strtolower((string) $this->config->get('assets.compile.style'));
if (!\in_array($outputStyle, $outputStyles)) {
throw new ConfigException(\sprintf('"%s" value must be "%s".', 'assets.compile.style', implode('" or "', $outputStyles)));
}
$scssPhp->setOutputStyle($outputStyle);
// variables
$variables = $this->config->get('assets.compile.variables', default: []);
$variables = $this->config->get('assets.compile.variables');
if (!empty($variables)) {
$variables = array_map('ScssPhp\ScssPhp\ValueConverter::parseValue', $variables);
$scssPhp->replaceVariables($variables);
Expand Down Expand Up @@ -325,7 +325,7 @@ public function compile(): self
public function minify(): self
{
// disable minify to preserve inline source map
if ($this->builder->isDebug() && (bool) $this->config->get('assets.compile.sourcemap', default: false)) {
if ($this->builder->isDebug() && (bool) $this->config->get('assets.compile.sourcemap')) {
return $this;
}

Expand Down Expand Up @@ -384,7 +384,7 @@ public function optimize(string $filepath): self
return $this;
}

$quality = $this->config->get('assets.images.quality', default: 75);
$quality = $this->config->get('assets.images.quality');
$cache = new Cache($this->builder, (string) $this->builder->getConfig()->get('cache.assets.dir'));
$tags = ["q$quality", 'optimized'];
if ($this->data['width']) {
Expand Down Expand Up @@ -438,14 +438,14 @@ public function resize(int $width): self
return $assetResized; // returns asset with the new width only: CDN do the rest of the job
}

$quality = $this->config->get('assets.images.quality', default: 75);
$quality = $this->config->get('assets.images.quality');
$cache = new Cache($this->builder, (string) $this->builder->getConfig()->get('cache.assets.dir'));
$cacheKey = $cache->createKeyFromAsset($assetResized, ["{$width}x", "q$quality"]);
if (!$cache->has($cacheKey)) {
$assetResized->data['content'] = Image::resize($assetResized, $width, $quality);

Check notice on line 445 in src/Assets/Asset.php

View check run for this annotation

Scrutinizer / Inspection

src/Assets/Asset.php#L445

It seems like ``$quality`` can also be of type ``null``; however, parameter ``$quality`` of ``Cecil\Assets\Image::resize()`` does only seem to accept ``integer``, maybe add an additional type check?
$assetResized->data['path'] = '/' . Util::joinPath(
(string) $this->config->get('assets.target', default: 'assets'),
(string) $this->config->get('assets.images.resize.dir', default: 'thumbnails'),
(string) $this->config->get('assets.target'),
(string) $this->config->get('assets.images.resize.dir'),
(string) $width,
$assetResized->data['path']
);
Expand All @@ -471,7 +471,7 @@ public function convert(string $format, ?int $quality = null): self
}

if ($quality === null) {
$quality = (int) $this->config->get('assets.images.quality', default: 75);
$quality = (int) $this->config->get('assets.images.quality');
}

$asset = clone $this;
Expand Down Expand Up @@ -605,7 +605,7 @@ public function getVideo(): array
public function dataurl(): string
{
if ($this->data['type'] == 'image' && !Image::isSVG($this)) {
return Image::getDataUrl($this, $this->config->get('assets.images.quality', default: 75));
return Image::getDataUrl($this, $this->config->get('assets.images.quality'));

Check notice on line 608 in src/Assets/Asset.php

View check run for this annotation

Scrutinizer / Inspection

src/Assets/Asset.php#L608

It seems like ``$this->config->get('assets.images.quality')`` can also be of type ``null``; however, parameter ``$quality`` of ``Cecil\Assets\Image::getDataUrl()`` does only seem to accept ``integer``, maybe add an additional type check?
}

return \sprintf('data:%s;base64,%s', $this->data['subtype'], base64_encode($this->data['content']));
Expand Down Expand Up @@ -642,11 +642,11 @@ public function save(): void
*/
public function isImageInCdn()
{
if ($this->data['type'] != 'image' || (bool) $this->config->get('assets.images.cdn.enabled', default: false) !== true || (Image::isSVG($this) && (bool) $this->config->get('assets.images.cdn.svg', default: false) !== true)) {
if ($this->data['type'] != 'image' || (bool) $this->config->get('assets.images.cdn.enabled') !== true || (Image::isSVG($this) && (bool) $this->config->get('assets.images.cdn.svg') !== true)) {
return false;
}
// remote image?
if ($this->data['url'] !== null && (bool) $this->config->get('assets.images.cdn.remote', default: true) !== true) {
if ($this->data['url'] !== null && (bool) $this->config->get('assets.images.cdn.remote') !== true) {
return false;
}

Expand Down Expand Up @@ -896,9 +896,9 @@ private function buildImageCdnUrl(): string
],
[
$this->config->get('assets.images.cdn.account'),
ltrim($this->data['url'] ?? (string) new Url($this->builder, $this->data['path'], ['canonical' => $this->config->get('assets.images.cdn.canonical', default: true)]), '/'),
ltrim($this->data['url'] ?? (string) new Url($this->builder, $this->data['path'], ['canonical' => $this->config->get('assets.images.cdn.canonical')]), '/'),
$this->data['width'],
$this->config->get('assets.images.quality', default: 75),
$this->config->get('assets.images.quality'),
$this->data['ext'],
],
(string) $this->config->get('assets.images.cdn.url')
Expand Down
2 changes: 1 addition & 1 deletion src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public static function getVersion(): string
protected function logConfigError(): void
{
// baseurl
if (empty(trim((string) $this->config->get('baseurl', default: ''), '/'))) {
if (empty(trim((string) $this->config->get('baseurl'), '/'))) {
$this->getLogger()->error('`baseurl` configuration key is required in production (e.g.: "baseurl: https://example.com/").');
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,15 @@ public function getOutputFormatProperty(string $name, string $property): string|
*/
public function getAssetsImagesWidths(): array
{
return $this->get('assets.images.responsive.widths', default: [480, 640, 768, 1024, 1366, 1600, 1920]);
return $this->get('assets.images.responsive.widths');
}

/**
* Returns asset image sizes.
*/
public function getAssetsImagesSizes(): array
{
return $this->get('assets.images.responsive.sizes', default: ['default' => '100vw']);
return $this->get('assets.images.responsive.sizes');
}

/*
Expand Down
16 changes: 8 additions & 8 deletions src/Converter/Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(Builder $builder, ?array $options = null)
$this->highlighter = new Highlighter();

// options
$options = array_merge(['selectors' => (array) $this->config->get('pages.body.toc', default: ['h2', 'h3'])], $options ?? []);
$options = array_merge(['selectors' => (array) $this->config->get('pages.body.toc')], $options ?? []);

parent::__construct();
parent::setOptions($options);
Expand Down Expand Up @@ -111,19 +111,19 @@ protected function inlineLink($Excerpt)

// External link
if (str_starts_with($link['element']['attributes']['href'], 'http') && !str_starts_with($link['element']['attributes']['href'], (string) $this->config->get('baseurl'))) {
if ($this->config->get('pages.body.links.external.blank', default: false)) {
if ($this->config->get('pages.body.links.external.blank')) {
$link['element']['attributes']['target'] = '_blank';
}
if (!\array_key_exists('rel', $link['element']['attributes'])) {
$link['element']['attributes']['rel'] = '';
}
if ($this->config->get('pages.body.links.external.noopener', default: true)) {
if ($this->config->get('pages.body.links.external.noopener')) {
$link['element']['attributes']['rel'] .= ' noopener';
}
if ($this->config->get('pages.body.links.external.noreferrer', default: true)) {
if ($this->config->get('pages.body.links.external.noreferrer')) {
$link['element']['attributes']['rel'] .= ' noreferrer';
}
if ($this->config->get('pages.body.links.external.nofollow', default: true)) {
if ($this->config->get('pages.body.links.external.nofollow')) {
$link['element']['attributes']['rel'] .= ' nofollow';
}
$link['element']['attributes']['rel'] = trim($link['element']['attributes']['rel']);
Expand All @@ -133,7 +133,7 @@ protected function inlineLink($Excerpt)
* Embed link?
*/
$embed = false;
$embed = (bool) $this->config->get('pages.body.links.embed.enabled', default: false);
$embed = (bool) $this->config->get('pages.body.links.embed.enabled');
if (isset($link['element']['attributes']['embed'])) {
$embed = true;
if ($link['element']['attributes']['embed'] == 'false') {
Expand Down Expand Up @@ -268,7 +268,7 @@ protected function inlineImage($Excerpt)
}

// disable remote image handling?
if (Util\Url::isUrl($InlineImage['element']['attributes']['src']) && !(bool) $this->config->get('pages.body.images.remote.enabled', default: true)) {
if (Util\Url::isUrl($InlineImage['element']['attributes']['src']) && !(bool) $this->config->get('pages.body.images.remote.enabled')) {
return $InlineImage;
}

Expand Down Expand Up @@ -389,7 +389,7 @@ protected function inlineImage($Excerpt)

// converts image to formats and put them in picture > source
if (
\count($formats = ((array) $this->config->get('pages.body.images.formats', default: []))) > 0
\count($formats = ((array) $this->config->get('pages.body.images.formats'))) > 0
&& \in_array($InlineImage['element']['attributes']['src']['subtype'], ['image/jpeg', 'image/png', 'image/gif'])
) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function generate(): void
}
$path = $page->getPath();
// site pagination configuration
$paginationPerPage = \intval($this->config->get('pagination.max', default: 5));
$paginationPath = (string) $this->config->get('pagination.path', default: 'page');
$paginationPerPage = \intval($this->config->get('pagination.max'));
$paginationPath = (string) $this->config->get('pagination.path');
// page pagination configuration
$pagePagination = $page->getVariable('pagination');
if ($pagePagination) {
Expand Down
8 changes: 4 additions & 4 deletions src/Renderer/Extension/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public function scssToCss(?string $value): string
throw new ConfigException(\sprintf('"%s" value must be "%s".', 'assets.compile.style', implode('" or "', $outputStyles)));
}
$scssPhp->setOutputStyle($outputStyle);
$variables = $this->config->get('assets.compile.variables', default: []);
$variables = $this->config->get('assets.compile.variables');
if (!empty($variables)) {
$variables = array_map('ScssPhp\ScssPhp\ValueConverter::parseValue', $variables);
$scssPhp->replaceVariables($variables);
Expand All @@ -478,8 +478,8 @@ public function html(array $context, Asset $asset, array $attributes = [], array
{
$htmlAttributes = '';
$preload = false;
$responsive = (bool) $this->config->get('assets.images.responsive.enabled', default: false);
$formats = (array) $this->config->get('assets.images.formats', default: []);
$responsive = (bool) $this->config->get('assets.images.responsive.enabled');
$formats = (array) $this->config->get('assets.images.formats');
extract($options, EXTR_IF_EXISTS);

// builds HTML attributes
Expand Down Expand Up @@ -705,7 +705,7 @@ public function markdownToHtml(?string $markdown): ?string
public function markdownToToc(?string $markdown, $format = 'html', ?array $selectors = null, string $url = ''): ?string
{
$markdown = $markdown ?? '';
$selectors = $selectors ?? (array) $this->config->get('pages.body.toc', default: ['h2', 'h3']);
$selectors = $selectors ?? (array) $this->config->get('pages.body.toc');

try {
$parsedown = new Parsedown($this->builder, ['selectors' => $selectors, 'url' => $url]);
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function __construct(Builder $builder, $templatesPath)
switch ($name) {
case 'localizeddate':
return new \Twig\TwigFilter($name, function (?\DateTime $value = null) {
return date($this->builder->getConfig()->get('date.format', default: 'F j, Y'), $value->getTimestamp());
return date($this->builder->getConfig()->get('date.format'), $value->getTimestamp());

Check notice on line 119 in src/Renderer/Twig.php

View check run for this annotation

Scrutinizer / Inspection

src/Renderer/Twig.php#L119

It seems like ``$this->builder->getConfig()->get('date.format')`` can also be of type ``null``; however, parameter ``$format`` of ``date()`` does only seem to accept ``string``, maybe add an additional type check?
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Step/Optimize/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function init(array $options): void
*/
public function setProcessor(): void
{
$this->processor = Optimizer::create($this->config->get('assets.images.quality', default: 75));
$this->processor = Optimizer::create($this->config->get('assets.images.quality'));

Check notice on line 45 in src/Step/Optimize/Images.php

View check run for this annotation

Scrutinizer / Inspection

src/Step/Optimize/Images.php#L45

It seems like ``$this->config->get('assets.images.quality')`` can also be of type ``null``; however, parameter ``$quality`` of ``Cecil\Assets\Image\Optimizer::create()`` does only seem to accept ``integer``, maybe add an additional type check?
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Step/Pages/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function process(): void
*/
public function convertPage(Builder $builder, Page $page, ?string $format = null, ?ConverterInterface $converter = null): Page
{
$format = $format ?? (string) $builder->getConfig()->get('pages.frontmatter.format', default: 'yaml');
$format = $format ?? (string) $builder->getConfig()->get('pages.frontmatter.format');
$converter = $converter ?? new Converter($builder);

// converts front matter
Expand Down

0 comments on commit 253637e

Please sign in to comment.