Skip to content

Commit

Permalink
make option more explicit, updated default value & removed redundant …
Browse files Browse the repository at this point in the history
…logging
  • Loading branch information
David Hewitt committed Jan 13, 2018
1 parent 4d2e510 commit 829b1f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-source-wordpress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ plugins: [
// It can help you debug specific API Endpoints problems
verboseOutput: false,
// Search and Replace Urls across WordPress content
searchReplace: {
searchAndReplaceURLs: {
sourceUrl: "https://source-url.com",
replacementUrl: "https://replacement-url.com"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-source-wordpress/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports.sourceNodes = async (
auth = {},
verboseOutput,
perPage = 100,
searchReplace = [],
searchAndReplaceURLs = {},
}
) => {
const { createNode } = boundActionCreators
Expand Down Expand Up @@ -96,7 +96,7 @@ exports.sourceNodes = async (
// Search and replace Content Urls
entities = normalize.searchReplaceContentUrls({
entities,
searchReplace,
searchAndReplaceURLs,
})

// creates nodes for each entry
Expand Down
20 changes: 7 additions & 13 deletions packages/gatsby-source-wordpress/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,19 @@ exports.mapTagsCategoriesToTaxonomies = entities =>
return e
})

exports.searchReplaceContentUrls = function ({ entities, searchReplace }) {
exports.searchReplaceContentUrls = function ({ entities, searchAndReplaceURLs }) {

if (
!(_.isPlainObject(searchReplace)) ||
!(_.has(searchReplace, `sourceUrl`)) ||
!(_.has(searchReplace, `replacementUrl`)) ||
typeof searchReplace.sourceUrl !== `string` ||
typeof searchReplace.replacementUrl !== `string`
!(_.isPlainObject(searchAndReplaceURLs)) ||
!(_.has(searchAndReplaceURLs, `sourceUrl`)) ||
!(_.has(searchAndReplaceURLs, `replacementUrl`)) ||
typeof searchAndReplaceURLs.sourceUrl !== `string` ||
typeof searchAndReplaceURLs.replacementUrl !== `string`
) {
console.log(
colorized.out(
`Invalid Search and Replace option`,
colorized.color.Font.FgRed
)
)
return entities
}

const { sourceUrl, replacementUrl } = searchReplace
const { sourceUrl, replacementUrl } = searchAndReplaceURLs

const _blacklist = [
`_links`,
Expand Down

0 comments on commit 829b1f2

Please sign in to comment.