Strip HTML comments from READMEs
This commit is contained in:
parent
cc3ee90f0b
commit
fee164d3e4
1
elm.json
1
elm.json
|
@ -11,6 +11,7 @@
|
|||
"elm/html": "1.0.0",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm/regex": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"pablohirafuji/elm-markdown": "2.0.5"
|
||||
},
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
module Pages.App_String exposing (Model, Msg, Params, page)
|
||||
|
||||
import Regex
|
||||
import Html exposing (Html, button, div, h2, h5, img, text, ul, li, a, p, span)
|
||||
import Html.Attributes exposing (src, style, class, alt, href)
|
||||
import Html.Events exposing (onClick)
|
||||
|
@ -11,6 +12,9 @@ import Spa.Page as Page exposing (Page)
|
|||
import Spa.Url as Url exposing (Url)
|
||||
|
||||
|
||||
-- INIT
|
||||
|
||||
|
||||
page : Page Params Model Msg
|
||||
page =
|
||||
Page.element
|
||||
|
@ -20,9 +24,6 @@ page =
|
|||
, subscriptions = subscriptions
|
||||
}
|
||||
|
||||
-- INIT
|
||||
|
||||
|
||||
type alias Params =
|
||||
{ app : String
|
||||
}
|
||||
|
@ -56,6 +57,7 @@ init url =
|
|||
|
||||
|
||||
default_image : String
|
||||
-- FIXME: change to absolute URL, if this works?
|
||||
default_image = "http://localhost:8000/logo.png"
|
||||
|
||||
|
||||
|
@ -78,6 +80,7 @@ update msg model =
|
|||
case result of
|
||||
Ok apps ->
|
||||
let
|
||||
-- TODO better way of getting a single app?
|
||||
apps_filtered = List.filter (\app -> app.name == model.url.params.app) apps
|
||||
in
|
||||
case List.head apps_filtered of
|
||||
|
@ -92,7 +95,14 @@ update msg model =
|
|||
GotText result ->
|
||||
case result of
|
||||
Ok content ->
|
||||
( { model | readme = content }, Cmd.none )
|
||||
-- update model.content with the loaded README
|
||||
let
|
||||
-- remove HTML comments
|
||||
pattern = "<!--.*-->"
|
||||
maybeRegex = Regex.fromString pattern
|
||||
regex = Maybe.withDefault Regex.never maybeRegex
|
||||
in
|
||||
( { model | readme = Regex.replace regex (\_ -> "") content }, Cmd.none )
|
||||
|
||||
Err _ ->
|
||||
( { model | status = Failure }, Cmd.none )
|
||||
|
@ -179,9 +189,11 @@ viewApp app readme =
|
|||
, viewStatusBadge app
|
||||
, repository_link
|
||||
, a [ class "card-link", href "http://example.com" ] [ text "homepage" ]
|
||||
-- FIXME: add actual homepage link to apps.json and render here
|
||||
]
|
||||
, img [ class "card-img-top", src icon_url, alt ("icon for " ++ app.name) ] []
|
||||
, div [ class "card-body" ]
|
||||
-- render Markdown with no special options
|
||||
[ div [] (Markdown.toHtml Nothing readme)
|
||||
]
|
||||
, div [ class "card-footer" ]
|
||||
|
@ -194,16 +206,20 @@ viewApp app readme =
|
|||
|
||||
loadData : Cmd Msg
|
||||
loadData =
|
||||
-- fetch app JSON and README in parallel
|
||||
Cmd.batch
|
||||
[ Http.get
|
||||
-- FIXME: change to absolute URL, if this works?
|
||||
{ url = "http://localhost:8000/abra-apps-list.json"
|
||||
, expect = Http.expectJson GotApps appListDecoder }
|
||||
, Http.get
|
||||
-- FIXME add branch name to apps.json, load actual README
|
||||
{ url = "http://localhost:1234/coop-cloud/adapt_authoring/raw/branch/main/README.md"
|
||||
, expect = Http.expectString GotText }
|
||||
]
|
||||
|
||||
featuresDecoder =
|
||||
-- get features.status if it's there
|
||||
(Decode.oneOf
|
||||
[ Decode.at [ "status" ] Decode.string
|
||||
, Decode.succeed ""
|
||||
|
|
Reference in New Issue