Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelist page types + add image loader #357

Merged
merged 6 commits into from
Jul 20, 2016
Prev Previous commit
Next Next commit
Only require file types that Gatsby designates as possible pages
  • Loading branch information
KyleAMathews committed Jul 19, 2016
commit 78f2b429549371783d66a3f7b0283685efa9d8e1
1 change: 1 addition & 0 deletions lib/isomorphic/create-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = (files, pagesReq) => {

const staticFileTypes = [
'md',
'markdown',
'html',
'json',
'yaml',
Expand Down
17 changes: 3 additions & 14 deletions lib/utils/glob-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@ import glob from 'glob'
import buildPage from './build-page'
const debug = require('debug')('gatsby:glob')

import pageFileTypes from './page-file-types'

function globQuery (directory) {
// Make this list easy to modify through the config?
// Or just keep adding extensions...?
const fileTypesToGlob = [
'coffee',
'cjsx',
'jsx',
'js',
'md',
'html',
'json',
'yaml',
'toml',
]
const fileGlobQuery = fileTypesToGlob.map((type) => `*.${type}`)
const fileGlobQuery = pageFileTypes.map((type) => `*.${type}`)
const joinedFileQuery = fileGlobQuery.join('|')
return `${directory}/pages/**/?(${joinedFileQuery})`
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/load-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// This file is auto-written and used by Gatsby to require
// files from your pages directory.
module.exports = function (callback) {
let context = require.context('./pages', true)
let context = require.context('./pages', true, /(coffee|cjsx|jsx|js|markdown|md|html|json|yaml|toml)$/)
if (module.hot) {
module.hot.accept(context.id, () => {
context = require.context('./pages', true)
context = require.context('./pages', true, /(coffee|cjsx|jsx|js|markdown|md|html|json|yaml|toml)$/)
return callback(context)
})
}
Expand Down
14 changes: 14 additions & 0 deletions lib/utils/page-file-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const pageFileTypes = [
'coffee',
'cjsx',
'jsx',
'js',
'markdown',
'md',
'html',
'json',
'yaml',
'toml',
]

export default pageFileTypes