Skip to content

Commit 685f0ef

Browse files
authored
Merge pull request #401 from georgesboris/patch-4
Fix button links on elm-pages.com
2 parents 35bf525 + 43a3af1 commit 685f0ef

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

examples/docs/app/Route/Index.elm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Head
77
import Head.Seo as Seo
88
import Html.Styled as Html exposing (..)
99
import Html.Styled.Attributes as Attr exposing (css)
10-
import Link
10+
import Link exposing (Link)
1111
import Pages.Url
1212
import PagesMsg exposing (PagesMsg)
1313
import Route exposing (Route)
@@ -118,7 +118,7 @@ landingView =
118118
{ heading = "Pull in typed Elm data to your pages"
119119
, body = "Whether your data is coming from markdown files, APIs, a CMS, or all of the above, elm-pages lets you pull in just the data you need for a page. No loading spinners, no Msg or update logic, just define your data and use it in your view."
120120
, buttonText = "Check out the Docs"
121-
, buttonLink = Route.Docs__Section__ { section = Nothing }
121+
, buttonLink = Route.Docs__Section__ { section = Nothing } |> Link.internal
122122
, svgIcon = "M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"
123123
, code =
124124
( "app/Route/Repo/Name_.elm", """module Route.Repo.Name_ exposing (Data, Model, Msg, route)
@@ -161,7 +161,7 @@ view app =
161161
{ heading = "Combine data from multiple sources"
162162
, body = "Wherever the data came from, you can transform BackendTasks and combine multiple BackendTasks using the full power of Elm's type system."
163163
, buttonText = "Learn more about BackendTasks"
164-
, buttonLink = Route.Docs__Section__ { section = Just "data-sources" }
164+
, buttonLink = "https://package.elm-lang.org/packages/dillonkearns/elm-pages/latest/BackendTask" |> Link.external
165165
, svgIcon = "M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"
166166
, code =
167167
( "src/Project.elm", """type alias Project =
@@ -189,7 +189,7 @@ all =
189189
|> BackendTask.resolve
190190
191191
192-
stars : String -> BackendTask Int
192+
stars : String -> BackendTask FatalError Int
193193
stars repoName =
194194
Decode.field "stargazers_count" Decode.int
195195
|> BackendTask.Http.getJson ("https://api.github.com/repos/dillonkearns/" ++ repoName)
@@ -200,7 +200,7 @@ stars repoName =
200200
{ heading = "SEO"
201201
, body = "Make sure your site previews look polished with the type-safe SEO API. `elm-pages build` pre-renders HTML for your pages. And your SEO tags get access to the page's BackendTasks."
202202
, buttonText = "Learn about the SEO API"
203-
, buttonLink = Route.Docs__Section__ { section = Nothing }
203+
, buttonLink = "https://package.elm-lang.org/packages/dillonkearns/elm-pages/latest/Head-Seo" |> Link.external
204204
, svgIcon = "M10 21h7a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v11m0 5l4.879-4.879m0 0a3 3 0 104.243-4.242 3 3 0 00-4.243 4.242z"
205205
, code =
206206
( "app/Route/Blog/Slug_.elm", """head :
@@ -233,7 +233,7 @@ head app =
233233
{ heading = "Full-Stack Elm"
234234
, body = "With server-rendered routes, you can seamlessly pull in user-specific data from your backend and hydrate it into a dynamic Elm application. No API layer required. You can access incoming HTTP requests from your server-rendered routes, and even use the Session API to manage key-value pairs through signed cookies."
235235
, buttonText = "Learn about server-rendered routes"
236-
, buttonLink = Route.Docs__Section__ { section = Nothing }
236+
, buttonLink = Route.Docs__Section__ { section = Nothing } |> Link.internal
237237
, svgIcon = "M20.25 6.375c0 2.278-3.694 4.125-8.25 4.125S3.75 8.653 3.75 6.375m16.5 0c0-2.278-3.694-4.125-8.25-4.125S3.75 4.097 3.75 6.375m16.5 0v11.25c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125V6.375m16.5 0v3.75m-16.5-3.75v3.75m16.5 0v3.75C20.25 16.153 16.556 18 12 18s-8.25-1.847-8.25-4.125v-3.75m16.5 0c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125"
238238
, code =
239239
( "app/Route/Feed.elm", """module Route.Feed exposing (ActionData, Data, Model, Msg, RouteParams, route)
@@ -314,7 +314,7 @@ view app shared model =
314314
{ heading = "Forms Without the Wiring"
315315
, body = "elm-pages uses progressively enhanced web standards. The Web has had a way to send data to backends for decades, no need to re-invent the wheel! Just modernize it with some progressive enhancement. You define your Form and validations declaratively, and elm-pages gives you client-side validations and state with no Model/init/update wiring whatsoever. You can even derive pending/optimistic UI from the in-flight form submissions (which elm-pages manages and exposes to you for free as well!)."
316316
, buttonText = "Learn about the Form API"
317-
, buttonLink = Route.Docs__Section__ { section = Nothing }
317+
, buttonLink = "https://package.elm-lang.org/packages/dillonkearns/elm-pages/latest/Pages-Form" |> Link.external
318318
, svgIcon = "M3.375 19.5h17.25m-17.25 0a1.125 1.125 0 01-1.125-1.125M3.375 19.5h7.5c.621 0 1.125-.504 1.125-1.125m-9.75 0V5.625m0 12.75v-1.5c0-.621.504-1.125 1.125-1.125m18.375 2.625V5.625m0 12.75c0 .621-.504 1.125-1.125 1.125m1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125m0 3.75h-7.5A1.125 1.125 0 0112 18.375m9.75-12.75c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125m19.5 0v1.5c0 .621-.504 1.125-1.125 1.125M2.25 5.625v1.5c0 .621.504 1.125 1.125 1.125m0 0h17.25m-17.25 0h7.5c.621 0 1.125.504 1.125 1.125M3.375 8.25c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125m17.25-3.75h-7.5c-.621 0-1.125.504-1.125 1.125m8.625-1.125c.621 0 1.125.504 1.125 1.125v1.5c0 .621-.504 1.125-1.125 1.125m-17.25 0h7.5m-7.5 0c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125M12 10.875v-1.5m0 1.5c0 .621-.504 1.125-1.125 1.125M12 10.875c0 .621.504 1.125 1.125 1.125m-2.25 0c.621 0 1.125.504 1.125 1.125M13.125 12h7.5m-7.5 0c-.621 0-1.125.504-1.125 1.125M20.625 12c.621 0 1.125.504 1.125 1.125v1.5c0 .621-.504 1.125-1.125 1.125m-17.25 0h7.5M12 14.625v-1.5m0 1.5c0 .621-.504 1.125-1.125 1.125M12 14.625c0 .621.504 1.125 1.125 1.125m-2.25 0c.621 0 1.125.504 1.125 1.125m0 1.5v-1.5m0 0c0-.621.504-1.125 1.125-1.125m0 0h7.5"
319319
, code =
320320
( "app/Route/Signup.elm", """module Route.Signup exposing (ActionData, Data, Model, Msg, RouteParams, route)
@@ -474,7 +474,7 @@ formHandlers =
474474
firstSection :
475475
{ heading : String
476476
, body : String
477-
, buttonLink : Route
477+
, buttonLink : Link
478478
, buttonText : String
479479
, svgIcon : String
480480
, code : ( String, String )

examples/docs/src/Link.elm

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
1-
module Link exposing (link)
1+
module Link exposing (Link, external, internal, link)
22

33
import Html.Styled exposing (Attribute, Html, a)
44
import Html.Styled.Attributes as Attr
55
import Route exposing (Route)
66

77

8-
link : Route -> List (Attribute msg) -> List (Html msg) -> Html msg
9-
link route attrs children =
10-
Route.toLink
11-
(\anchorAttrs ->
8+
external : String -> Link
9+
external =
10+
ExternalLink
11+
12+
13+
internal : Route -> Link
14+
internal =
15+
RouteLink
16+
17+
18+
type Link
19+
= RouteLink Route
20+
| ExternalLink String
21+
22+
23+
link : Link -> List (Attribute msg) -> List (Html msg) -> Html msg
24+
link link_ attrs children =
25+
case link_ of
26+
RouteLink route ->
27+
Route.toLink
28+
(\anchorAttrs ->
29+
a
30+
(List.map Attr.fromUnstyled anchorAttrs ++ attrs)
31+
children
32+
)
33+
route
34+
35+
ExternalLink string ->
1236
a
13-
(List.map Attr.fromUnstyled anchorAttrs ++ attrs)
37+
(Attr.href string :: attrs)
1438
children
15-
)
16-
route

0 commit comments

Comments
 (0)