Skip to content

Commit e0553c3

Browse files
committed
Present slightly nicer
1 parent a9fa0d5 commit e0553c3

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

apps/components_guide/lib/components_guide/research/spec.ex

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@ defmodule ComponentsGuide.Research.Spec do
55
url = "https://cdn.jsdelivr.net/npm/[email protected]/data.json"
66
{:ok, data} = Source.json_at(url)
77
table = data["data"]
8+
89
if false do
910
keys = Map.keys(table)
1011
inspect(keys)
1112
else
12-
table["documenthead"] |> inspect()
13+
matching_keywords =
14+
table
15+
|> Enum.flat_map(fn {key, value} ->
16+
case value["keywords"] |> String.contains?(query) do
17+
true -> [value["description"]]
18+
false -> []
19+
end
20+
end)
21+
22+
# table["documenthead"] |> inspect()
23+
matching_keywords
1324
end
1425
end
1526

@@ -32,7 +43,7 @@ defmodule ComponentsGuide.Research.Spec do
3243

3344
document
3445
|> Floki.find("body")
35-
|> Floki.find("a:fl-contains('form')")
46+
|> Floki.find("a:fl-contains('#{query}')")
3647
|> Floki.raw_html()
3748

3849
# html

apps/components_guide_web/lib/components_guide_web/controllers/research_controller.ex

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,27 @@ defmodule ComponentsGuideWeb.ResearchController do
2525
content_tag(:h2, text, class: "font-bold")
2626
end
2727

28+
defp present_results(results) when is_binary(results) do
29+
results
30+
end
31+
32+
defp present_results(results) when is_list(results) do
33+
items = results
34+
|> Enum.map(fn result -> content_tag(:li, result) end)
35+
36+
content_tag(:ul, items)
37+
end
38+
2839
defp load_results(query) when is_binary(query) do
2940
# Spec.clear_search_cache()
3041
[
3142
content_tag(:article, [
3243
h2("HTML spec"),
33-
Spec.search_for(:whatwg_html_spec, query)
44+
Spec.search_for(:whatwg_html_spec, query) |> present_results()
3445
]),
3546
content_tag(:article, [
3647
h2("Can I Use"),
37-
Spec.search_for(:caniuse, query)
48+
Spec.search_for(:caniuse, query) |> present_results()
3849
])
3950
]
4051
end

apps/components_guide_web/lib/components_guide_web/templates/research/index.html.eex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<h2 class="mx-auto max-w-4xl text-5xl text-center font-bold leading-tight text-shadow">
44
<%= "Research 🔍 specs and implementations" %>
55
</h2>
6+
<form role=search action="/research" class="flex h-full pt-8 px-2 items-center">
7+
<input type=text name=q placeholder="Search" class="w-full py-1 px-2 bg-white text-black text-xl" value="<%= @query %>">
8+
</form>
69
</section>
710
</header>
811

0 commit comments

Comments
 (0)