Search v1 (#19)

* Adds description to media items; hooks it up to indexing/media downloading

* Added a search method using postgres fulltext search

* Hooked up search functionality to the search form

* Added persistence to the search form when on search page
This commit is contained in:
Kieran
2024-02-13 17:46:14 -08:00
committed by GitHub
parent 850cf2db73
commit 58771ee37b
25 changed files with 261 additions and 25 deletions
@@ -0,0 +1,25 @@
defmodule PinchflatWeb.Searches.SearchHTML do
use PinchflatWeb, :html
embed_templates "search_html/*"
@doc """
Highlight search terms in a string of text based on `[PF_HIGHLIGHT]` and `[/PF_HIGHLIGHT]` tags
"""
attr :text, :string, required: true
def highlight_search_terms(assigns) do
split_string = String.split(assigns.text, ~r{\[PF_HIGHLIGHT\]|\[/PF_HIGHLIGHT\]}, include_captures: true)
assigns = assign(assigns, split_string: split_string)
~H"""
<%= for fragment <- @split_string do %>
<%= render_fragment(fragment) %>
<% end %>
"""
end
defp render_fragment("[PF_HIGHLIGHT]"), do: raw(~s(<span class="font-bold italic">))
defp render_fragment("[/PF_HIGHLIGHT]"), do: raw("</span>")
defp render_fragment(text), do: text
end