Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ブログ記事の一覧にて、feature タグがついてるブログ記事はメンター・管理者にだけ目印が表示される。 #8186

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ArticlesController < ApplicationController
before_action :require_admin_or_mentor_login, except: %i[index show]

def index
@articles = sorted_articles.page(params[:page])
@articles = sorted_articles.preload([:tags]).page(params[:page])
@articles = @articles.tagged_with(params[:tag]) if params[:tag]
number_per_page = @articles.page(1).limit_value
@atom_articles = sorted_articles.limit(number_per_page)
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def meta_robots_tag
content = logged_in? ? 'none' : 'noindex, nofollow'
tag.meta(name: 'robots', content:)
end

def feature_tag?(article)
Copy link
Member

Choose a reason for hiding this comment

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

helperに独自のメソッドを追加した場合は対応するテストが1つはほしい感じです〜

article.tags.pluck(:name).include?('feature')
end
end
1 change: 1 addition & 0 deletions app/javascript/stylesheets/_common-imports.sass
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
@import "shared/blocks/card/congrats-card-body"
@import "shared/blocks/card/practice-books"
@import "shared/blocks/card/thumbnail-card"
@import "shared/blocks/card/tags-highlight"

@import "shared/blocks/card-list/card-list-item-actions"
@import "shared/blocks/card-list/card-list-item-meta"
Expand Down
6 changes: 6 additions & 0 deletions app/javascript/stylesheets/config/mixins/_badge.sass
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
margin-left: .1875em
&:not(:last-child)
margin-right: .1875em
&.is-block
width: 100%
display: flex
.a-badge__inner
overflow: hidden
text-overflow: ellipsis

=badge-color($color)
background-color: $color
Expand Down
15 changes: 15 additions & 0 deletions app/javascript/stylesheets/shared/blocks/card/_tags-highlight.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.tags-highlight
position: absolute
left: 0
top: 0
padding: .5rem .75rem
display: flex
gap: .25rem
width: 100%
flex-wrap: wrap

.tags-highlight__item
width: 25%
max-width: 6rem
.a-badge
border: solid 1px var(--base)
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
.thumbnail-card
padding: 1rem
+media-breakpoint-up(md)
height: 100%
+media-breakpoint-down(sm)
.col-xs-6 &
height: 100%

.thumbnail-card__inner
padding: 1rem
display: flex
flex-direction: column
gap: 1rem
position: relative

a.thumbnail-card__inner
+flex-link
Expand Down
6 changes: 6 additions & 0 deletions app/views/articles/_articles.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ hr.a-border-tint
.col-lg-4.col-md-6.col-xs-12
.thumbnail-card.a-card class=(article.wip? ? ' is-wip' : '')
= link_to article, class: 'thumbnail-card__inner' do
- if current_user&.admin_or_mentor_login? && feature_tag?(article)
.tags-highlight
.tags-highlight__item
.a-badge.is-sm.is-primary.is-block
.a-badge__inner
| 注目の記事
.thumbnail-card__row
- if article.prepared_thumbnail?
= image_tag article.prepared_thumbnail_url, class: 'thumbnail-card__image', alt: "ブログ記事「#{article.title}」のアイキャッチ画像"
Expand Down