Skip to content

Commit

Permalink
[1.0] Make mediaType optional (#1299)
Browse files Browse the repository at this point in the history
* Make mediaType optional

* Fix tests

* more test fixing
  • Loading branch information
KyleAMathews committed Jun 29, 2017
1 parent 9f377dc commit e82dbed
Show file tree
Hide file tree
Showing 35 changed files with 158 additions and 319 deletions.
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
Loading

0 comments on commit e82dbed

Please sign in to comment.