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

Process Contentful images inlined in markdown #5542

Merged
merged 20 commits into from
Jun 12, 2018
Merged

Process Contentful images inlined in markdown #5542

merged 20 commits into from
Jun 12, 2018

Conversation

Khaledgarbaya
Copy link
Contributor

@Khaledgarbaya Khaledgarbaya commented May 24, 2018

Closes #1502

TODO :

  • Fix Tests
  • Add a show case page in using-contenful example
  • Add documentation
  • Handle configs

@gatsbybot
Copy link
Collaborator

gatsbybot commented May 24, 2018

Deploy preview for using-drupal ready!

Built with commit ea3ff23

https://deploy-preview-5542--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented May 24, 2018

Deploy preview for gatsbygram ready!

Built with commit ea3ff23

https://deploy-preview-5542--gatsbygram.netlify.com

@Khaledgarbaya Khaledgarbaya changed the title WIP: Process Contentful images inlined in markdown Process Contentful images inlined in markdown May 28, 2018
@Khaledgarbaya
Copy link
Contributor Author

Any reviewer?

@pieh pieh self-assigned this May 30, 2018
backgroundColor: `white`,
linkImagesToOriginal: true,
showCaptions: false,
pathPrefix,
Copy link
Contributor

Choose a reason for hiding this comment

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

linkImagesToOriginal, showCaptions and pathPrefix aren't really used anywhere? Or I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for some reason my changes were not pushed to the branch 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

method: `GET`,
url: `https:${node.url}`, // for some reason there is a './' prefix
responseType: `stream`,
})
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 it would be good idea to implement some sort of caching mechanism so we don't have to redownload images everytime

sqip plugin implemented this locally - https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-sqip/src/extend-node-type.js#L229-L248 - maybe this can be turned into utility that could be moved to main contentful plugin and exported from it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't actually download the entire file I just get the metadata from the first bits in the stream and then destroy it

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I've missed that, you are of course right. In any case we could cache metadata so we don't do same requests every build I think.

One way to do it is to pass cache helper utility here https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-remark/src/extend-node-type.js#L181-L188 and use that here - similar to what sqip plugin is doing - https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-sqip/src/generate-sqip.js#L38-L76 (just note that cache is not namespaced so, you would have to namespace used keys yourself.

If you are not sure how to use it just let me know - I can jump in and do this part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @pieh That would be nice but I think the gatsby-transfromer-remark is not passing the cache function to it's plugins.
Does it make sense to add a PR that does that ?

const rawHtmlNodes = select(markdownAST, `html`)

const generateImagesAndUpdateNode = async function(node, resolve) {
// Ingonre if it is not contentful image
Copy link
Contributor

@pieh pieh May 31, 2018

Choose a reason for hiding this comment

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

typo in "Ingonre" :)

node =>
new Promise(async (resolve, reject) => {
// Ignore gifs as we can't process them,
// svgs as they are already responsive by definition
Copy link
Contributor

Choose a reason for hiding this comment

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

are gifs and svgs actually ignored here? if so explanation that images.ctfassets.net isn't used for those would be helpful

@Khaledgarbaya
Copy link
Contributor Author

@pieh to be able to cache I added the ability to the gatsby-transformer-remark plugin to pass along the cache object to its children plugins.

@pieh
Copy link
Contributor

pieh commented Jun 7, 2018

@Khaledgarbaya Is this ready for another round of review?

@Khaledgarbaya
Copy link
Contributor Author

Hey @pieh yes this is ready for another round of review

@pieh
Copy link
Contributor

pieh commented Jun 8, 2018

I tried it locally and I couldn't get placeholder images to show - should we actually download those (maybe change from w=40 to w=20 there) and inline it using background-image: url('data:image/jpeg;base64,...')?

And I think we would have to split this into 2 PRs - one is adding gatsby-remark-images-contentful and changes in gatsby-transformer-remark to pass cache and second one are changes to example - we need to publish plugin first otherwise example will not work until we publish new package (I can handle that just before merging)

---edit:
Other stuff look great!

@Khaledgarbaya
Copy link
Contributor Author

Hey, @pieh that make sense. I will split this into 3 PRs

@Khaledgarbaya
Copy link
Contributor Author

@pieh this PR is ready for a review and once it's merged and released I will add the showcase page

@pieh
Copy link
Contributor

pieh commented Jun 12, 2018

I updated minor stuff - formatting and failing test (which I'm not super happy how it looks but it works) and I think this is good to go!

pieh
pieh previously approved these changes Jun 12, 2018
@pieh
Copy link
Contributor

pieh commented Jun 12, 2018

@Khaledgarbaya yeah, that's a lot nicer way for tests - do you want to add anything more here? If not I'll just fix formatting, rerun tests and merge this in! :)

@Khaledgarbaya
Copy link
Contributor Author

Khaledgarbaya commented Jun 12, 2018

@pieh all good here nothing to add from my side

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Thank You very much @Khaledgarbaya !

@pieh pieh merged commit 7dbfa3f into gatsbyjs:master Jun 12, 2018
@Khaledgarbaya Khaledgarbaya deleted the feat/markdown-contentful-images branch June 13, 2018 08:20
m-allanson added a commit that referenced this pull request Jun 14, 2018
* master: (26 commits)
  Publish
  [feat] Extract internal plugin for automatically creating pages so we can reuse for other directories (#4490)
  fix(contentful): properly delete deleted entries and assets (#5756)
  Fix typo
  add Linda's post (#5817)
  [gatsby-source-contentful] Fix prepareJSONNode for array normalization (#5107)
  Process Contentful images inlined in markdown (#5542)
  feat(contentful): add traced SVGs to Contentful images (#5659)
  [SQIP] Add documentation (#5287)
  Add site to showcase (#5819)
  [gatsby-remark-copy-linked-files] Support reference-style images (#5818)
  Update docs for gatsby-plugin-catch-links (#5843)
  Added ⋅ representing a space to sub-list examples to reflect actual code (#5829)
  Adding tigerfacilityservices.com to showcase (#5855)
  fix schema type conflict reporter regressions (#5805)
  [gatsby-plugin-feed] Support nested output directory (#5820)
  Make cache available to the plugins (#5840)
  [gatsby-source-contentful] update data and jest snapshots (#5802)
  [gatsby-plugin-manifest] Replace all manifest.json with manifest.webmanifest in comments/docs (#5157)
  Update deploy-gatsby.md (#5800)
  ...

# Conflicts:
#	docs/tutorial/part-one/index.md
#	examples/using-sqip/src/components/polaroid.js
#	packages/gatsby-image/README.md
#	packages/gatsby-image/package.json
#	packages/gatsby-plugin-catch-links/package.json
#	packages/gatsby-plugin-feed/package.json
#	packages/gatsby-plugin-manifest/package.json
#	packages/gatsby-plugin-page-creator/src/gatsby-node.js
#	packages/gatsby-remark-copy-linked-files/package.json
#	packages/gatsby-source-contentful/package.json
#	packages/gatsby-source-contentful/src/__tests__/__snapshots__/normalize.js.snap
#	packages/gatsby-source-contentful/src/extend-node-type.js
#	packages/gatsby-source-contentful/src/gatsby-node.js
#	packages/gatsby-source-contentful/src/normalize.js
#	packages/gatsby-transformer-remark/package.json
#	packages/gatsby-transformer-remark/src/__tests__/__snapshots__/gatsby-node.js.snap
#	packages/gatsby-transformer-sqip/package.json
#	packages/gatsby-transformer-sqip/src/extend-node-type.js
#	packages/gatsby/package.json
#	packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.js.snap
#	packages/gatsby/src/bootstrap/load-plugins/load.js
#	www/src/data/sites.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants