File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed
components_guide_web/lib/components_guide_web
components_guide/lib/components_guide/research Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,22 @@ defmodule ComponentsGuide.Research.Spec do
5
5
url = "https://cdn.jsdelivr.net/npm/[email protected] /data.json"
6
6
{ :ok , data } = Source . json_at ( url )
7
7
table = data [ "data" ]
8
+
8
9
if false do
9
10
keys = Map . keys ( table )
10
11
inspect ( keys )
11
12
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
13
24
end
14
25
end
15
26
@@ -32,7 +43,7 @@ defmodule ComponentsGuide.Research.Spec do
32
43
33
44
document
34
45
|> Floki . find ( "body" )
35
- |> Floki . find ( "a:fl-contains('form ')" )
46
+ |> Floki . find ( "a:fl-contains('#{ query } ')" )
36
47
|> Floki . raw_html ( )
37
48
38
49
# html
Original file line number Diff line number Diff line change @@ -25,16 +25,27 @@ defmodule ComponentsGuideWeb.ResearchController do
25
25
content_tag ( :h2 , text , class: "font-bold" )
26
26
end
27
27
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
+
28
39
defp load_results ( query ) when is_binary ( query ) do
29
40
# Spec.clear_search_cache()
30
41
[
31
42
content_tag ( :article , [
32
43
h2 ( "HTML spec" ) ,
33
- Spec . search_for ( :whatwg_html_spec , query )
44
+ Spec . search_for ( :whatwg_html_spec , query ) |> present_results ( )
34
45
] ) ,
35
46
content_tag ( :article , [
36
47
h2 ( "Can I Use" ) ,
37
- Spec . search_for ( :caniuse , query )
48
+ Spec . search_for ( :caniuse , query ) |> present_results ( )
38
49
] )
39
50
]
40
51
end
Original file line number Diff line number Diff line change 3
3
< h2 class = "mx-auto max-w-4xl text-5xl text-center font-bold leading-tight text-shadow " >
4
4
<%= "Research 🔍 specs and implementations" %>
5
5
</ 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 >
6
9
</ section >
7
10
</ header >
8
11
You can’t perform that action at this time.
0 commit comments