Skip to content

Commit 28e4ebb

Browse files
committed
Improve searching for specs
1 parent 95d6c51 commit 28e4ebb

File tree

5 files changed

+88
-85
lines changed

5 files changed

+88
-85
lines changed

apps/components_guide/lib/components_guide/research/static.ex

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,31 @@ defmodule ComponentsGuide.Research.Static do
3636
end)
3737

3838
@rfc_list [
39-
{"json", ["rfc8259", "rfc7159", "rfc4627"],
39+
{"JSON", ["rfc8259", "rfc7159", "rfc4627"],
4040
[
41-
url: "https://tools.ietf.org/html/rfc8259",
4241
media_type: "application/json"
4342
]},
44-
{"csv", ["rfc4180"],
43+
{"CSV", ["rfc4180"],
4544
[
46-
url: "https://tools.ietf.org/html/rfc4180",
4745
media_type: "text/csv"
48-
]}
46+
]},
47+
{"URL", ["rfc1738"], []},
48+
{"URI", ["rfc3986"], []},
49+
{"TCP", ["rfc793"], []},
50+
{"UDP", ["rfc768"], []},
51+
{"DNS", ["rfc1034", "rfc1035"], []},
52+
{"DNS TXT", ["rfc1464"], []},
53+
{"HTTP", ["rfc2616", "rfc7230", "rfc7231", "rfc7232", "rfc7233", "rfc7234", "rfc7235"], []},
54+
{"Timestamps", ["rfc3339", "ISO 8601"], []},
55+
{"WebSockets", ["rfc6455"], []}
4956
]
5057

58+
@aliases %{
59+
"redirect" => ["301", "302"],
60+
"invalid" => ["412", "422"],
61+
"etag" => ["304"]
62+
}
63+
5164
def search_for(query) when is_binary(query) do
5265
[
5366
search_for(:http_status, query),
@@ -75,8 +88,10 @@ defmodule ComponentsGuide.Research.Static do
7588
{^query, _, _} ->
7689
true
7790

78-
{_, rfcs, metadata} ->
79-
Enum.member?(rfcs, query) || Keyword.get(metadata, :media_type) == query
91+
{name, rfcs, metadata} ->
92+
String.downcase(name) == query ||
93+
Enum.member?(rfcs, query) ||
94+
Keyword.get(metadata, :media_type) == query
8095
end
8196

8297
@rfc_list

apps/components_guide_web/assets/css/app.css

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
border: 0;
4141
}
4242

43-
article a:not(nav *) {
44-
text-decoration: underline;
43+
article {
44+
/* --link-decoration: underline; */
4545
}
4646
article a:hover {
47-
text-decoration: underline;
47+
--hover\:link-decoration: underline;
4848
}
4949
article figcaption {
5050
font-style: italic;
@@ -60,12 +60,11 @@ a:not([class]) {
6060
text-decoration: var(--link-decoration);
6161
}
6262
a:hover:not([class]) {
63-
--hover\:links-decoration: var(--link-decoration);
64-
text-decoration: var(--hover\:links-decoration);
63+
text-decoration: var(--hover\:link-decoration);
6564
}
6665

6766
nav {
68-
--hover\:links-decoration: underline;
67+
--hover\:link-decoration: underline;
6968
}
7069
nav a:only-of-type {
7170
--link-padding: 0.5rem;

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

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -318,28 +318,62 @@ defmodule ComponentsGuideWeb.ResearchView do
318318
"mb-4 text-xl spacing-y-4 p-4 text-white bg-indigo-900 border border-indigo-800 rounded-lg shadow-lg"
319319
)
320320
end
321-
end
322321

323-
def render_static({type, info}) do
324-
render_static(type, info)
325-
end
322+
def unordered_list(items, attrs \\ []) do
323+
children =
324+
Enum.map(items, fn text ->
325+
content_tag(:li, text)
326+
end)
326327

327-
def render_static(:http_status, {name, description}) do
328-
Section.card([
329-
content_tag(:h3, "HTTP Status: #{name}", class: "text-2xl"),
330-
content_tag(:p, description)
331-
])
328+
content_tag(:ul, children, attrs)
329+
end
330+
331+
def description_list(items) do
332+
children =
333+
items
334+
|> Stream.filter(fn {_title, value} -> value != nil end)
335+
|> Enum.map(fn {title, value} ->
336+
content_tag(:div, [
337+
content_tag(:dt, title, class: "font-bold"),
338+
content_tag(:dd, value, class: "pl-4")
339+
])
340+
end)
341+
342+
content_tag(:dl, children)
343+
end
332344
end
333345

334-
def render_static(:rfc, {name, rfcs, metadata}) do
335-
Section.card([
336-
content_tag(:h3, "RFC: #{name}", class: "text-2xl"),
337-
content_tag(:p, inspect(rfcs)),
338-
content_tag(:p, inspect(metadata)),
339-
content_tag(:dl, [
340-
content_tag(:dt, "Media (MIME) Type"),
341-
content_tag(:dd, Keyword.get(metadata, :media_type))
346+
defmodule Static do
347+
def render(:http_status, {name, description}) do
348+
Section.card([
349+
content_tag(:h3, "HTTP Status: #{name}", class: "text-2xl font-bold"),
350+
content_tag(:p, description)
351+
])
352+
end
353+
354+
def render(:rfc, {name, specs, metadata}) do
355+
Section.card([
356+
content_tag(:h3, "#{name} Spec", class: "text-2xl font-bold"),
357+
Section.description_list([
358+
{"Specs",
359+
specs
360+
|> Enum.map(&link_to_spec/1)
361+
|> Section.unordered_list(class: "flex list-disc ml-4 space-x-8")},
362+
{"Media (MIME) Type", Keyword.get(metadata, :media_type)}
363+
])
342364
])
343-
])
365+
end
366+
367+
def link_to_spec("rfc" <> _ = spec) do
368+
link(spec, to: "https://tools.ietf.org/html/" <> spec)
369+
end
370+
371+
def link_to_spec(spec) do
372+
spec
373+
end
374+
end
375+
376+
def render_static({type, info}) do
377+
Static.render(type, info)
344378
end
345379
end

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%
22
heading = "Research 🔍 specs and implementations"
3-
heading = "Search across Can I Use, BundlePhobia, W3 & WhatWG specs"
3+
heading = "Search across Can I Use, BundlePhobia, RFCs, W3 & WhatWG specs"
44
%>
55

66
<header class="text-white bg-gray-900">
@@ -30,7 +30,7 @@ heading = "Search across Can I Use, BundlePhobia, W3 & WhatWG specs"
3030
<li><%= link("menu", to: "?q=menu") %>
3131
</ul>
3232
</dd>
33-
<dt>Third-party</dt>
33+
<dt>Libraries</dt>
3434
<dd>
3535
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
3636
<li><%= link("react-dom", to: "?q=react-dom") %>
@@ -43,10 +43,12 @@ heading = "Search across Can I Use, BundlePhobia, W3 & WhatWG specs"
4343
<li><%= link("wonka", to: "?q=wonka") %>
4444
</ul>
4545
</dd>
46-
<dt>Concepts</dt>
46+
<dt>Specs</dt>
4747
<dd>
4848
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
49-
<li><%= link("error", to: "?q=error") %>
49+
<li><%= link("JSON", to: "?q=JSON") %>
50+
<li><%= link("CSV", to: "?q=CSV") %>
51+
<li><%= link("ISO 8601", to: "?q=ISO%208601") %>
5052
</ul>
5153
</dd>
5254
</dl>

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

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,9 @@
11
<%
22
heading = "Research 🔍 specs and implementations"
3-
heading = "Search across Can I Use, BundlePhobia, W3 & WhatWG specs"
3+
heading = "Search across Can I Use, BundlePhobia, RFCs, W3 & WhatWG specs"
44
%>
5-
<header class="text-white bg-gray-900">
6-
<div class="bg-indigo-900">
7-
<h2 class="mx-auto max-w-4xl py-4 text-2xl text-center italic leading-tight text-indigo-100">
8-
<%= heading %>
9-
</h2>
10-
</div>
11-
<section class="container px-6 pb-8">
12-
<form role=search action="/research" class="flex h-full pt-8 items-center">
13-
<input type=text name=q placeholder="Search" class="w-full py-1 px-6 text-3xl bg-white text-black border rounded-full" value="<%= @query %>">
14-
</form>
15-
<dl
16-
class="text-xl grid gap-2 items-center pt-4 px-6"
17-
style="
18-
grid-template-columns: auto 1fr;
19-
--link-color: #76a9fa;
20-
--hover\:link-decoration: underline;"
21-
>
22-
<dt>HTML & Roles</dt>
23-
<dd>
24-
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
25-
<li><%= link("form", to: "?q=form") %>
26-
<li><%= link("button", to: "?q=button") %>
27-
<li><%= link("contentinfo", to: "?q=contentinfo") %>
28-
<li><%= link("dialog", to: "?q=dialog") %>
29-
<li><%= link("menu", to: "?q=menu") %>
30-
</ul>
31-
</dd>
32-
<dt>Third-party</dt>
33-
<dd>
34-
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
35-
<li><%= link("react-dom", to: "?q=react-dom") %>
36-
<li><%= link("preact", to: "?q=preact") %>
37-
<li><%= link("vue", to: "?q=vue") %>
38-
<li><%= link("lit-html", to: "?q=lit-html") %>
39-
<li><%= link("xstate", to: "?q=xstate") %>
40-
<li><%= link("mobx", to: "?q=mobx") %>
41-
<li><%= link("lodash", to: "?q=lodash") %>
42-
<li><%= link("wonka", to: "?q=wonka") %>
43-
</ul>
44-
</dd>
45-
<dt>Concepts</dt>
46-
<dd>
47-
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
48-
<li><%= link("error", to: "?q=error") %>
49-
</ul>
50-
</dd>
51-
</dl>
52-
</section>
53-
</header>
5+
6+
<%= render @view_module, "_header.html", query: @query %>
547

558
<div class="text-white bg-gray-900 py-8">
569
<div class="container">

0 commit comments

Comments
 (0)