Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Add plugin option search and replace #129

Closed
wants to merge 11 commits into from
Closed

Add plugin option search and replace #129

wants to merge 11 commits into from

Conversation

philippmunzert
Copy link

Hi 👋 ,

during my upgrade gatsby-source-wordpress-experimental I missed the search and replace option from the previous version. We use this for example to replace our basic Wordpress URL with a CDN URL to serve the images from there. So with this PR I added the option to the new plugin version as well.

This solves #95.

Philipp Munzert added 2 commits October 19, 2020 10:55
# Conflicts:
#	src/steps/source-nodes/create-nodes/process-node.js
@acao
Copy link
Contributor

acao commented Nov 13, 2020

so you're referring to this functionality in the old source plugin, correct?

// Search and Replace Urls across WordPress content.
searchAndReplaceContentUrls: {
  sourceUrl: "https://source-url.com",
  replacementUrl: "https://replacement-url.com",
},

I like how your implementation expands on this

@@ -799,6 +799,35 @@ const replaceNodeHtmlLinks = ({ wpUrl, nodeString, node }) => {
return nodeString
}

// replaces specific string with a given string from the plugin options config
const findAndReplaceNodeHtmlString = ({ nodeString, node, pluginOptions }) => {
if (pluginOptions?.findAndReplace?.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be looking for pluginOptions?.searchAndReplace according to the docs.

also, this would be a great place to check Array.isArray(pluginOptions?.searchAndReplace). However, now that we have plugin options validation, duck typing checks like these won't be as important

Copy link
Contributor

@acao acao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking awesome all around. Do you mind if we finish it up for you?

Let's just make sure the plugin option names and doc names match up, and what's more, we just added plugin option validation, so when you pull in the upstream you can add joi validation for this option as well!

@philippmunzert
Copy link
Author

@acao thanks for the review. Add the suggested change. But to be honest I never worked with this joi validation. Do you have any tips here?

@munyah
Copy link

munyah commented Mar 10, 2021

erm, sorry, excuse the interruption, what happened to this feature @philmuze?

@TylerBarnes
Copy link
Collaborator

Sorry @philmuze and @munyah this PR slipped between the cracks during some internal changes at Gatsby. If you're able to open this PR on the Gatsby repo for gatsby-source-wordpress I'm happy to review/merge it. Thanks everyone!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants