From b9616f1bdf45df70d5dfd8980a080e47290e9685 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 6 Nov 2017 23:23:45 +0000 Subject: [PATCH] Added check to ensure linked Codepen file exists --- plugins/gatsby-remark-codepen-examples/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/gatsby-remark-codepen-examples/index.js b/plugins/gatsby-remark-codepen-examples/index.js index f00fb76b..e5e1ee6c 100644 --- a/plugins/gatsby-remark-codepen-examples/index.js +++ b/plugins/gatsby-remark-codepen-examples/index.js @@ -1,3 +1,5 @@ +const {existsSync} = require('fs'); +const {join} = require('path'); const map = require('unist-util-map'); const DEFAULT_LINK_TEXT = 'Try it on CodePen'; @@ -15,6 +17,15 @@ module.exports = ({markdownAST}) => { const text = node.children.length === 0 ? DEFAULT_LINK_TEXT : node.children[0].value; + // Verify that the specified example file exists. + const filePath = join(__dirname, `../../${href}.js`); + if (!existsSync(filePath)) { + console.log( + `Invalid Codepen link specified; no such file "${filePath}"`, + ); + process.exit(1); + } + const anchorOpenNode = { type: 'html', value: ``,