diff --git a/generator/src/render.js b/generator/src/render.js index 5ed5318c..2bf3e81d 100755 --- a/generator/src/render.js +++ b/generator/src/render.js @@ -229,17 +229,6 @@ async function outputString( /** @typedef { { head: any[]; errors: any[]; contentJson: any[]; html: string; route: string; title: string; } } Arg */ -/** - * @param {string} string - */ -function jsonOrNull(string) { - try { - return JSON.parse(string); - } catch (e) { - return { invalidJson: e.toString() }; - } -} - async function runHttpJob(app, mode, requestToPerform, fs, hasFsAccess) { pendingDataSourceCount += 1; try { @@ -342,7 +331,6 @@ async function readFileJobNew(req, patternsToWatch) { parsedFrontmatter: parsedFile.data, withoutFrontmatter: parsedFile.content, rawFile: fileContents, - jsonFile: jsonOrNull(fileContents), }); } catch (error) { throw { diff --git a/src/DataSource/File.elm b/src/DataSource/File.elm index 530d7375..26de5f90 100644 --- a/src/DataSource/File.elm +++ b/src/DataSource/File.elm @@ -43,6 +43,7 @@ plain old JSON in Elm. -} import DataSource exposing (DataSource) +import DataSource.File import DataSource.Http import DataSource.Internal.Request import Json.Decode as Decode exposing (Decoder) @@ -273,7 +274,14 @@ The Decode will strip off any unused JSON data. -} jsonFile : Decoder a -> String -> DataSource a jsonFile jsonFileDecoder filePath = - read filePath (Decode.field "jsonFile" jsonFileDecoder) + rawFile filePath + |> DataSource.andThen + (\jsonString -> + jsonString + |> Decode.decodeString jsonFileDecoder + |> Result.mapError Decode.errorToString + |> DataSource.fromResult + ) {-| Gives us the file's content without stripping off frontmatter.