Skip to content

Commit

Permalink
Fix covers (#678)
Browse files Browse the repository at this point in the history
* fix covers

* Update Image.php

* Update Image.php

* force use cover from article

* Build frontend

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
talyguryn and github-actions[bot] authored Jan 15, 2023
1 parent b056a5c commit a80d369
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
37 changes: 22 additions & 15 deletions www/application/classes/Controller/Cover/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,39 @@ private function article($articleId)

$image = null;

/**
* Try to get url of the first image from the article
/**
* Get cover image from the article
*/
try {
$editor = new EditorJS($article->text, Model_Article::getEditorConfig());
$blocks = $editor->getBlocks();

foreach ($blocks as $block) {
if ($block['type'] === 'image') {
$image_url = $block['data']['file']['url'];
$image = substr($image_url, 0, 4) !== 'http' ? sprintf('%s%s', DOCROOT, $image_url) : $image_url;
break;
if ($article->cover) {
$image = substr($article->cover, 0, 4) !== 'http' ? sprintf('%s%s', DOCROOT, $article->cover) : $article->cover;
} else {
/**
* Try to get url of the first image from the article
*/
try {
$editor = new EditorJS($article->text, Model_Article::getEditorConfig());
$blocks = $editor->getBlocks();

foreach ($blocks as $block) {
if ($block['type'] === 'image') {
$image_url = $block['data']['file']['url'];
$image = substr($image_url, 0, 4) !== 'http' ? sprintf('%s%s', DOCROOT, $image_url) : $image_url;
break;
}
}
} catch (\Exception $e) {
\Hawk\Catcher::get()->sendException($e);
}
} catch (\Exception $e) {
\Hawk\Catcher::get()->sendException($e);
}

/**
* Check if passed image exists
*/
$image_exists = $image !== null && file_exists($image);
$image_exists = $image !== null;
$cover = $this->background($image_exists ? $image : null);

/**
* Use black font if background image exists
* Use white font if background image exists
*/
if ($image_exists) {
$font_color = '#FFFFFF';
Expand Down
2 changes: 1 addition & 1 deletion www/public/build/release.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"release":"d0306d9565948f8ad52d","date":1673569245967}
{"release":"d0306d9565948f8ad52d","date":1673813069113}

0 comments on commit a80d369

Please sign in to comment.