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

fix(gatsby-source-wordpress): image fixes #29813

Merged
merged 5 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/gatsby-source-wordpress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@rematch/core": "^1.3.0",
"@rematch/immer": "^1.2.0",
"async-retry": "^1.3.1",
"progress": "2.0.3",
"atob": "^2.1.2",
"axios": "^0.21.1",
"axios-rate-limit": "^1.3.0",
Expand All @@ -31,7 +32,7 @@
"gatsby-core-utils": "^2.1.0-next.1",
"gatsby-image": "^3.1.0-next.1",
"gatsby-plugin-catch-links": "^3.1.0-next.1",
"gatsby-source-filesystem": "^3.1.0-next.1",
"gatsby-source-filesystem": "2.11.1",
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
"glob": "^7.1.6",
"got": "^11.7.0",
"graphql-query-compress": "^1.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const buildGatsbyNodeObjectResolver = ({ field, fieldName }) => async (
schema: { typePrefix: prefix },
} = getPluginOptions()

if (!existingNode.__typename.startsWith(prefix)) {
if (existingNode?.__typename && !existingNode.__typename.startsWith(prefix)) {
existingNode.__typename = buildTypeName(existingNode.__typename)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
exports.__esModule = true
exports.getRemoteFileExtension = getRemoteFileExtension
exports.getRemoteFileName = getRemoteFileName
exports.createProgress = createProgress
exports.createFilePath = createFilePath

const path = require(`path`)

const Url = require(`url`)

const ProgressBar = require(`progress`)
/**
* getParsedPath
* --
* Parses remote url to a path object
*
*
* @param {String} url
* @return {Object} path
*/

function getParsedPath(url) {
return path.parse(Url.parse(url).pathname)
}
/**
* getRemoteFileExtension
* --
* Parses remote url to retrieve remote file extension
*
*
* @param {String} url
* @return {String} extension
*/

function getRemoteFileExtension(url) {
return getParsedPath(url).ext
}
/**
* getRemoteFileName
* --
* Parses remote url to retrieve remote file name
*
*
* @param {String} url
* @return {String} filename
*/

function getRemoteFileName(url) {
return getParsedPath(url).name
} // TODO remove in V3

function createProgress(message, reporter) {
if (reporter && reporter.createProgress) {
return reporter.createProgress(message)
}

const bar = new ProgressBar(
` [:bar] :current/:total :elapsed s :percent ${message}`,
{
total: 0,
width: 30,
clear: true,
}
)
return {
start() {},

tick() {
bar.tick()
},

done() {},

set total(value) {
bar.total = value
},
}
}
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
/**
* createFilePath
* --
*
* @param {String} directory
* @param {String} filename
* @param {String} ext
* @return {String}
*/

function createFilePath(directory, filename, ext) {
return path.join(directory, `${filename}${ext}`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { isWebUri } = require(`valid-url`)
const Queue = require(`better-queue`)
const readChunk = require(`read-chunk`)
const fileType = require(`file-type`)
const { createProgress } = require(`gatsby-source-filesystem/utils`)
const { createProgress } = require(`./create-progress`)

const { createFileNode } = require(`gatsby-source-filesystem/create-file-node`)
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export const errorPanicker = ({
)
)
reporter.panic(error)
} else {
console.error(error)
reporter.panic()
Comment on lines +142 to +143
Copy link
Contributor

Choose a reason for hiding this comment

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

What's wrong with panicking with an error?

Suggested change
console.error(error)
reporter.panic()
reporter.panic(error)

Copy link
Contributor Author

@TylerBarnes TylerBarnes Mar 1, 2021

Choose a reason for hiding this comment

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

reporter.panic() is broken right now - this will result in Gatsby logging "There was an error" and quitting with no additional info https://gatsby.canny.io/ideas/p/reporterpanic-is-broken

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,11 @@ const replaceNodeHtmlLinks = ({ wpUrl, nodeString, node }) => {
const normalizedPath = path.replace(/\\/g, ``)

// replace normalized match with relative path
const thisMatchRegex = new RegExp(normalizedMatch, `g`)
const thisMatchRegex = new RegExp(
normalizedMatch + `(?!/?wp-content|/?wp-admin|/?wp-includes)`,
`g`
)

nodeString = nodeString.replace(thisMatchRegex, normalizedPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's always helpful to add a comment with an example of what this converts into

} catch (e) {
console.error(e)
Expand Down
34 changes: 33 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13177,6 +13177,19 @@ gather-stream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/gather-stream/-/gather-stream-1.0.0.tgz#b33994af457a8115700d410f317733cbe7a0904b"

gatsby-core-utils@^1.10.1:
version "1.10.1"
resolved "https://registry.yarnpkg.com/gatsby-core-utils/-/gatsby-core-utils-1.10.1.tgz#97bed40df3fa79800e7ce0c0491680f0aadd6ce7"
integrity sha512-4P3feGCJckg+DRWWl2beFk7N9c63zmCryEGPaU1OHCp+ZT2bO0ihCBuXywDWuuEp6SYP9PZ1fs0YJ/Rt6q6lag==
dependencies:
ci-info "2.0.0"
configstore "^5.0.1"
fs-extra "^8.1.0"
node-object-hash "^2.0.0"
proper-lockfile "^4.1.1"
tmp "^0.2.1"
xdg-basedir "^4.0.0"

gatsby-design-tokens@^2.0.2:
version "2.0.13"
resolved "https://registry.yarnpkg.com/gatsby-design-tokens/-/gatsby-design-tokens-2.0.13.tgz#33f5fa84a399b821ae224b9921847d7b37c45600"
Expand Down Expand Up @@ -13227,6 +13240,25 @@ gatsby-plugin-webfonts@^1.1.4:
postcss "^8.2.2"
postcss-js "^3.0.3"

gatsby-source-filesystem@2.11.1:
version "2.11.1"
resolved "https://registry.yarnpkg.com/gatsby-source-filesystem/-/gatsby-source-filesystem-2.11.1.tgz#c90f49c096c4bdafd8e68462966b3a6e21fd746b"
integrity sha512-Ao526Mmhm8KkF+0Tvf9Le5kKnqX7kgC1wecp82BW2KLQgdtG7UIgmHvG6PkjuFNiJ2ghXPC3vRK3J/vDPyLtkA==
dependencies:
"@babel/runtime" "^7.12.5"
better-queue "^3.8.10"
chokidar "^3.4.3"
file-type "^16.0.0"
fs-extra "^8.1.0"
gatsby-core-utils "^1.10.1"
got "^9.6.0"
md5-file "^5.0.0"
mime "^2.4.6"
pretty-bytes "^5.4.1"
progress "^2.0.3"
valid-url "^1.0.9"
xstate "^4.14.0"

gauge@~2.7.3:
version "2.7.4"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
Expand Down Expand Up @@ -21544,7 +21576,7 @@ process@~0.5.1:
version "0.5.2"
resolved "https://registry.yarnpkg.com/process/-/process-0.5.2.tgz#1638d8a8e34c2f440a91db95ab9aeb677fc185cf"

progress@^2.0.0, progress@^2.0.1, progress@^2.0.3:
progress@2.0.3, progress@^2.0.0, progress@^2.0.1, progress@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"

Expand Down