Manage books with epilogue — https://epilogue.micro.blog

This commit is contained in:
2023-12-02 11:30:00 +11:00
parent 1edad91c2f
commit 734352d25e
4 changed files with 42 additions and 6 deletions

View File

@@ -50,7 +50,7 @@ module Micropub
elsif req.params[:q] == "source"
res.status = 200
res.content_type = "Application/JSON"
res.body = microformat_post.call(url: req.params[:url], properties: req.params[:properties]).to_json
res.body = microformat_post.call(url: req.params[:url], filter: req.params[:filter], properties: req.params[:properties]).to_json
else
res.redirect_to "/"
end

View File

@@ -6,7 +6,19 @@ module Micropub
class MicroformatPost
include Deps["repos.post_repo"]
def call(url:, properties:)
def call(url:, filter:, properties:)
if url
fetch_post(url: url, properties: properties)
end
if filter
search_posts(filter: filter)
end
end
private
def fetch_post(url:, properties:)
slug = URI(url).path.split("/").last
post = post_repo.fetch_unpublished!(slug)
@@ -31,6 +43,24 @@ module Micropub
result[:properties][:photos] = post.photos if properties.include? "photos"
result
end
def search_posts(filter:)
post_repo
.search(term: filter)
.map { |post|
content = ReverseMarkdown.convert(post.content, unknown_tags: :pass_through, github_flavored: true).to_s
{
type: ["h-entry"],
properties: {
published: [post.published_at],
content: [content],
photo: post.photos,
category: post.tags.map { |t| t.label.to_s }
}
}
}
end
end
end
end

View File

@@ -121,6 +121,15 @@ module Micropub
delete_post = posts.where(slug: slug).command(:update)
delete_post.call(published_at: Time.now)
end
def search(term:)
posts
.published
.search(term: term)
.combine(:tags)
.order(Sequel.desc(:published_at))
.to_a
end
end
end
end