mirror of
https://github.com/danbee/micropub.git
synced 2025-03-04 08:59:13 +00:00
Photo posts
This commit is contained in:
parent
617bd2c101
commit
0827022bf0
0
lib/micropub/photo.rb
Normal file
0
lib/micropub/photo.rb
Normal file
28
lib/micropub/photo_post.rb
Normal file
28
lib/micropub/photo_post.rb
Normal file
@ -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}
|
||||
---
|
||||
|
||||
<figure class="photo photo--wide">
|
||||
{{< img src="#{photo}" alt="#{alt_text}" caption="#{caption}" >}}
|
||||
|
||||
<figcaption>#{caption}</figcaption>
|
||||
</figure>
|
||||
|
||||
#{content.strip}
|
||||
POST
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -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
|
||||
|
||||
|
||||
67
test/lib/micropub/photo_post_test.rb
Normal file
67
test/lib/micropub/photo_post_test.rb
Normal file
@ -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
|
||||
---
|
||||
|
||||
<figure class="photo photo--wide">
|
||||
{{< img src="photo.jpg" alt="" caption="" >}}
|
||||
|
||||
<figcaption></figcaption>
|
||||
</figure>
|
||||
|
||||
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
|
||||
---
|
||||
|
||||
<figure class="photo photo--wide">
|
||||
{{< img src="photo.jpg" alt="" caption="" >}}
|
||||
|
||||
<figcaption></figcaption>
|
||||
</figure>
|
||||
|
||||
Hallo, Earth!
|
||||
POST
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user