-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Conversation
There was a problem hiding this 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`, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ;)
Deploy preview ready! Built with commit 63e3e674baea1178475dce51412040b48704ab66 |
Deploy preview ready! Built with commit fb154c1 |
// In your gatsby-config.js | ||
plugins: [ | ||
{ | ||
resolve: `gatsby-source-hacker-news`, |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
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, { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 {}
}
}
}
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
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:
to links like these?
|
@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. |
See how they're using the plugin on their company site https://smartive.ch/ |
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? |
@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. |
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. |
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, |
Awesome! Everything looks really good! Merging and publishing now 🎉 |
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