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

feat(gatsby-source-wordpress): use image cdn for non-resizable images in html (svgs/gifs mainly) #35529

Merged
merged 11 commits into from
May 4, 2022
Prev Previous commit
Next Next commit
remove dead code and update comments
  • Loading branch information
TylerBarnes committed Apr 30, 2022
commit 75a9c8c464087d0e560cd143604cd59bbbd076c5
Original file line number Diff line number Diff line change
@@ -160,8 +160,8 @@ const pickNodeBySourceUrlOrCheerioImg = ({
let displayedFailedToRestoreMessage = false

const fetchNodeHtmlImageMediaItemNodes = async ({
// node, // for inspecting nodes while debugging
cheerioImages,
node,
helpers,
wpUrl,
}) => {
@@ -414,26 +414,6 @@ const copyFileToStaticAndReturnUrlPath = async (fileNode, helpers) => {
return relativeUrl
}

const filterMatches =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function isn't being used anywhere 🤔 not sure why but it was dead code so I deleted it

wpUrl =>
({ match }) => {
const { hostname: wpHostname } = url.parse(wpUrl)

// @todo make it a plugin option to fetch non-wp images
// here we're filtering out image tags that don't contain our site url
const isHostedInWp =
// if it has the full WP url
match.includes(wpHostname) ||
// or it's an absolute path
match.includes(`src=\\"/wp-content`)

// six backslashes means we're looking for three backslashes
// since we're looking for JSON encoded strings inside of our JSON encoded string
const isInJSON = match.includes(`src=\\\\\\"`)

return isHostedInWp && !isInJSON
}

const cacheCreatedFileNodeBySrc = ({ node, src }) => {
if (node) {
// save any fetched media items in our global media item cache
@@ -576,7 +556,7 @@ export const replaceNodeHtmlImages = async ({
const configuredMaxWidth = pluginOptions?.html?.imageMaxWidth

// if the configured html.maxWidth property is less than the result, then
// override the resultant width
// override the resulting width
if (configuredMaxWidth && configuredMaxWidth < maxWidth) {
maxWidth = configuredMaxWidth
}