-
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
Front matter in JS #439
Comments
Hey, components don't need wrappers. Just drop a component of whatever sort React component pages don't support front matter as you can just use JS
|
how would i export the variables that would normally go into front matter (title, date) so that they are available in other places like this? https://github.com/gatsbyjs/gatsby-starter-blog/blob/master/pages/index.js#L21 |
Oh... hmmm right. That'd require a change to Gatsby internals actually. This file is where the frontmatter is pulled off html/md files. To make this work, we'd need some sort of static way of exporting data from a component because as this is in node.js context, we can't just require the react component as often it'll have special webpack import/requires which would just blow up in Node.js Probably one of the JS parsers out there would make quick work of this. Support convention like: // In React.js page component
export const data = {
title: "It was a beautiful day",
date: "2016-09-12T13:52:59-07:00",
} Then pull that off each component and set it as You want to take this on? |
I think js pages must be wrapped in 'wrappers/js.js' too. import React from 'react';
const AboutComponent = (props) => (
<div className="about">
<p>Im Renato...</p>
</div>
);
export const data = {
// or AboutComponent.data = {
title: 'About me',
foo: 'bar'
};
export default AboutComponent; wrappers/js.js import React from 'react'
export default ({ route: { page: { data } } }) => {
// data.body = <AboutComponent />
return (
<div className="JSWrapper">
{data.body}
</div>
)
} |
See the code here for wrappers — react components are required directly and data files are "wrapped" gatsby/lib/isomorphic/create-routes.js Line 114 in 7a4c553
|
@KyleAMathews ill look into supporting It should be as easy as adding a new |
Yup! As per my TODO there I'd thought about using webpack-require but that's kinda slow/overkill for pulling off static data. Extra points if you support commonjs exports as well |
Just to be clear. Is this not related to this? It seems to me that it is but I could be misunderstanding |
@chiedo yes, that's on the same issue. Didn't get to this in the past obviously :-) |
Cool :) |
#591 closes this. |
Thanks @jbolda for adding this! Added a quick example of how this works on the starter blog |
Hey there, I would like to use pure React components to write my posts, but I would also like to have front matter for title/path/etc.
I tried writing a loader to do this, but the webpack
require.context
call inutils/load-context
always errors before I get the chance to parse and remove whatever I use to write the front matter.Do you have any suggestions on how I can accomplish this, or if it is already possible? Thanks!
The text was updated successfully, but these errors were encountered: