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-contentful): Support storing assets locally #10682

Merged

Conversation

polarathene
Copy link
Contributor

@polarathene polarathene commented Dec 27, 2018

Downloads and caches Contentful Assets to the local filesystem. Useful for reduced data usage or projects where you want the assets copied locally with builds for deploying without links to Contentful CDN.

Resolves #10587 #5919

Downloads and caches Contentful Assets to the local filesystem. Useful for reduced data usage or projects where you want the assets copied locally with builds for deploying without links to Contentful CDN.
Filename was updated to match naming convention, missed updating it's import statement in `gatsby-node.js`.
@polarathene polarathene force-pushed the topics/gatsby-source-contentful-download branch 2 times, most recently from 912c3f3 to 4a87047 Compare December 27, 2018 18:03
@polarathene polarathene force-pushed the topics/gatsby-source-contentful-download branch from 4a87047 to c24051d Compare December 27, 2018 18:06
@polarathene polarathene changed the title feat(gatsby-source-contentful): Support local assets feat(gatsby-source-contentful): Support storing assets locally Dec 27, 2018
@polarathene
Copy link
Contributor Author

ci/circleci: e2e_tests_path-prefix fails with:

 Production pathPrefix
    ✓ returns 200 on base route (529ms)
    navigation
      ✓ prefixes link with /blog (225ms)
      ✓ can navigate to secondary page (343ms)
      ✓ can navigate back from secondary page (303ms)
      1) can go back


  4 passing (12s)
  1 failing

I'm not sure what's causing that or how to fix it. Navigating my own project works fine. Any advice?

@DSchau
Copy link
Contributor

DSchau commented Dec 27, 2018

@polarathene don't worry about that e2e failure--it's unrelated.

I'll create an issue now so that we can track on it.

@DSchau
Copy link
Contributor

DSchau commented Dec 27, 2018

Whoops--I already did create that issue.

See #9233, but once more, unrelated to any changes here!

@polarathene
Copy link
Contributor Author

@DSchau @sidharthachatterjee Would either of you be happy to review and merge this then if the failing e2e test is nothing to worry about? :)

I'm not sure if it will work well if an asset is modified on Contentful, it might not invalidate the cache and either not update the asset locally or create a new file copying over old data while the cache hasn't been cleared? (I have mentioned this in the README.md)

The wordpress plugin uses a modified metadata value to handle this, Contentful isn't providing one for ContentfulAsset afaik, there is internal.contentDigest but I'm not sure if that's useful.

@wardpeet
Copy link
Contributor

wardpeet commented Feb 8, 2019

@polarathene just to make sure we won't have any regressions in the future could you add a few tests to test your cache invalidation code (https://github.com/gatsbyjs/gatsby/pull/10682/files#diff-caa2171e85ea277bf3075bd98f17c16eR51)?

@wardpeet wardpeet added type: feature or enhancement status: awaiting author response Additional information has been requested from the author labels Feb 8, 2019
@polarathene
Copy link
Contributor Author

@wardpeet I could try, but I've not really written much tests before.

It's been a while since I wrote this, I vaguely remember referencing some existing implementations(although I'm not sure that they had any testing in place either). Any advice(link to a similar test could suffice).

@wardpeet
Copy link
Contributor

wardpeet commented Mar 4, 2019

It's more or less testing your download function to make sure it's only called when options.localDownload is set and if the correct nodes are created correctly.

I have only found one package that tests sourceNodes https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-drupal/src/__tests__/index.js so I understand that this won't help you much as contentful doesn't have a lot of tests either. I don't want to burden you with this so if you're not up for it, no biggy.

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

LGTM! I'm going to test this one and I'll be merging afterwards

@wardpeet
Copy link
Contributor

Tested this on www.gatsbyjs.com and seems to work. Looks identical to https://www.gatsbyjs.org/docs/image-tutorial/ 👍

@wardpeet wardpeet merged commit 6d7bd76 into gatsbyjs:master Mar 15, 2019
@gatsbot
Copy link

gatsbot bot commented Mar 15, 2019

Holy buckets, @polarathene — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: awaiting author response Additional information has been requested from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants