Skip to content

Commit b9616f1

Browse files
committed
Added check to ensure linked Codepen file exists
1 parent 6fd0d79 commit b9616f1

File tree

1 file changed

+11
-0
lines changed
  • plugins/gatsby-remark-codepen-examples

1 file changed

+11
-0
lines changed

plugins/gatsby-remark-codepen-examples/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const {existsSync} = require('fs');
2+
const {join} = require('path');
13
const map = require('unist-util-map');
24

35
const DEFAULT_LINK_TEXT = 'Try it on CodePen';
@@ -15,6 +17,15 @@ module.exports = ({markdownAST}) => {
1517
const text =
1618
node.children.length === 0 ? DEFAULT_LINK_TEXT : node.children[0].value;
1719

20+
// Verify that the specified example file exists.
21+
const filePath = join(__dirname, `../../${href}.js`);
22+
if (!existsSync(filePath)) {
23+
console.log(
24+
`Invalid Codepen link specified; no such file "${filePath}"`,
25+
);
26+
process.exit(1);
27+
}
28+
1829
const anchorOpenNode = {
1930
type: 'html',
2031
value: `<a href="${href}" target="_blank">`,

0 commit comments

Comments
 (0)