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

[gatsby-source-medium] Add Medium Source #1907

Merged
merged 7 commits into from
Sep 4, 2017
Merged

[gatsby-source-medium] Add Medium Source #1907

merged 7 commits into from
Sep 4, 2017

Conversation

deniaz
Copy link
Contributor

@deniaz deniaz commented Aug 24, 2017

Hey again ;)

We wanted to display our latest Medium stories on our company website and wrote a small plugin to pull in the data.

Does it make sense to merge this into your repo or shall we just publish it regularly with npm?

Your call!

Cheers,
Rob

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

This is fantastic! Happy to host in here in the monorepo. Didn't know about the JSON API. This looks much nicer than their other APIs :-)

Could you also put together a little example site as well? That'd be really helpful to both test this source plugin going further + also help people get started using it.

parent: `__SOURCE__`,
children: [],
internal: {
mediaType: `application/json`,
Copy link
Contributor

Choose a reason for hiding this comment

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

mediaType isn't needed unless the node content can be transformed into something else e.g. text/x-markdown. In these cases, the mediaType is a signal to transformer plugins that they can transform the node.

internal: {
mediaType: `application/json`,
type: `Medium${resource.type}`,
content: resource.title ? resource.title : resource.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with content — not necessary unless the node can be transformed. Sorry this isn't more obvious! Source plugin docs are very much a WIP still.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries. If this helps seeing what the docs lack, even better ;)

@gatsbybot
Copy link
Collaborator

gatsbybot commented Aug 24, 2017

Deploy preview ready!

Built with commit 63e3e674baea1178475dce51412040b48704ab66

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

@gatsbybot
Copy link
Collaborator

gatsbybot commented Aug 24, 2017

Deploy preview ready!

Built with commit fb154c1

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

// In your gatsby-config.js
plugins: [
{
resolve: `gatsby-source-hacker-news`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be gatsby-source-medium?


## Install

`npm install --save gatsby-source-medium`
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary once it is part of gatsby :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It still is, though ;) This is a lerna - so all packages live in the same repository, but are distributed as individual npm packages.

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Aug 24, 2017

Deploy preview failed.

Built with commit 72f15415fe0536ddd081b728725e078fd41ca551

https://app.netlify.com/sites/using-glamor/deploys/59a8b1cd6f4c50251f2ed8e3

resources.map(resource => {
const digest = crypto.createHash(`md5`).update(JSON.stringify(resource)).digest(`hex`)

const node = Object.assign(resource, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh something else that'd be fantastic would be to link posts and users. So that way you could query for users and also then query for their posts and vice versa.

The syntax isn't well-documented but basically to create a link you add a field like authors___NODE: ["id1", "id2", "id3"] where authors will be the eventual field name (the "___NODE" is stripped) and the array of IDs is the linked user ids who are authors.

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'd love to implement this, but honestly, I don't quite get it.

So on resources with type MediumPost I'll add a topleve field author__NODE (not inside internal) which basically has the same content as resource.creatorId (Medium User ID) which then magically links to MediumUser? I tried that but I'm not sure how to verify whether this works. Should I be able to query:

{
  allMediumPost {
    edges {
      node {
        id
      }
      author {}
    }
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, the author___NODE field should have as its value the "id" of the MediumUser. Then you'll be able to query attributes off the MediumUser node.

@@ -0,0 +1,56 @@
# gatsby-source-medium

Source plugin for pulling data into Gatsby from unofficial Medium JSON endpoints.
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh hmmm… just looked at the JSON output and it only sends previews back? https://medium.com/webpack/latest?format=json

That changes things… this should be emphasized then in the README so as not to give the wrong impression.

@erlend-sh
Copy link

This sounds fantastic! So what will happen if I make a link from one Medium article to another? Will Gatsby be able to translate those from links like these:

https://medium.com/@myusername/how-i-went-from-x-to-y-45abcabcabcabc

to links like these?

gatsbyblog.example.com/how-i-went-from-x-to-y

@KyleAMathews
Copy link
Contributor

@erlend-sh that'd be nifty! But I think since the Medium only gives you an excerpt of the article, keeping the links pointed at the original Medium URLs makes the most sense.

@KyleAMathews
Copy link
Contributor

See how they're using the plugin on their company site https://smartive.ch/

@deniaz
Copy link
Contributor Author

deniaz commented Aug 28, 2017

Hey @KyleAMathews

About the example site. All other examples load the plugins from the npm packages, but for this you'd need to release first. Should I add it as a local plugin in the example and then create a new pull request after a release?

@deniaz
Copy link
Contributor Author

deniaz commented Aug 28, 2017

@KyleAMathews @erlend-sh That would be very nice indeed, and not even that hard to implement from my point of view. As Kyle mentioned it's questionable to do this with this plugin since we don't get the full Medium articles from the endpoint.

@KyleAMathews
Copy link
Contributor

Re the example site. If you use gatsby-dev-cli you can develop the site using the still unpublished plugin by just adding the package to the sites package.json. But it is a bit clunky I agree. It might be easier yeah to just copy the plugin to be a local plugin while developing.

@deniaz
Copy link
Contributor Author

deniaz commented Sep 4, 2017

Hey @KyleAMathews

Sooo I've finally managed to add the GraphQL links between Posts and Users and added a simple example site.

What else do you think is needed to get this one merged? (Apart from your requested changes which I've implemented but have no idea about how to resolve that now...)

Cheers,
Rob

@KyleAMathews
Copy link
Contributor

Awesome! Everything looks really good! Merging and publishing now 🎉

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.

5 participants