Skip to content

Commit 8b4ed45

Browse files
authored
Merge pull request #265 from joyofrails/feat/enhance-search-index
Enhance search index
2 parents 6b4ba5a + ff0b7bb commit 8b4ed45

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Pages
2+
class SearchIndexRefreshJob < ApplicationJob
3+
def perform
4+
Page.refresh_search_index
5+
end
6+
end
7+
end

app/models/page.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def self.search(query)
3030
.where("pages_search_index MATCH ?", query)
3131
end
3232

33-
def self.rebuild_search_index
33+
def self.refresh_search_index
3434
find_each(&:update_in_search_index)
3535
end
3636

@@ -43,7 +43,15 @@ def body
4343
end
4444

4545
def body_html
46-
ApplicationController.render(inline: body, type: resource.handler, layout: false)
46+
ApplicationController.render(
47+
inline: body,
48+
type: (resource.handler.to_sym == :mdrb) ? :"mdrb-atom" : resource.handler,
49+
layout: false,
50+
content_type: "application/atom+xml",
51+
assigns: {
52+
format: :atom
53+
}
54+
)
4755
end
4856

4957
def body_text

app/views/components/markdown/application.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ def default_commonmarker_options
1212
}
1313
end
1414

15-
def code_block(source, language = "", **attributes)
15+
def code_block(source, metadata = "", **attributes)
16+
language, _ = metadata.split(":", 2)
1617
render CodeBlock::Code.new(source, language: language, **attributes)
1718
end
1819

1920
def image(src, alt: "", title: "")
21+
title, _ = title.split("|", 2)
2022
figure do
2123
image_tag(src, alt: alt, title: title)
2224
figcaption { title }

lib/tasks/deploy.rake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace :deploy do
2+
desc "Post deploy script"
3+
task finish: :environment do
4+
Pages::SearchIndexRefreshJob.perform_later
5+
end
6+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Pages::SearchIndexRefreshJob, type: :job do
4+
it "refreshes the search index" do
5+
allow(Page).to receive(:refresh_search_index)
6+
7+
described_class.perform_now
8+
9+
expect(Page).to have_received(:refresh_search_index)
10+
end
11+
end

spec/models/page_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
expect(page.resource).to eq Sitepress.site.get("/")
88
end
99

10-
describe ".rebuild_search_index" do
10+
describe ".refresh_search_index" do
1111
it "doesn’t blow up" do
1212
Page.find_or_create_by!(request_path: "/")
1313

14-
Page.rebuild_search_index
14+
Page.refresh_search_index
1515
end
1616
end
1717

@@ -25,7 +25,7 @@
2525
it "works after rebuilding index" do
2626
page = Page.find_or_create_by!(request_path: "/")
2727

28-
Page.rebuild_search_index
28+
Page.refresh_search_index
2929

3030
expect(Page.search("Joy of Rails")).to include page
3131
end

0 commit comments

Comments
 (0)