|
1 | | -<!-- app/views/pages/search.html.erb --> |
2 | | - |
3 | | -<div class="container mt-4"> |
4 | | - <!-- Search Results --> |
| 1 | +<div class="container mt-5"> |
5 | 2 | <% if @query.present? %> |
6 | | - <h2>Search Results for "<%= @query %>"</h2> |
| 3 | + <h2 class="mb-4">Search Results for "<%= @query %>"</h2> |
7 | 4 |
|
8 | 5 | <% if @results.any? %> |
9 | | - <table class="table table-striped mt-3"> |
10 | | - <thead> |
11 | | - <tr> |
12 | | - <th>Title</th> |
13 | | - <th>Content</th> |
14 | | - </tr> |
15 | | - </thead> |
16 | | - <tbody> |
17 | | - <% @results.each do |result| %> |
18 | | - <tr> |
19 | | - <td><%= link_to result.title, render_page_path(result.slug) %></td> |
20 | | - <td><%= truncate(strip_tags(result.content.to_s), length: 100) %></td> |
21 | | - </tr> |
22 | | - <% end %> |
23 | | - </tbody> |
24 | | - </table> |
| 6 | + <div class="row"> |
| 7 | + <% @results.each_with_index do |result, index| %> |
| 8 | + <% highlight = @highlights[index]['highlight'] || {} %> |
| 9 | + <div class="col-md-6 mb-4"> |
| 10 | + <div class="card shadow-sm"> |
| 11 | + <div class="card-body"> |
| 12 | + <h5 class="card-title"> |
| 13 | + <%= link_to result.title, render_page_path(result.slug), class: "text-decoration-none" %> |
| 14 | + </h5> |
| 15 | + |
| 16 | + <p class="card-text"> |
| 17 | + <% if highlight['title'] %> |
| 18 | + <%= highlight['title'].first.html_safe %> |
| 19 | + <% elsif highlight['content'] %> |
| 20 | + <%= highlight['content'].first.html_safe %> |
| 21 | + <% elsif highlight['blocks.rich_text_content.body'] %> |
| 22 | + <%= highlight['blocks.rich_text_content.body'].first.html_safe %> |
| 23 | + <% else %> |
| 24 | + <%= truncate(strip_tags(result.content.to_s), length: 150) %> |
| 25 | + <% end %> |
| 26 | + </p> |
| 27 | + |
| 28 | + <a href="<%= render_page_path(result.slug) %>" class="btn btn-primary mt-2">View More</a> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + </div> |
| 32 | + <% end %> |
| 33 | + </div> |
| 34 | + <%= paginate @results %> |
25 | 35 | <% else %> |
26 | | - <p>No results found for "<%= @query %>". Please try another search term.</p> |
| 36 | + <div class="alert alert-warning mt-4"> |
| 37 | + <p>No results found for "<%= @query %>". Please try another search term.</p> |
| 38 | + </div> |
27 | 39 | <% end %> |
28 | 40 | <% end %> |
29 | 41 | </div> |
0 commit comments