Skip to content

Instantly share code, notes, and snippets.

@CMessinides
Last active July 21, 2019 20:47
Show Gist options
  • Save CMessinides/4c0222d759bdf83699d1b7b8b433d437 to your computer and use it in GitHub Desktop.
Save CMessinides/4c0222d759bdf83699d1b7b8b433d437 to your computer and use it in GitHub Desktop.
Article list view for www.thecollegianmagazine.com
- site_title = site_info && site_info['site_info.site_title'] && site_info['site_info.site_title'].as_text || 'The Collegian Magazine'
- articles.sort_by! do |doc|
- [ (doc['article.date'] && doc['article.date'].value || doc.first_published_date),
- (doc['article.weight'] && doc['article.weight'].value || 10),
- (doc['article.title'] && doc['article.title'].as_text || doc.uid) ]
- articles.reverse!
- feat_article = articles.find { |article| !!article['article.featured_image'] }
- if feat_article
- content_for :meta_image do
- feat_article['article.featured_image'].views['small'].url
- articles_by_category = documents.select { |doc| doc.type == 'article' }.group_by { |doc| doc['article.category'] && doc['article.category'].uid }
- categories = articles_by_category.keys.compact.sort.sort { |a,b| articles_by_category[b].length <=> articles_by_category[a].length }.map { |cat_uid| documents.find { |doc| doc.type == 'category' && doc.uid == cat_uid }}
- category_doc = defined?(category) && categories.find { |cat| cat.uid == category }
- category_name = category_doc && category_doc['category.name'] && category_doc['category.name'].as_text || defined?(category) && category.humanize.titleize
- category_description = category_doc && category_doc['category.description'] && category_doc['category.description'].as_text
- content_for :meta_title do
- category_name || 'All Articles'
- content_for :social_title do
- category_name ? "#{post_process_html(category_name)} — #{site_title}" : "All Articles — #{site_title}"
- if category_description
- content_for :meta_description do
- category_description
%header.Hero.u-taCenter
.Page-container
%h1.Hero-heading= category_name ? post_process_html(category_name) : 'All Articles'
- if category_description
%p.Hero-subheading= category_description
%main
- if articles.length >= 3 && feat_article
.u-pt20px.u-pb48px.md-u-pt32px.lg-u-pt48px.u-bdr0.u-bdrcGreyWash.u-bdrstSolid.u-bdrwBottom1px
%section.Page-container
%h2.u-forSR Featured Article
= partial "partials/articles/story", locals: { article: feat_article, modifiers: [:wide] }
.Page-container.Page-container--split
%section.Page-column
%h2.Page-subheading The Latest
%ul.Stories
- articles.each_with_index do |article, index|
- if articles.length < 3 || article != feat_article
- mods = index == 0 ? [:big] : []
%li.Stories-item
= partial "partials/articles/story", locals: { :article => article, :modifiers => mods }
%aside.Page-sidebar
%h2.Page-subheading Browse by Category
%ul.SidebarList.SidebarList--categories
- categories.each do |_category|
- _category_name = _category['category.name'] && _category['category.name'].as_text || _category.uid.humanize.titleize
- is_current_category = defined?(category) && category == _category.uid
%li{ :class => "SidebarList-item#{ ' SidebarList-item--current' if is_current_category }" }
- if is_current_category
%span.u-forSR Articles in
= _category_name
- else
%a.SidebarList-link{ :href => abs_url("/categories/#{_category.uid.parameterize}") }
%span.u-forSR Articles in
= _category_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment