Refactor micropub specific things out to a slice

This commit is contained in:
2023-11-15 18:55:57 +11:00
parent 730ecb9ea4
commit 5b133363b3
63 changed files with 468 additions and 174 deletions

View File

@@ -0,0 +1,37 @@
require "reverse_markdown"
module Micropub
module Queries
module Posts
class MicroformatPost
include Deps["repos.post_repo"]
def call(url:, properties:)
slug = URI(url).path.split("/").last
post = post_repo.fetch_unpublished!(slug)
markdown_content = ReverseMarkdown.convert(post.content, unknown_tags: :pass_through, github_flavored: true).to_s
if properties.nil? || properties.empty?
return {
type: ["h-entry"],
properties: {
published: [post.published_at],
content: [markdown_content],
photo: post.photos,
category: post.tags.map { |t| t.label.to_s }
}
}
end
result = {properties: {}}
result[:properties][:published] = [post.published_at] if properties.include? "published"
result[:properties][:content] = [markdown_content] if properties.include? "content"
result[:properties][:category] = post.tags.map { |t| t.label.to_s } if properties.include? "category"
result[:properties][:photos] = post.photos if properties.include? "photos"
result
end
end
end
end
end