diff --git a/lib/micropub/photo.rb b/lib/micropub/photo.rb new file mode 100644 index 0000000..e69de29 diff --git a/lib/micropub/photo_post.rb b/lib/micropub/photo_post.rb new file mode 100644 index 0000000..8d66e88 --- /dev/null +++ b/lib/micropub/photo_post.rb @@ -0,0 +1,28 @@ +module Micropub + class PhotoPost < Post + BASE_PATH="/photos" + + def alt_text + params["alt_text"] + end + + def caption + params["caption"] + end + + def post_content + <<~POST + #{post_frontmatter.strip} + --- + +
+ {{< img src="#{photo}" alt="#{alt_text}" caption="#{caption}" >}} + +
#{caption}
+
+ + #{content.strip} + POST + end + end +end diff --git a/lib/micropub/post.rb b/lib/micropub/post.rb index 742f2f7..c8630f8 100644 --- a/lib/micropub/post.rb +++ b/lib/micropub/post.rb @@ -4,10 +4,10 @@ require "kramdown" module Micropub class Post - attr_accessor :params - BASE_PATH="/blog" + attr_accessor :params + def initialize(params = {}) @params = params end @@ -80,8 +80,9 @@ module Micropub { "title" => title, "date" => published.rfc3339, - "layout" => "micropost", + "layout" => title.nil? || title.empty? ? "micropost" : "post", "categories" => categories, + "image" => photo, }.compact.to_yaml end diff --git a/test/lib/micropub/photo_post_test.rb b/test/lib/micropub/photo_post_test.rb new file mode 100644 index 0000000..2528813 --- /dev/null +++ b/test/lib/micropub/photo_post_test.rb @@ -0,0 +1,67 @@ +require "test_helper" + +require "micropub/photo_post" + +describe Micropub::PhotoPost do + describe "#post_content" do + it "returns a post formatted for hugo" do + post = Micropub::PhotoPost.new( + "content" => "Hallo, Earth!", + "published" => "2019-11-12", + "category" => ["one", "two", "three"], + "photo" => "photo.jpg", + ) + + _(post.post_content).must_equal <<~POST + --- + date: '2019-11-12T00:00:00+00:00' + layout: micropost + categories: + - one + - two + - three + image: photo.jpg + --- + +
+ {{< img src="photo.jpg" alt="" caption="" >}} + +
+
+ + Hallo, Earth! + POST + end + + it "returns a post formatted for hugo with a title" do + post = Micropub::PhotoPost.new( + "name" => "Welcome!", + "content" => "Hallo, Earth!", + "published" => "2019-11-12", + "category" => ["one", "two", "three"], + "photo" => "photo.jpg", + ) + + _(post.post_content).must_equal <<~POST + --- + title: Welcome! + date: '2019-11-12T00:00:00+00:00' + layout: post + categories: + - one + - two + - three + image: photo.jpg + --- + +
+ {{< img src="photo.jpg" alt="" caption="" >}} + +
+
+ + Hallo, Earth! + POST + end + end +end diff --git a/test/lib/micropub/post_test.rb b/test/lib/micropub/post_test.rb index f610981..ff4ff5f 100644 --- a/test/lib/micropub/post_test.rb +++ b/test/lib/micropub/post_test.rb @@ -230,7 +230,7 @@ describe Micropub::Post do --- title: Welcome! date: '2019-11-12T00:00:00+00:00' - layout: micropost + layout: post categories: - one - two