Sha256: bfb0e3c54b6d9b9f9b875c9b036abf2d96044c393df333269eb034530368550d
Contents?: true
Size: 1.24 KB
Versions: 14
Compression:
Stored size: 1.24 KB
Contents
class Blog::BlogpostController < Blog::MainController LATEST_FOR_PREVIEW = 2 BLOGPOSTS_FOR_PREVIEW = 6 RELATED_FOR_PREVIEW = 3 def index # Fetch data as Json data = BlogpostParser.fetch_all .select { |b| b['published'] && !b['outdated'] } @authors = AuthorParser.fetch_all_authors categories = CategoryParser.fetch_all_categories # Build Blogposts by category @categories_with_blogposts = categories.map do |category| Blog::Category.new(category).build_n_blogposts_by_category(data, BLOGPOSTS_FOR_PREVIEW) end # Build latest Blogposts @latest_blogposts = data.first(LATEST_FOR_PREVIEW) .map { |attributes| Blog::Blogpost.new(attributes) } end def show data = BlogpostParser.fetch_all @blogpost = Blog::Blogpost.build_blogpost_from_path(params[:blog_path], 'en') @related_blogposts = data.select { |b| b['category']['slug'] == @blogpost.category.slug && b['title'] != @blogpost.title && b['published'] && !b['outdated'] } .first(RELATED_FOR_PREVIEW) .sort_by { |b| b['updated_at'] }.reverse .map { |attributes| Blog::Blogpost.new attributes } end end
Version data entries
14 entries across 14 versions & 1 rubygems