@@ -22,7 +22,7 @@ defmodule ComponentsGuideWeb.ResearchController do
22
22
end
23
23
24
24
defp h2 ( text ) do
25
- content_tag ( :h2 , text , class: "font-bold" )
25
+ content_tag ( :h2 , text , class: "text-2xl font-bold" )
26
26
end
27
27
28
28
defp present_results ( results ) when is_binary ( results ) do
@@ -36,12 +36,34 @@ defmodule ComponentsGuideWeb.ResearchController do
36
36
content_tag ( :ul , items )
37
37
end
38
38
39
+ defp bundlephobia ( query ) do
40
+ case Spec . search_for ( :bundlephobia , query ) do
41
+ # %{"assets" => [%{"gzip" => 3920, "name" => "main", "size" => 10047, "type" => "js"}], "dependencyCount" => 0, "dependencySizes" => [%{"approximateSize" => 9537, "name" => "preact"}], "description" => "Fast 3kb React-compatible Virtual DOM library.", "gzip" => 3920, "hasJSModule" => "dist/preact.module.js", "hasJSNext" => false, "hasSideEffects" => true, "name" => "preact", "repository" => "https://github.com/preactjs/preact.git", "scoped" => false, "size" => 10047, "version" => "10.4.1"}
42
+ % { "name" => name , "size" => size , "gzip" => size_gzip , "version" => version } ->
43
+ emerging_3g_ms = floor ( size_gzip / 50 )
44
+ content_tag ( :article , [
45
+ content_tag ( :h3 , "#{ name } @#{ version } " , class: "text-2xl" ) ,
46
+ content_tag ( :dl , [
47
+ content_tag ( :dt , "Minified" , class: "font-bold" ) ,
48
+ content_tag ( :dd , "#{ size } " ) ,
49
+ content_tag ( :dt , "Minified + Gzipped" , class: "font-bold" ) ,
50
+ content_tag ( :dd , "#{ size_gzip } " ) ,
51
+ content_tag ( :dt , "Emerging 3G (50kB/s)" , class: "font-bold" ) ,
52
+ content_tag ( :dd , "#{ emerging_3g_ms } ms" ) ,
53
+ ] , class: "grid grid-flow-col grid-rows-2" )
54
+ ] , class: "text-xl" )
55
+
56
+ other ->
57
+ inspect ( other )
58
+ end
59
+ end
60
+
39
61
defp load_results ( query ) when is_binary ( query ) do
40
62
# ComponentsGuide.Research.Source.clear_cache()
41
63
[
42
64
content_tag ( :article , [
43
65
h2 ( "Bundlephobia" ) ,
44
- Spec . search_for ( : bundlephobia, query ) |> present_results ( )
66
+ bundlephobia ( query )
45
67
] ) ,
46
68
content_tag ( :article , [
47
69
h2 ( "Can I Use" ) ,
0 commit comments