diff --git a/app/helpers/portal_helper.rb b/app/helpers/portal_helper.rb index 8bc234415..ef16e9797 100644 --- a/app/helpers/portal_helper.rb +++ b/app/helpers/portal_helper.rb @@ -61,4 +61,9 @@ module PortalHelper def render_category_content(content) ChatwootMarkdownRenderer.new(content).render_markdown_to_plain_text end + + def thumbnail_bg_color(username) + colors = ['#6D95BA', '#A4C3C3', '#E19191'] + colors[username.length % colors.size] + end end diff --git a/app/views/icons/_user.html.erb b/app/views/icons/_user.html.erb new file mode 100644 index 000000000..885c26fc9 --- /dev/null +++ b/app/views/icons/_user.html.erb @@ -0,0 +1 @@ + diff --git a/app/views/public/api/v1/portals/_authors.html.erb b/app/views/public/api/v1/portals/_authors.html.erb new file mode 100644 index 000000000..86a0dae89 --- /dev/null +++ b/app/views/public/api/v1/portals/_authors.html.erb @@ -0,0 +1,24 @@ +<% author_count = category.articles.published.order(position: :asc).map(&:author).uniq.size %> +<% if author_count > 0 %> +
+
+ <% category.articles.published.order(position: :asc).map(&:author).uniq.take(3).each do |author| %> + <%= render "public/api/v1/portals/thumbnail", author: author, size: 5 %> + <% end %> +
+ + <% first_author = category.articles.published.order(position: :asc).map(&:author).uniq.first.name %> + <% author_text = author_count > 1 ? "#{author_count} #{I18n.t('public_portal.common.authors')}" : "#{author_count} #{I18n.t('public_portal.common.author')}" %> + <% other_authors_count = author_count - 1 %> + <% other_authors_text = other_authors_count > 1 ? I18n.t('public_portal.common.others') : I18n.t('public_portal.common.other') %> + + + <% if show_expanded %> + <%= "#{I18n.t('public_portal.common.by')} #{first_author}" %> + <%= other_authors_count.positive? ? " and #{other_authors_count} #{other_authors_text}" : '' %> + <% else %> + <%= author_text %> + <% end %> + +
+<% end %> diff --git a/app/views/public/api/v1/portals/_category-block.html.erb b/app/views/public/api/v1/portals/_category-block.html.erb index c28cd73ce..069aa9d9c 100644 --- a/app/views/public/api/v1/portals/_category-block.html.erb +++ b/app/views/public/api/v1/portals/_category-block.html.erb @@ -34,7 +34,7 @@ <% else %> <% category.articles.published.order(position: :asc).take(5).each do |article| %> -
+
<%= article.title %> <%= render partial: 'icons/chevron-right' %> @@ -45,7 +45,9 @@ <% end %>
-
+
+ <%= render "public/api/v1/portals/authors", category: category, show_expanded: false %> + <%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.order(position: :asc).size %>
diff --git a/app/views/public/api/v1/portals/_featured_articles.html.erb b/app/views/public/api/v1/portals/_featured_articles.html.erb index 321e0dd99..19e5e87dd 100644 --- a/app/views/public/api/v1/portals/_featured_articles.html.erb +++ b/app/views/public/api/v1/portals/_featured_articles.html.erb @@ -14,7 +14,7 @@
<% featured_articles.each do |article| %> -
+
<%= article.title %> <%= render partial: 'icons/chevron-right' %> diff --git a/app/views/public/api/v1/portals/_thumbnail.html.erb b/app/views/public/api/v1/portals/_thumbnail.html.erb new file mode 100644 index 000000000..d3d6520c2 --- /dev/null +++ b/app/views/public/api/v1/portals/_thumbnail.html.erb @@ -0,0 +1,7 @@ +<% if author&.avatar_url&.present? %> + <%= author.name %> +<% else %> +
+ <%= render partial: 'icons/user' %> +
+<% end %> diff --git a/app/views/public/api/v1/portals/articles/_article_header.html.erb b/app/views/public/api/v1/portals/articles/_article_header.html.erb index 582eb2aba..f70d24519 100644 --- a/app/views/public/api/v1/portals/articles/_article_header.html.erb +++ b/app/views/public/api/v1/portals/articles/_article_header.html.erb @@ -30,11 +30,9 @@
- <% if article.author&.avatar_url&.present? %> -
- <%= article.author.display_name %> -
- <% end %> +
+ <%= render "public/api/v1/portals/thumbnail", author: article.author, size: 5 %> +
By <%= article.author.available_name %> • <%= I18n.t('public_portal.common.last_updated_on', last_updated_on: article.updated_at.strftime("%b %d, %Y")) %>
diff --git a/app/views/public/api/v1/portals/categories/_category-hero.html.erb b/app/views/public/api/v1/portals/categories/_category-hero.html.erb index 61bbe34c4..c0b87d82c 100644 --- a/app/views/public/api/v1/portals/categories/_category-hero.html.erb +++ b/app/views/public/api/v1/portals/categories/_category-hero.html.erb @@ -21,6 +21,10 @@ <%= category.description %> <% end %>
- <%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %> +
+ <%= render "public/api/v1/portals/authors", category: category, show_expanded: true %> + + <%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %> +
diff --git a/app/views/public/api/v1/portals/categories/show.html.erb b/app/views/public/api/v1/portals/categories/show.html.erb index 251da1a1c..3e6398c0b 100644 --- a/app/views/public/api/v1/portals/categories/show.html.erb +++ b/app/views/public/api/v1/portals/categories/show.html.erb @@ -29,10 +29,18 @@ >
-

<%= article.title %>

-

<%= render_category_content(article.content) %>

+

<%= article.title %>

+

<%= render_category_content(article.content) %>

+
+
+
+ <% author = article.author %> + <%= render "public/api/v1/portals/thumbnail", author: author, size: 5 %> + <%= "#{I18n.t('public_portal.common.by')} #{author.name}" %> +
+ + <%= I18n.t('public_portal.common.last_updated_on', last_updated_on: article.updated_at.strftime("%b %d, %Y")) %>
- <%= I18n.t('public_portal.common.last_updated_on', last_updated_on: article.updated_at.strftime("%b %d, %Y")) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 14175b263..e6629ae8d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -215,6 +215,11 @@ en: view_all_articles: View all article: article articles: articles + author: author + authors: authors + other: other + others: others + by: By no_articles: There are no articles here footer: made_with: Made with diff --git a/spec/helpers/portal_helper_spec.rb b/spec/helpers/portal_helper_spec.rb index 36a9acb61..8ae93fae1 100644 --- a/spec/helpers/portal_helper_spec.rb +++ b/spec/helpers/portal_helper_spec.rb @@ -246,4 +246,16 @@ describe PortalHelper do expect(helper.render_category_content(markdown_content)).to eq(plain_text_content) end end + + describe '#thumbnail_bg_color' do + it 'returns the correct color based on username length' do + expect(helper.thumbnail_bg_color('')).to eq('#6D95BA') # Length 0, so index is 0 + expect(helper.thumbnail_bg_color('Joe')).to eq('#6D95BA') # Length 3, so index is 0 + expect(helper.thumbnail_bg_color('John')).to eq('#A4C3C3') # Length 4, so index is 1 + expect(helper.thumbnail_bg_color('Jane james')).to eq('#A4C3C3') # Length 10, so index is 1 + expect(helper.thumbnail_bg_color('Jane_123')).to eq('#E19191') # Length 8, so index is 2 + expect(helper.thumbnail_bg_color('AlexanderTheGreat')).to eq('#E19191') # Length 17, so index is 2 + expect(helper.thumbnail_bg_color('Reginald John Sans')).to eq('#6D95BA') # Length 18, so index is 0 + end + end end