Skip to content

Commit

Permalink
Fix links to github source.
Browse files Browse the repository at this point in the history
Closes #228
  • Loading branch information
turboMaCk committed Nov 22, 2020
1 parent 29f5f02 commit 82e09dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/Page/Options.elm
Expand Up @@ -33,6 +33,7 @@ import Html.Attributes
( class
, colspan
, href
, target
)
import Html.Events
exposing
Expand Down Expand Up @@ -218,7 +219,9 @@ viewResultItemDetails channel item =
case Search.channelDetailsFromId channel of
Just channelDetails ->
a
[ href <| githubUrlPrefix channelDetails.branch ++ (value |> String.replace ":" "#L") ]
[ href <| githubUrlPrefix channelDetails.branch ++ (value |> String.replace ":" "#L")
, target "_blank"
]
[ text <| value ]

Nothing ->
Expand Down
15 changes: 8 additions & 7 deletions src/Page/Packages.elm
Expand Up @@ -34,6 +34,7 @@ import Html.Attributes
( class
, colspan
, href
, target
)
import Html.Events
exposing
Expand Down Expand Up @@ -248,18 +249,18 @@ viewResultItemDetails channel item =
githubUrlPrefix branch =
"https://github.com/NixOS/nixpkgs/blob/" ++ branch ++ "/"

cleanPosition value =
if String.startsWith "source/" value then
String.dropLeft 7 value

else
value
cleanPosition =
Regex.fromString "^[0-9a-f]+\\.tar\\.gz\\/"
|> Maybe.withDefault Regex.never
>> (\reg -> Regex.replace reg (\_ -> ""))

asGithubLink value =
case Search.channelDetailsFromId channel of
Just channelDetails ->
a
[ href <| githubUrlPrefix channelDetails.branch ++ (value |> String.replace ":" "#L" |> cleanPosition) ]
[ href <| githubUrlPrefix channelDetails.branch ++ (value |> String.replace ":" "#L" |> cleanPosition)
, target "blank_"
]
[ text <| cleanPosition value ]

Nothing ->
Expand Down
3 changes: 3 additions & 0 deletions src/Search.elm
Expand Up @@ -264,6 +264,9 @@ type Channel
| Release_20_09


{-| TODO: we should consider using more dynamic approach here
and load channels from apis similar to what status page does
-}
type alias ChannelDetails =
{ id : String
, title : String
Expand Down

0 comments on commit 82e09dd

Please sign in to comment.