Skip to content

Commit

Permalink
oops - added exporting of body to html file
Browse files Browse the repository at this point in the history
  • Loading branch information
seankovacs committed Apr 29, 2021
1 parent 04aa49b commit e44398f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"bugs": {
"url": "https://github.com/calendly/gatsby-plugin-guru-export"
Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/__snapshots__/gatsby-node.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `"<div>test</div>"`;

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`] = `"<div>test</div>"`;
21 changes: 16 additions & 5 deletions src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describe("gatsby-plugin-guru-export", () => {
id: 1,
title: "sample title",
description: "sample description",
slug: 'sample1'
slug: 'sample1',
htmlBody: '<div>test</div>'
},
},
},
Expand All @@ -42,7 +43,8 @@ describe("gatsby-plugin-guru-export", () => {
id: 2,
title: "sample title 2",
description: "sample description 2",
slug: 'sample2'
slug: 'sample2',
htmlBody: '<div>test</div>'
},
},
},
Expand All @@ -62,6 +64,7 @@ describe("gatsby-plugin-guru-export", () => {
title
description
slug
htmlBody
}
}
}
Expand All @@ -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();
});
});
});
13 changes: 9 additions & 4 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit e44398f

Please sign in to comment.