From 7ac3f17aa7b704c7b5ea48ebf498953fcfa4d9d4 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 21 Sep 2017 08:49:42 -0700 Subject: [PATCH] Fixed blog.html redirect --- www/gatsby-config.js | 1 + www/gatsby-node.js | 14 +++++---- www/package.json | 1 + www/src/pages/blog.html.js | 54 -------------------------------- www/yarn.lock | 63 +++++++++++++++++++++++++++++++------- 5 files changed, 62 insertions(+), 71 deletions(-) delete mode 100644 www/src/pages/blog.html.js diff --git a/www/gatsby-config.js b/www/gatsby-config.js index 7230eb816ce4f..b6b02c35283ae 100644 --- a/www/gatsby-config.js +++ b/www/gatsby-config.js @@ -20,6 +20,7 @@ module.exports = { }, plugins: [ 'gatsby-transformer-authors-yaml', + 'gatsby-plugin-netlify', 'gatsby-plugin-glamor', 'gatsby-plugin-react-next', { diff --git a/www/gatsby-node.js b/www/gatsby-node.js index 4542a066ed289..7e4aaa71f4173 100644 --- a/www/gatsby-node.js +++ b/www/gatsby-node.js @@ -28,7 +28,7 @@ exports.modifyWebpackConfig = ({ config, stage }) => { }; exports.createPages = async ({graphql, boundActionCreators}) => { - const {createPage} = boundActionCreators; + const {createPage, createRedirect} = boundActionCreators; const blogTemplate = resolve('./src/templates/blog.js'); const communityTemplate = resolve('./src/templates/community.js'); @@ -129,10 +129,7 @@ exports.createPages = async ({graphql, boundActionCreators}) => { } }); - /* TODO Register '/blog.html' redirect to most recent blog entry. - * And delete redundant 'pages/blog.html.js' - * github.com/gatsbyjs/gatsby/pull/1068 - const mostRecentBlogMarkdown = await graphql(` + const newestBlogEntry = await graphql(` { allMarkdownRemark( limit: 1, @@ -149,7 +146,12 @@ exports.createPages = async ({graphql, boundActionCreators}) => { } } `); - */ + + // Blog landing page should always show the most recent blog entry. + createRedirect({ + fromPath: '/blog.html', + toPath: newestBlogEntry.data.allMarkdownRemark.edges[0].node.fields.slug + }); }; // Parse date information out of blog post filename. diff --git a/www/package.json b/www/package.json index 61278b1914e3e..49608b7f55ed8 100644 --- a/www/package.json +++ b/www/package.json @@ -11,6 +11,7 @@ "gatsby-plugin-glamor": "^1.6.4", "gatsby-plugin-google-analytics": "^1.0.4", "gatsby-plugin-manifest": "^1.0.4", + "gatsby-plugin-netlify": "^1.0.2", "gatsby-plugin-offline": "^1.0.4", "gatsby-plugin-react-helmet": "^1.0.3", "gatsby-plugin-react-next": "^1.0.3", diff --git a/www/src/pages/blog.html.js b/www/src/pages/blog.html.js deleted file mode 100644 index 7f818e97a7d72..0000000000000 --- a/www/src/pages/blog.html.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core -*/ - -'use strict'; - -import {Component} from 'react'; -import {navigateTo} from 'gatsby-link'; -import PropTypes from 'prop-types'; - -// TODO Remove this page in favor of createRedirect() in gatsby-node.js -// github.com/gatsbyjs/gatsby/pull/1068 - -class BlogRedirectPage extends Component { - componentDidMount() { - navigateTo(this.props.data.allMarkdownRemark.edges[0].node.fields.slug); - } - - render() { - return null; - } -} - -BlogRedirectPage.propTypes = { - data: PropTypes.object.isRequired, -}; - -// eslint-disable-next-line no-undef -export const pageQuery = graphql` - query BlogPageQuery { - allMarkdownRemark( - limit: 1, - filter: { id: { regex: "/_posts/" } } - sort: { fields: [fields___date], order: DESC } - ) { - edges { - node { - fields { - slug - } - } - } - } - } -`; - -export default BlogRedirectPage; diff --git a/www/yarn.lock b/www/yarn.lock index 7f713140912d3..e282044f5dd2a 100644 --- a/www/yarn.lock +++ b/www/yarn.lock @@ -1642,6 +1642,14 @@ chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" +chalk@^2.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.1.0.tgz#ac5becf14fa21b99c6c92ca7a7d7cfd5b17e743e" + dependencies: + ansi-styles "^3.1.0" + escape-string-regexp "^1.0.5" + supports-color "^4.0.0" + chalk@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.0.1.tgz#dbec49436d2ae15f536114e76d14656cdbc0f44d" @@ -3366,6 +3374,15 @@ gatsby-plugin-manifest@^1.0.4: babel-runtime "^6.26.0" bluebird "^3.5.0" +gatsby-plugin-netlify@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/gatsby-plugin-netlify/-/gatsby-plugin-netlify-1.0.2.tgz#4c84287efda9bb36ffd5c10bfb8fe135fc51929e" + dependencies: + babel-runtime "^6.26.0" + lodash "^4.17.4" + pify "3.0.0" + webpack-assets-manifest "^1.0.0" + gatsby-plugin-offline@^1.0.4: version "1.0.9" resolved "https://registry.yarnpkg.com/gatsby-plugin-offline/-/gatsby-plugin-offline-1.0.9.tgz#5d5879caf81a6e762984341f6eba765818d92320" @@ -3488,8 +3505,8 @@ gatsby-source-filesystem@^1.4.4: slash "^1.0.0" gatsby-transformer-remark@^1.7.2: - version "1.7.9" - resolved "https://registry.yarnpkg.com/gatsby-transformer-remark/-/gatsby-transformer-remark-1.7.9.tgz#fe1d2867aca54c62e9bef33c73cc19e2a90674e0" + version "1.7.10" + resolved "https://registry.yarnpkg.com/gatsby-transformer-remark/-/gatsby-transformer-remark-1.7.10.tgz#0e0df5495a189b0db601ca73c48c66b70e6055be" dependencies: babel-runtime "^6.26.0" bluebird "^3.5.0" @@ -3514,8 +3531,8 @@ gatsby-transformer-sharp@^1.6.1: image-size "^0.6.0" gatsby@^1.9.9: - version "1.9.40" - resolved "https://registry.yarnpkg.com/gatsby/-/gatsby-1.9.40.tgz#e4c713ec9ad849d4f5e455e595f941abd5a05ede" + version "1.9.42" + resolved "https://registry.yarnpkg.com/gatsby/-/gatsby-1.9.42.tgz#6792442e9b7f69e7d2b3e76b63b468de097c61c6" dependencies: async "^2.1.2" babel-code-frame "^6.22.0" @@ -5139,6 +5156,14 @@ lodash.foreach@^4.3.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.foreach/-/lodash.foreach-4.5.0.tgz#1a6a35eace401280c7f06dddec35165ab27e3e53" +lodash.get@^4.0: + version "4.4.2" + resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" + +lodash.has@^4.0: + version "4.5.2" + resolved "https://registry.yarnpkg.com/lodash.has/-/lodash.has-4.5.2.tgz#d19f4dc1095058cccbe2b0cdf4ee0fe4aa37c862" + lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" @@ -5167,6 +5192,10 @@ lodash.keys@^3.0.0: lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" +lodash.keys@^4.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-4.2.0.tgz#a08602ac12e4fb83f91fc1fb7a360a4d9ba35205" + lodash.map@^4.4.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3" @@ -5179,7 +5208,7 @@ lodash.memoize@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" -lodash.merge@^4.4.0: +lodash.merge@^4.0, lodash.merge@^4.4.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5" @@ -5195,7 +5224,7 @@ lodash.padstart@^4.1.0: version "4.6.1" resolved "https://registry.yarnpkg.com/lodash.padstart/-/lodash.padstart-4.6.1.tgz#d2e3eebff0d9d39ad50f5cbd1b52a7bce6bb611b" -lodash.pick@^4.2.1: +lodash.pick@^4.0, lodash.pick@^4.2.1: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3" @@ -5604,7 +5633,7 @@ mixin-deep@^1.1.3: for-in "^1.0.2" is-extendable "^0.1.1" -"mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: +"mkdirp@>=0.5 0", mkdirp@^0.5, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" dependencies: @@ -6219,14 +6248,14 @@ pez@1.x.x: hoek "2.x.x" nigel "1.x.x" +pify@3.0.0, pify@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" + pify@^2.0.0, pify@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" -pify@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" - pinkie-promise@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa" @@ -9053,6 +9082,18 @@ watchpack@^0.2.1: chokidar "^1.0.0" graceful-fs "^4.1.2" +webpack-assets-manifest@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/webpack-assets-manifest/-/webpack-assets-manifest-1.0.0.tgz#54a1bc4036e2eed2b3ce1fd6a7e31c09be99538a" + dependencies: + chalk "^2.0" + lodash.get "^4.0" + lodash.has "^4.0" + lodash.keys "^4.0" + lodash.merge "^4.0" + lodash.pick "^4.0" + mkdirp "^0.5" + webpack-configurator@^0.3.0: version "0.3.1" resolved "https://registry.yarnpkg.com/webpack-configurator/-/webpack-configurator-0.3.1.tgz#d16802afa674101a0cbfa6fc344d415c9649540b"