about summary refs log tree commit diff
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2023-10-15T22·58+0200
committerclbot <clbot@tvl.fyi>2023-10-15T23·05+0000
commit71297499685d7d2c1c839c94187cf8d2fda54e4c (patch)
treec5b4ab949124b5cb6248a3fa627fa0dbd95dc5d9
parent81b790af1d8a49b52376c566183591396f60fb3e (diff)
feat(users/Profpatsch/whatcd-resolver): also link json ld fields r/6820
We can cross-reference all of these to schema.org, it should work for
most of the fields.

Change-Id: I38d8dbc7e964764886ddd156c4148bcf3ee376f3
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9744
Autosubmit: Profpatsch <mail@profpatsch.de>
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
-rw-r--r--users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs b/users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs
index 858b8a000dec..6b8efd8a78c0 100644
--- a/users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs
+++ b/users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs
@@ -452,7 +452,7 @@ renderJsonld = \case
       <dd><a href={obj.id_}>{obj.id_}</a></dd>
       <dt>Fields</dt>
       <dd>
-        {obj.previewFields & toDefinitionList renderJsonld}
+        {obj.previewFields & toDefinitionList schemaType renderJsonld}
         <div>
           <button
             hx-get={snippetHref obj.id_}
@@ -471,11 +471,11 @@ renderJsonld = \case
 
       schemaTypes xs =
         xs
-          <&> ( \t ->
-                  let href :: Text = [fmt|https://schema.org/{t}|] in [hsx|<a href={href} target="_blank">{t}</a>|]
-              )
+          <&> schemaType
           & List.intersperse ", "
           & mconcat
+      schemaType t =
+        let href :: Text = [fmt|https://schema.org/{t}|] in [hsx|<a href={href} target="_blank">{t}</a>|]
   JsonldArray arr ->
     toOrderedList renderJsonld arr
   JsonldField f -> mkVal f
@@ -569,7 +569,7 @@ mkVal = \case
   Json.Object obj ->
     obj
       & KeyMap.toMapText
-      & toDefinitionList mkVal
+      & toDefinitionList (Html.toHtml @Text) mkVal
 
 toOrderedList :: (Foldable t1) => (t2 -> Html) -> t1 t2 -> Html
 toOrderedList mkValFn arr =
@@ -584,11 +584,11 @@ toUnorderedList mkValFn arr =
     & Html.ul
 
 -- | Render a definition list from a Map
-toDefinitionList :: (t -> Html) -> Map Text t -> Html
-toDefinitionList mkValFn obj =
+toDefinitionList :: (Text -> Html) -> (t -> Html) -> Map Text t -> Html
+toDefinitionList mkKeyFn mkValFn obj =
   obj
     & Map.toList
-    & foldMap (\(k, v) -> Html.dt (Html.toHtml @Text k) <> Html.dd (mkValFn v))
+    & foldMap (\(k, v) -> Html.dt (mkKeyFn k) <> Html.dd (mkValFn v))
     & Html.dl
 
 -- | Render a table-like structure of json values as an HTML table.