Skip to content

Commit 49b0f5e

Browse files
committed
Make caniuse spec match more results
1 parent 1349b46 commit 49b0f5e

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmodule ComponentsGuide.Research.Spec do
1010
def search_for(:npm_downloads_last_month, query) when is_binary(query) do
1111
query = String.trim(query)
1212
url = "https://api.npmjs.org/downloads/point/last-month/#{query}"
13+
1314
case Source.json_at(url) do
1415
{:ok, %{"downloads" => downloads_count, "package" => name}} ->
1516
%{downloads_count: downloads_count, name: name}
@@ -65,22 +66,13 @@ defmodule ComponentsGuide.Research.Spec do
6566

6667
table = data["data"]
6768

68-
if false do
69-
keys = Map.keys(table)
70-
inspect(keys)
71-
else
72-
matching_keywords =
73-
table
74-
|> Enum.flat_map(fn {key, value} ->
75-
case value["keywords"] |> String.contains?(query) do
76-
true -> [value]
77-
false -> []
78-
end
79-
end)
80-
81-
# table["documenthead"] |> inspect()
82-
matching_keywords
83-
end
69+
table
70+
|> Stream.filter(fn {_key, value} ->
71+
value["keywords"] |> String.contains?(query) ||
72+
value["title"] |> String.downcase() |> String.contains?(query) ||
73+
value["description"] |> String.downcase() |> String.contains?(query)
74+
end)
75+
|> Enum.map(fn {_key, value} -> value end)
8476
end
8577

8678
defp process_search_for(:wai_aria_practices, query, {:ok, document}) when is_binary(query) do

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,19 @@ defmodule ComponentsGuideWeb.ResearchController do
160160
:dl,
161161
[
162162
content_tag(:dt, "Description", class: "font-bold"),
163-
content_tag(:dd, "#{description}"),
163+
content_tag(:dd, "#{description}", class: "text-base"),
164164
case notes do
165165
"" ->
166166
[]
167167

168168
notes ->
169169
[
170170
content_tag(:dt, "Notes", class: "font-bold"),
171-
content_tag(:dd, "#{notes}")
171+
content_tag(:dd, "#{notes}", class: "text-base")
172172
]
173173
end,
174174
content_tag(:dt, "Internet Explorer", class: "font-bold"),
175-
content_tag(:dd, "#{inspect(stats["ie"])}")
175+
content_tag(:dd, "#{inspect(stats["ie"])}", class: "text-sm")
176176
# content_tag(:dd, "#{inspect(item)}")
177177
],
178178
class: "grid grid-flow-col gap-4",
@@ -260,9 +260,9 @@ defmodule ComponentsGuideWeb.ResearchController do
260260
# ComponentsGuide.Research.Source.clear_cache()
261261
[
262262
static(query),
263+
caniuse(query),
263264
bundlephobia(query),
264265
npm_downloads(query),
265-
caniuse(query),
266266
html_spec(query),
267267
aria_practices(query),
268268
html_aria(query)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<%
22
heading = "Research 🔍 specs and implementations"
33
heading = "Search across Can I Use, BundlePhobia, RFCs, W3 & WhatWG specs"
4+
search_url = fn (q) -> "?" <> URI.encode_query(q: q) end
5+
search_link = fn (q) -> link(q, to: search_url.(q)) end
46
%>
57

68
<header class="text-white bg-gray-900">
@@ -43,6 +45,18 @@ heading = "Search across Can I Use, BundlePhobia, RFCs, W3 & WhatWG specs"
4345
<li><%= link("wonka", to: "?q=wonka") %>
4446
</ul>
4547
</dd>
48+
<dt>Features</dt>
49+
<dd>
50+
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
51+
<li><%= search_link.("CSS Variables") %>
52+
<li><%= search_link.("Generators") %>
53+
<li><%= search_link.("Template Literals") %>
54+
<li><%= search_link.("Proxy") %>
55+
<li><%= search_link.("CSS Grid") %>
56+
<li><%= search_link.("Dynamic Import") %>
57+
<li><%= search_link.("BigInt") %>
58+
</ul>
59+
</dd>
4660
<dt>Specs</dt>
4761
<dd>
4862
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">

0 commit comments

Comments
 (0)