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

[1.0] Make mediaType optional #1299

Merged
merged 3 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make mediaType optional
  • Loading branch information
KyleAMathews committed Jun 29, 2017
commit e199f1f7555f0357dd2f2c0941faccb298d7fe0a
5 changes: 4 additions & 1 deletion docs/docs/node-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ parent: String,
fields: Object,
internal: {
contentDigest: String,
// Optional media type (https://en.wikipedia.org/wiki/Media_type) to indicate
// to transformer plugins this node has data they can futher process.
mediaType: String,
// A globally unique node type choosen by the plugin owner.
type: String,
// The plugin which created this node.
owner: String,
// Stores which plugins created which fields.
fieldOwners: Object,
// Raw content for this node.
// Optional field exposing the raw content for this node
// that transformer plugins can take and further process.
content: String,
}
...other node type specific fields
Expand Down
4 changes: 2 additions & 2 deletions examples/image-processing/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ export const pageQuery = graphql`
}
sizes: imageSharp(id: { regex: "/fecolormatrix-kanye-west.jpg/" }) {
responsiveSizes(
duotone: { highlight: "#f00e2e", shadow: "#192550" },
toFormat: PNG,
duotone: { highlight: "#f00e2e", shadow: "#192550" }
toFormat: PNG
) {
base64
aspectRatio
Expand Down
6 changes: 3 additions & 3 deletions examples/using-remark/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export const pageQuery = graphql`
}
}
allMarkdownRemark(
limit: 2000,
sort: { fields: [frontmatter___date], order: DESC },
filter: { frontmatter: { draft: { ne: true } } },
limit: 2000
sort: { fields: [frontmatter___date], order: DESC }
filter: { frontmatter: { draft: { ne: true } } }
) {
edges {
node {
Expand Down
4 changes: 2 additions & 2 deletions examples/using-remark/src/pages/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const pageQuery = graphql`
}
}
allMarkdownRemark(
limit: 2000,
filter: { frontmatter: { draft: { ne: true } } },
limit: 2000
filter: { frontmatter: { draft: { ne: true } } }
) {
group(field: frontmatter___tags) {
fieldValue
Expand Down
8 changes: 4 additions & 4 deletions examples/using-remark/src/templates/template-blog-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ export const pageQuery = graphql`
children {
... on ImageSharp {
responsiveResolution(
width: 50,
height: 50,
quality: 75,
grayscale: true,
width: 50
height: 50
quality: 75
grayscale: true
) {
src
srcSet
Expand Down
6 changes: 3 additions & 3 deletions examples/using-remark/src/templates/template-tag-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export default TagRoute
export const pageQuery = graphql`
query TagPage($tag: String) {
allMarkdownRemark(
limit: 1000,
sort: { fields: [frontmatter___date], order: DESC },
filter: { frontmatter: { tags: { in: [$tag] }, draft: { ne: true } } },
limit: 1000
sort: { fields: [frontmatter___date], order: DESC }
filter: { frontmatter: { tags: { in: [$tag] }, draft: { ne: true } } }
) {
totalCount
edges {
Expand Down
14 changes: 7 additions & 7 deletions packages/gatsby-remark-copy-linked-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const isRelativeUrl = require(`is-relative-url`)
const fsExtra = require(`fs-extra`)
const path = require(`path`)
const _ = require(`lodash`)
const $ = require('cheerio');
const $ = require(`cheerio`)

module.exports = ({ files, markdownNode, markdownAST, getNode }) => {
// Copy linked files to the public directory and modify the AST to point to
Expand Down Expand Up @@ -63,14 +63,14 @@ module.exports = ({ files, markdownNode, markdownAST, getNode }) => {
visitor(image)
}
})

// Same as the above except it only works for html img tags
visit(markdownAST, `html`, node => {
if(node.value.startsWith('<img')){
let image = Object.assign(node, $.parseHTML(node.value)[0].attribs);
image.url = image.src;
image.type = 'image';
image.position = node.position;
if (node.value.startsWith(`<img`)) {
let image = Object.assign(node, $.parseHTML(node.value)[0].attribs)
image.url = image.src
image.type = `image`
image.position = node.position

const imagePath = path.join(getNode(markdownNode.parent).dir, image.url)
const imageNode = _.find(files, file => {
Expand Down
25 changes: 13 additions & 12 deletions packages/gatsby-remark-responsive-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const isRelativeUrl = require(`is-relative-url`)
const _ = require(`lodash`)
const { responsiveSizes } = require(`gatsby-plugin-sharp`)
const Promise = require(`bluebird`)
const $ = require('cheerio');
const $ = require(`cheerio`)

// If the image is relative (not hosted elsewhere)
// 1. Find the image file
Expand All @@ -23,22 +23,23 @@ module.exports = (
}

const options = _.defaults(pluginOptions, defaults)

// This will only work for markdown syntax image tags
const imageNodes = select(markdownAST, 'image');
const imageNodes = select(markdownAST, `image`)

// This will also allow the use of html image tags
const rawHtmlImageNodes = select(markdownAST, 'html').filter((node) => {
return node.value.startsWith('<img');
});
const rawHtmlImageNodes = select(markdownAST, `html`).filter(node => node.value.startsWith(`<img`))

for(let node of rawHtmlImageNodes) {
let formattedImgTag = Object.assign(node, $.parseHTML(node.value)[0].attribs);
formattedImgTag.url = formattedImgTag.src;
formattedImgTag.type = 'image';
formattedImgTag.position = node.position;
for (let node of rawHtmlImageNodes) {
let formattedImgTag = Object.assign(
node,
$.parseHTML(node.value)[0].attribs
)
formattedImgTag.url = formattedImgTag.src
formattedImgTag.type = `image`
formattedImgTag.position = node.position

imageNodes.push(formattedImgTag);
imageNodes.push(formattedImgTag)
}

return Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ describe(`Fix contentful IDs`, () => {

describe(`Gets field value based on current locale`, () => {
const field = {
de: "Playsam Streamliner Klassisches Auto, Espresso",
"en-US": "Playsam Streamliner Classic Car, Espresso",
de: `Playsam Streamliner Klassisches Auto, Espresso`,
"en-US": `Playsam Streamliner Classic Car, Espresso`,
}
it(`Gets the specified locale`, () => {
expect(
Expand Down
3 changes: 0 additions & 3 deletions packages/gatsby-source-contentful/src/process-api-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ exports.createContentTypeNodes = ({
children: [],
internal: {
type: `${makeTypeName(contentTypeItemId)}`,
mediaType: `application/x-contentful`,
},
}

Expand Down Expand Up @@ -315,7 +314,6 @@ exports.createContentTypeNodes = ({
description: contentTypeItem.description,
internal: {
type: `${makeTypeName(`ContentType`)}`,
mediaType: `text/x-contentful`,
},
}

Expand Down Expand Up @@ -362,7 +360,6 @@ exports.createAssetNodes = ({
node_locale: locale.code,
internal: {
type: `${makeTypeName(`Asset`)}`,
mediaType: `text/x-contentful`,
},
}

Expand Down
4 changes: 0 additions & 4 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ exports.sourceNodes = async (
internal: {
...node.internal,
type: makeTypeName(node.internal.type),
content: nodeStr,
mediaType: `application/json`,
},
author___NODE: result.data.data[i].relationships.uid.data.id,
}
Expand Down Expand Up @@ -120,8 +118,6 @@ exports.sourceNodes = async (
parent: `__SOURCE__`,
internal: {
type: makeTypeName(user.internal.type),
content: userStr,
mediaType: `application/json`,
},
}

Expand Down
2 changes: 0 additions & 2 deletions packages/gatsby-source-hacker-news/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ fragment commentsFragment on HackerNewsItem {
content: storyStr,
internal: {
type: `HNStory`,
mediaType: `application/json`,
},
domain,
order: i + 1,
Expand Down Expand Up @@ -136,7 +135,6 @@ fragment commentsFragment on HackerNewsItem {
parent,
internal: {
type: `HNComment`,
mediaType: `application/json`,
},
order: i + 1,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ exports.onCreateNode = async ({
children: [],
internal: {
contentDigest: digest(strContent),
content: strContent,
type: `DocumentationJs`,
mediaType: `text/x-javascript-metadata`,
},
}

Expand Down
Loading