Skip to content

Commit

Permalink
Хот-фикс: чинит картинки на главной
Browse files Browse the repository at this point in the history
  • Loading branch information
igsekor committed Aug 28, 2024
1 parent 682fa2a commit 4f92d3d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/includes/blocks/featured-article.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% macro featuredArticle(article, class, isLazyLoading=false) %}
{% set hasImage = article.cover %}

<article class="featured-article {{ class if class }}" style="--accent-color: var(--color-{{ article.section }})">
{% if hasImage %}
{% if article.imageLink %}
<picture class="featured-article__image-wrapper">
<img
class="featured-article__image"
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/modules/transform-article-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function transformArticleData(article) {
title: article.data.title,
cover: article.data.cover ?? {},
get imageLink() {
return `${this.cover.mobile}`
return Object.keys(this.cover).includes('mobile') ? `${this.cover.mobile}` : undefined
},
description: article.data.description,
link: `/${section}/${article.fileSlug}/`,
Expand Down

3 comments on commit 4f92d3d

@vitya-ne
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igsekor, тут можно короче:

get imageLink() {
  return this.cover?.mobile
},

вот тесты:

function imageLink() {
  return this.cover?.mobile
}

console.log(imageLink.call({ cover: { mobile: 'image' } })); // image
console.log(imageLink.call({ cover: {} })); // undefined
console.log(imageLink.call({ cover: [] })); // undefined
console.log(imageLink.call({ cover: 'str' })); // undefined
console.log(imageLink.call({ cover: 42 })); // undefined
console.log(imageLink.call({ cover: true })); // undefined
console.log(imageLink.call({})); // undefined
console.log(imageLink.call([])); // undefined
console.log(imageLink.call('str2')); // undefined
console.log(':', imageLink.call(null)); // undefined

@vitya-ne
Copy link
Contributor

@vitya-ne vitya-ne commented on 4f92d3d Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а если нужна точно строка, то так:

function imageLink() {
  return this.cover?.mobile?.toString()
}

смотрится конечно не очень.. )

@igsekor
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо! Валидно, сделаешь пиар? Это точно строка и так, поэтому вариант this.cover?.mobile вполне подойдёт :)

Please sign in to comment.