From e44398f4c23743c745844c0c387b4ce8541ae660 Mon Sep 17 00:00:00 2001 From: Sean Kovacs Date: Thu, 29 Apr 2021 16:57:14 -0400 Subject: [PATCH] oops - added exporting of body to html file --- package.json | 2 +- .../__snapshots__/gatsby-node.js.snap | 6 +++++- src/__tests__/gatsby-node.js | 21 ++++++++++++++----- src/gatsby-node.js | 13 ++++++++---- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index ed6eb8f..0290c26 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gatsby-plugin-guru-export", "description": "Creates an Guru export for your Gatsby site.", - "version": "0.1.0", + "version": "0.2.0", "author": "Sean Kovacs ", "bugs": { "url": "https://github.com/calendly/gatsby-plugin-guru-export" diff --git a/src/__tests__/__snapshots__/gatsby-node.js.snap b/src/__tests__/__snapshots__/gatsby-node.js.snap index ebd9001..49da99d 100644 --- a/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -7,9 +7,13 @@ ExternalUrl: http://dummy.url/sample1 " `; -exports[`gatsby-plugin-guru-export onPostBuild exports 2`] = ` +exports[`gatsby-plugin-guru-export onPostBuild exports 2`] = `"
test
"`; + +exports[`gatsby-plugin-guru-export onPostBuild exports 3`] = ` "Title: sample title 2 ExternalId: 2 ExternalUrl: http://dummy.url/sample2 " `; + +exports[`gatsby-plugin-guru-export onPostBuild exports 4`] = `"
test
"`; diff --git a/src/__tests__/gatsby-node.js b/src/__tests__/gatsby-node.js index b715036..a3ddb7d 100755 --- a/src/__tests__/gatsby-node.js +++ b/src/__tests__/gatsby-node.js @@ -32,7 +32,8 @@ describe("gatsby-plugin-guru-export", () => { id: 1, title: "sample title", description: "sample description", - slug: 'sample1' + slug: 'sample1', + htmlBody: '
test
' }, }, }, @@ -42,7 +43,8 @@ describe("gatsby-plugin-guru-export", () => { id: 2, title: "sample title 2", description: "sample description 2", - slug: 'sample2' + slug: 'sample2', + htmlBody: '
test
' }, }, }, @@ -62,6 +64,7 @@ describe("gatsby-plugin-guru-export", () => { title description slug + htmlBody } } } @@ -82,22 +85,30 @@ describe("gatsby-plugin-guru-export", () => { ExternalId: "id", ExternalUrl: (serializedData) => `${serializedData.site.siteMetadata.siteUrl}${serializedData.slug}`, + Body: 'htmlBody' }, }, ], }; await onPostBuild({ graphql }, options); - expect(fs.writeFile).toHaveBeenCalledTimes(2); + expect(fs.writeFile).toHaveBeenCalledTimes(4); const call0 = fs.writeFile.mock.calls[0]; const call1 = fs.writeFile.mock.calls[1]; expect(call0[0]).toEqual(path.join(`public/guru`, `card0.yaml`)); expect(call0[1]).toMatchSnapshot(); - - expect(call1[0]).toEqual(path.join(`public/guru`, `card1.yaml`)); + expect(call1[0]).toEqual(path.join(`public/guru`, `card0.html`)); expect(call1[1]).toMatchSnapshot(); + + const call2 = fs.writeFile.mock.calls[2]; + const call3 = fs.writeFile.mock.calls[3]; + + expect(call2[0]).toEqual(path.join(`public/guru`, `card1.yaml`)); + expect(call2[1]).toMatchSnapshot(); + expect(call3[0]).toEqual(path.join(`public/guru`, `card1.html`)); + expect(call3[1]).toMatchSnapshot(); }); }); }); diff --git a/src/gatsby-node.js b/src/gatsby-node.js index d446d65..e6f7fa0 100755 --- a/src/gatsby-node.js +++ b/src/gatsby-node.js @@ -54,12 +54,17 @@ exports.onPostBuild = async ({ graphql }, pluginOptions) => { } return acc; }, {}) + const outputBody = outputData.Body; + delete outputData.Body; - const yamlResult = yaml.dump(outputData); - const fileName = `card${i}.yaml` - const outputFile = path.join(outputPath, fileName); + const outputYaml = yaml.dump(outputData); + const yamlFile = `card${i}.yaml` + const yamlOutputFile = path.join(outputPath, yamlFile); + await fs.writeFile(yamlOutputFile, outputYaml); - await fs.writeFile(outputFile, yamlResult); + const bodyFile = `card${i}.html` + const bodyOutputFile = path.join(outputPath, bodyFile); + await fs.writeFile(bodyOutputFile, outputBody); } });