~arestifo/www

550179603fffd47c88fb9759bdc4e7ef9ecb8332 — Alberto Restifo 19 days ago b9a07dd
Tweak website
M src/actions/bread/recipes/show.cr => src/actions/bread/recipes/show.cr +1 -4
@@ 9,10 9,7 @@ class Bread::Recipes::Show < BrowserAction
      raise Lucky::RouteNotFoundError.new(context)
    end

    recipe = File.open(path) do |file|
      Recipe.from_markdown(file)
    end

    recipe = Recipe.from_markdown(path)
    html Bread::Recipes::ShowPage, recipe: recipe
  end
end

M src/components/shared/layout_head.cr => src/components/shared/layout_head.cr +2 -2
@@ 7,8 7,8 @@ class Shared::LayoutHead < BaseComponent
    head do
      utf8_charset
      title @page_title
      css_link asset("css/app.css"), data_turbolinks_track: "reload"
      js_link asset("js/app.js"), defer: "true", data_turbolinks_track: "reload"
      css_link asset("css/app.css")
      js_link asset("js/app.js"), defer: "true"
      csrf_meta_tags
      responsive_meta_tag


M src/js/app.js => src/js/app.js +0 -7
@@ 1,10 1,3 @@
import ujs from "@rails/ujs";
import turbolinks from "turbolinks";

ujs.start();
turbolinks.start();

// // Actions to be taken to very page view
// document.addEventListener("turbolinks:load", function() {
//   //
// });

M src/models/recipe.cr => src/models/recipe.cr +7 -5
@@ 5,10 5,9 @@ class Recipe
  getter ingredients : Array(Recipe::Ingredient)
  getter description : String
  getter gallery : Array(Recipe::Image)
  getter last_modified : Time

  # TODO: Add the last modified date, useful for the feed

  def self.from_markdown(file : IO) : Recipe
  def self.from_markdown(file : IO, last_modified : Time) : Recipe
    ::FrontMatter.parse(file) do |front_matter, content|
      metadata = Recipe::FrontMatter.from_yaml(front_matter)
      description = Markd.to_html(content.gets_to_end)


@@ 28,16 27,19 @@ class Recipe
        description: description,
        cover_image: metadata.cover_image,
        gallery: gallery,
        last_modified: last_modified,
      )
    end
  end

  def self.from_markdown(path : String) : Recipe
    info = File.info(path)

    File.open(path) do |file|
      self.from_markdown(file)
      self.from_markdown(file, info.modification_time)
    end
  end

  def initialize(@name, @title, @ingredients, @description, @cover_image, @gallery)
  def initialize(@name, @title, @ingredients, @description, @cover_image, @gallery, @last_modified)
  end
end

M src/models/recipe/front_matter.cr => src/models/recipe/front_matter.cr +6 -6
@@ 1,10 1,10 @@
# The front-matter included in the recipe
# markdown document.
class Recipe::FrontMatter
  YAML.mapping(
    title: String,
    cover_image: String?,
    ingredients: Array(Recipe::Ingredient),
    gallery: Array(Recipe::Image)?
  )
  include YAML::Serializable

  getter title : String
  getter cover_image : String?
  getter ingredients : Array(Recipe::Ingredient)
  getter gallery : Array(Recipe::Image)?
end

M src/models/recipe/image.cr => src/models/recipe/image.cr +4 -4
@@ 1,7 1,7 @@
# Gallery of images for the bread
class Recipe::Image
  YAML.mapping(
    path: String,
    description: String,
  )
  include YAML::Serializable

  getter path : String
  getter description : String
end

M src/models/recipe/ingredient.cr => src/models/recipe/ingredient.cr +5 -5
@@ 1,7 1,7 @@
class Recipe::Ingredient
  YAML.mapping(
    name: String,
    quantity: Int32,
    comment: String?,
  )
  include YAML::Serializable

  getter name : String
  getter quantity : Int32
  getter comment : String?
end

M src/pages/bread/index_page.cr => src/pages/bread/index_page.cr +3 -0
@@ 8,6 8,9 @@ class Bread::IndexPage < MainLayout
  def content
    h1 "Bread recipes"

    para "None of those recipies are my original creation, I simply tweaked them
          to my liking."

    ul do
      @recipes.each do |recipe|
        li do

M src/serializers/feed/bread_serializer.cr => src/serializers/feed/bread_serializer.cr +8 -1
@@ 1,5 1,8 @@
class Feed::BreadSerializer < FeedSerializer
  def initialize(@recipes : Array(Recipe))
  @recipes : Array(Recipe)

  def initialize(recipes : Array(Recipe))
    @recipes = recipes.sort_by(&.last_modified).reverse
  end

  def title : String


@@ 14,6 17,10 @@ class Feed::BreadSerializer < FeedSerializer
    Bread::Index.route.url
  end

  def last_modified : Time
    @recipes[0].last_modified
  end

  def items(xml : XML::Builder)
    @recipes.each do |recipe|
      xml.element("item") do

M src/serializers/feed_serializer.cr => src/serializers/feed_serializer.cr +6 -0
@@ 3,6 3,7 @@ abstract class FeedSerializer
  abstract def description : String
  abstract def link : String
  abstract def items(xml : XML::Builder)
  abstract def last_modified : Time

  def render : String
    XML.build(version: "1.0") do |xml|


@@ 11,6 12,11 @@ abstract class FeedSerializer
          xml.element("title") { xml.text title }
          xml.element("description") { xml.text description }
          xml.element("link") { xml.text link }
          xml.element("author") do
            xml.element("name") { xml.text "Alberto Restifo" }
            xml.element("email") { xml.text "alberto@restifo.dev" }
          end
          xml.element("updated") { xml.text Time::Format::RFC_3339.format(last_modified) }
          xml.element(
            prefix: "atom",
            name: "link",