Skip to content

Commit 8cb049a

Browse files
committed
Add bundlephobia
1 parent ce8ec94 commit 8cb049a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

apps/components_guide/lib/components_guide/research/source.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ defmodule ComponentsGuide.Research.Source do
5757
def get(url) do
5858
uri = URI.parse(url)
5959

60-
IO.puts("fetching URL #{uri} #{uri.host} #{uri.path}")
6160
{:ok, conn} = Mint.HTTP.connect(:https, uri.host, 443)
62-
{:ok, conn, request_ref} = Mint.HTTP.request(conn, "GET", uri.path, [], nil)
61+
62+
path =
63+
case uri do
64+
%{query: nil, path: path} -> path
65+
%{query: query, path: path} -> path <> "?" <> query
66+
end
67+
68+
IO.puts("fetching URL #{uri} #{uri.host} #{path}")
69+
{:ok, conn, request_ref} = Mint.HTTP.request(conn, "GET", path, [], nil)
6370

6471
receive_mint_response(%Fetch{}, conn, request_ref)
6572
end

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ defmodule ComponentsGuide.Research.Spec do
4545
# |> Floki.find("#id-#{query}")
4646
|> Floki.raw_html()
4747
end
48+
49+
def search_for(:bundlephobia, query) when is_binary(query) do
50+
{:ok, data} = Source.json_at("https://bundlephobia.com/api/size?package=#{query}")
51+
52+
inspect(data)
53+
end
4854
end

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ defmodule ComponentsGuideWeb.ResearchController do
3737
end
3838

3939
defp load_results(query) when is_binary(query) do
40-
# Spec.clear_search_cache()
40+
# ComponentsGuide.Research.Source.clear_cache()
4141
[
42+
content_tag(:article, [
43+
h2("Bundlephobia"),
44+
Spec.search_for(:bundlephobia, query) |> present_results()
45+
]),
4246
content_tag(:article, [
4347
h2("Can I Use"),
4448
Spec.search_for(:caniuse, query) |> present_results()

0 commit comments

Comments
 (0)