diff --git a/README.md b/README.md index 0f967d4..2090d10 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,11 @@ The whole [portfolio](https://matthiaskretschmann.com) is a React-based Single P ### 💍 One data file to rule all pages -All content is powered by one YAML file where all the portfolio's projects are defined. The project description itself is transformed from Markdown written inside the YAML file. +All content is powered by one YAML file where all the portfolio's projects are defined. The project description itself is transformed from Markdown written inside the YAML file int HTML on build time. Gatsby automatically creates pages from each item in that file utilizing the [`Project.jsx`](src/templates/Project.jsx) template. +- [`gatsby-node.js`](gatsby-node.js) - [`data/projects.yml`](data/projects.yml) - [`src/templates/Project.jsx`](src/templates/Project.jsx) diff --git a/gatsby-node.js b/gatsby-node.js index f1345fd..92835c1 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,4 +1,36 @@ const path = require('path') +const remark = require('remark') +const markdown = require('remark-parse') +const html = require('remark-html') + +exports.onCreateNode = ({ node, actions }) => { + const { createNodeField } = actions + + // Projects YAML nodes + if (node.internal.type === 'ProjectsYaml') { + // Add transformed Markdown descriptions + const description = node.description + const descriptionWithLineBreaks = description.split('\n').join('\n\n') + + let descriptionHtml + + remark() + .use(markdown, { gfm: true, commonmark: true, pedantic: true }) + .use(html) + .process(descriptionWithLineBreaks, (err, file) => { + if (err) throw Error('Could not transform project description') + + descriptionHtml = file.contents + return descriptionHtml + }) + + createNodeField({ + node, + name: 'descriptionHtml', + value: descriptionHtml + }) + } +} // // Create project pages from projects.yml diff --git a/package.json b/package.json index bf47002..6a57b52 100644 --- a/package.json +++ b/package.json @@ -21,15 +21,15 @@ "new": "babel-node ./scripts/new.js" }, "dependencies": { - "file-saver": "^2.0.0-rc.4", - "gatsby": "^2.0.50", + "file-saver": "^2.0.0", + "gatsby": "^2.0.55", "gatsby-image": "^2.0.20", "gatsby-plugin-favicon": "^3.1.4", - "gatsby-plugin-matomo": "^0.5.0", - "gatsby-plugin-offline": "^2.0.15", + "gatsby-plugin-matomo": "^0.5.1", + "gatsby-plugin-offline": "^2.0.17", "gatsby-plugin-react-helmet": "^3.0.2", "gatsby-plugin-sass": "^2.0.4", - "gatsby-plugin-sharp": "^2.0.12", + "gatsby-plugin-sharp": "^2.0.13", "gatsby-plugin-sitemap": "^2.0.2", "gatsby-plugin-svgr": "^2.0.1", "gatsby-source-filesystem": "^2.0.8", @@ -44,8 +44,10 @@ "react": "^16.6.3", "react-dom": "^16.6.3", "react-helmet": "^5.2.0", - "react-markdown": "^4.0.3", "react-pose": "^4.0.2", + "remark": "^10.0.1", + "remark-html": "^9.0.0", + "remark-parse": "^6.0.3", "suncalc": "^1.8.0", "vcf": "^2.0.1" }, @@ -53,23 +55,23 @@ "@babel/core": "^7.1.6", "@babel/node": "^7.0.0", "@babel/preset-env": "^7.1.6", - "@svgr/webpack": "^4.0.3", + "@svgr/webpack": "^4.1.0", "ava": "^0.25.0", - "babel-eslint": "^10.0.0", + "babel-eslint": "^10.0.1", "chrome-launcher": "^0.10.5", - "eslint": "^5.8.0", - "eslint-config-prettier": "^3.1.0", - "eslint-loader": "^2.1.0", + "eslint": "^5.9.0", + "eslint-config-prettier": "^3.3.0", + "eslint-loader": "^2.1.1", "eslint-plugin-graphql": "^3.0.1", "eslint-plugin-prettier": "^3.0.0", "eslint-plugin-react": "^7.11.1", - "lighthouse": "^3.2.1", + "lighthouse": "^4.0.0-alpha.2-3.2.1", "ora": "^3.0.0", "prepend": "^1.0.2", "prettier": "^1.15.1", "prettier-stylelint": "^0.4.2", - "slugify": "^1.3.2", - "stylelint": "^9.7.1", + "slugify": "^1.3.3", + "stylelint": "^9.8.0", "stylelint-config-css-modules": "^1.3.0", "stylelint-config-standard": "^18.2.0", "why-did-you-update": "^1.0.6" diff --git a/src/components/Layout.jsx b/src/components/Layout.jsx index 93fd612..6ac1dd1 100644 --- a/src/components/Layout.jsx +++ b/src/components/Layout.jsx @@ -1,8 +1,8 @@ -import React, { PureComponent, Fragment } from 'react' +import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import posed, { PoseGroup } from 'react-pose' import { fadeIn } from './atoms/Transitions' -import Head from './molecules/Head' +import Typekit from './atoms/Typekit' import Header from './organisms/Header' import Footer from './organisms/Footer' import styles from './Layout.module.scss' @@ -27,8 +27,9 @@ export default class Layout extends PureComponent { const RoutesContainer = posed.div(fadeIn) return ( - - + <> + + {children} +