mirror of
https://github.com/danbee/micropub.git
synced 2025-03-04 08:59:13 +00:00
Add optional title to front matter
This commit is contained in:
parent
37fe32f291
commit
2d83f2eb0d
@ -1,4 +1,5 @@
|
|||||||
require "date"
|
require "date"
|
||||||
|
require "yaml"
|
||||||
require "kramdown"
|
require "kramdown"
|
||||||
|
|
||||||
module Micropub
|
module Micropub
|
||||||
@ -67,13 +68,18 @@ module Micropub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post_frontmatter
|
||||||
|
{
|
||||||
|
"title" => title,
|
||||||
|
"date" => published.rfc3339,
|
||||||
|
"layout" => "micropost",
|
||||||
|
"categories" => categories,
|
||||||
|
}.compact.to_yaml
|
||||||
|
end
|
||||||
|
|
||||||
def post_content
|
def post_content
|
||||||
<<~POST
|
<<~POST
|
||||||
---
|
#{post_frontmatter.strip}
|
||||||
date: '#{published.rfc3339}'
|
|
||||||
layout: micropost
|
|
||||||
categories:
|
|
||||||
#{categories.map { |category| "- #{category}\n" }.join.strip}
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#{content}
|
#{content}
|
||||||
|
|||||||
@ -205,5 +205,28 @@ describe Micropub::Post do
|
|||||||
Hallo, Earth!
|
Hallo, Earth!
|
||||||
POST
|
POST
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns a post formatted for hugo with a title" do
|
||||||
|
post = Micropub::Post.new(
|
||||||
|
"title" => "Welcome!",
|
||||||
|
"content" => "Hallo, Earth!",
|
||||||
|
"published" => "2019-11-12",
|
||||||
|
"category" => ["one", "two", "three"],
|
||||||
|
)
|
||||||
|
|
||||||
|
_(post.post_content).must_equal <<~POST
|
||||||
|
---
|
||||||
|
title: Welcome!
|
||||||
|
date: '2019-11-12T00:00:00+00:00'
|
||||||
|
layout: micropost
|
||||||
|
categories:
|
||||||
|
- one
|
||||||
|
- two
|
||||||
|
- three
|
||||||
|
---
|
||||||
|
|
||||||
|
Hallo, Earth!
|
||||||
|
POST
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user