Manage books with epilogue — https://epilogue.micro.blog
This commit is contained in:
@@ -37,10 +37,7 @@ module Adamantium
|
||||
end
|
||||
|
||||
def search(term:)
|
||||
ref = dataset
|
||||
.full_text_search([:content], [term])
|
||||
.select(:id)
|
||||
where(id: ref)
|
||||
where(Sequel.ilike(:content, "%#{term}%"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user