refactor: replace aeson ToJSON/FromJSON with json-fleece schemas
- RecipeSearchEntry: replace genericToJSON ToJSON with Fleece schema using object combinators (required, optionalNullable, list text) - SchemaOrgRecipe: replace manual FromJSON instance with Fleece decoder that reuses existing helper functions for quirky fields - Html.hs: use Fleece.Aeson.Encoder.encode instead of Data.Aeson.encode - stack.yaml: add shrubbery + json-fleece extra-deps - package.yaml: add json-fleece-aeson + json-fleece-core deps - Remove unused LANGUAGE pragmas and redundant brackets
This commit is contained in:
+4
-3
@@ -16,7 +16,6 @@ module Roux.Html (
|
||||
) where
|
||||
|
||||
import Control.Monad (unless)
|
||||
import Data.Aeson (encode)
|
||||
import Data.ByteString.Lazy (ByteString)
|
||||
import qualified Data.ByteString.Lazy as LB
|
||||
import Data.Function ((&))
|
||||
@@ -26,6 +25,8 @@ import Data.Ratio (denominator, numerator)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Encoding (decodeUtf8)
|
||||
import qualified Fleece.Aeson as Fleece
|
||||
import qualified Fleece.Core as FC
|
||||
import qualified Text.Blaze.Html.Renderer.Utf8 as R
|
||||
import Text.Blaze.Html5 as H
|
||||
import Text.Blaze.Html5.Attributes as A
|
||||
@@ -349,10 +350,10 @@ indexPage _mode recipes =
|
||||
H.div ! A.id "roux-recipe-list" $ H.p "Loading recipes..."
|
||||
-- Embedded JSON: recipe data
|
||||
H.script ! A.id "roux-recipe-data" ! A.type_ "application/json" $
|
||||
H.toHtml (decodeUtf8 (LB.toStrict (encode (Prelude.map Idx.toSearchEntry (filterOk recipes)))))
|
||||
H.toHtml (decodeUtf8 (LB.toStrict (Fleece.encode (Fleece.encoder (FC.list Idx.recipeSearchEntrySchema)) (Prelude.map Idx.toSearchEntry (filterOk recipes)))))
|
||||
-- Embedded JSON: error data
|
||||
H.script ! A.id "roux-errors-data" ! A.type_ "application/json" $
|
||||
H.toHtml (decodeUtf8 (LB.toStrict (encode (Prelude.map Idx.toSearchEntry (filterBad recipes)))))
|
||||
H.toHtml (decodeUtf8 (LB.toStrict (Fleece.encode (Fleece.encoder (FC.list Idx.recipeSearchEntrySchema)) (Prelude.map Idx.toSearchEntry (filterBad recipes)))))
|
||||
-- Inline JS
|
||||
H.script ! A.type_ "text/javascript" $ H.preEscapedText searchJs
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user