From 5433a472d8b8212580ff3b9666afe56710ea113a Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 13 Apr 2018 09:42:07 -0700 Subject: [PATCH 01/11] Added redirects for old React versions --- static/_redirects | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/static/_redirects b/static/_redirects index 7db75e0c..37534ccf 100644 --- a/static/_redirects +++ b/static/_redirects @@ -1,2 +1,6 @@ /html-jsx.html http://magic.reactjs.net/htmltojsx.htm 301 -/tips/controlled-input-null-value.html /docs/forms.html#controlled-input-null-value \ No newline at end of file +/tips/controlled-input-null-value.html /docs/forms.html#controlled-input-null-value + +/version/16.2 https://5abc31d8be40f1556f06c4be--reactjs.netlify.com/ 301 +/version/16.1 https://5a1dbcf14c4b93299e65b9a9--reactjs.netlify.com/ 301 +/version/16.0 https://5a046bf5a6188f4b8fa4938a--reactjs.netlify.com/ 301 \ No newline at end of file From 597fe259686d88a61c65f69d48ae84912ddea2db Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 13 Apr 2018 10:37:05 -0700 Subject: [PATCH 02/11] Added robots.txt to prevent crawling old versions of site --- static/robots.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 static/robots.txt diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 00000000..30823580 --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: /version/ \ No newline at end of file From ae0b9532e170046ee6aaab81eed020fca51725f1 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 13 Apr 2018 11:31:17 -0700 Subject: [PATCH 03/11] Added version drop-down toggle (that I will replace in a moment) --- src/components/LayoutHeader/Header.js | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/components/LayoutHeader/Header.js b/src/components/LayoutHeader/Header.js index f5ec82d3..29ee3369 100644 --- a/src/components/LayoutHeader/Header.js +++ b/src/components/LayoutHeader/Header.js @@ -10,9 +10,9 @@ import HeaderLink from './HeaderLink'; import Link from 'gatsby-link'; import React from 'react'; import {colors, fonts, media} from 'theme'; -import {version} from 'site-constants'; import ExternalLinkSvg from 'templates/components/ExternalLinkSvg'; import DocSearch from './DocSearch'; +import VersionToggler from './VersionToggler'; import logoSvg from 'icons/logo.svg'; @@ -146,27 +146,7 @@ const Header = ({location}: {location: Location}) => ( width: 'calc(100% / 6)', }, }}> - - v{version} - + Date: Fri, 13 Apr 2018 11:45:12 -0700 Subject: [PATCH 04/11] Added versions page with links to recent releases --- src/components/LayoutHeader/Header.js | 22 ++++++++++- src/pages/versions.js | 54 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/pages/versions.js diff --git a/src/components/LayoutHeader/Header.js b/src/components/LayoutHeader/Header.js index 29ee3369..35e6c55c 100644 --- a/src/components/LayoutHeader/Header.js +++ b/src/components/LayoutHeader/Header.js @@ -10,9 +10,9 @@ import HeaderLink from './HeaderLink'; import Link from 'gatsby-link'; import React from 'react'; import {colors, fonts, media} from 'theme'; +import {version} from 'site-constants'; import ExternalLinkSvg from 'templates/components/ExternalLinkSvg'; import DocSearch from './DocSearch'; -import VersionToggler from './VersionToggler'; import logoSvg from 'icons/logo.svg'; @@ -146,7 +146,25 @@ const Header = ({location}: {location: Location}) => ( width: 'calc(100% / 6)', }, }}> - + + v{version} + ( + +
+ +
+ +); + +export default Versions; From 48a92c592e08151764199cf7b878a897ddfe8bfe Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 13 Apr 2018 13:42:50 -0700 Subject: [PATCH 05/11] Moved versions control into versions.yml and Gatsby plug-in --- content/versions.yml | 9 +++ gatsby-config.js | 1 + .../create-redirects.js | 65 +++++++++++++++++++ .../gatsby-node.js | 32 +++++++++ .../package.json | 4 ++ src/pages/versions.js | 25 +++---- static/_redirects | 6 +- 7 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 content/versions.yml create mode 100644 plugins/gatsby-transformer-versions-yaml/create-redirects.js create mode 100644 plugins/gatsby-transformer-versions-yaml/gatsby-node.js create mode 100644 plugins/gatsby-transformer-versions-yaml/package.json diff --git a/content/versions.yml b/content/versions.yml new file mode 100644 index 00000000..fae7e84b --- /dev/null +++ b/content/versions.yml @@ -0,0 +1,9 @@ +- title: '16.2.0' + path: /version/16.2 + url: https://5abc31d8be40f1556f06c4be--reactjs.netlify.com +- title: '16.1.1' + path: /version/16.1 + url: https://5a1dbcf14c4b93299e65b9a9--reactjs.netlify.com +- title: '16.0.0' + path: /version/16.0 + url: https://5a046bf5a6188f4b8fa4938a--reactjs.netlify.com \ No newline at end of file diff --git a/gatsby-config.js b/gatsby-config.js index 66f84a54..fe4410e9 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -20,6 +20,7 @@ module.exports = { 'gatsby-source-react-error-codes', 'gatsby-transformer-authors-yaml', 'gatsby-transformer-home-example-code', + 'gatsby-transformer-versions-yaml', 'gatsby-plugin-netlify', 'gatsby-plugin-glamor', 'gatsby-plugin-react-next', diff --git a/plugins/gatsby-transformer-versions-yaml/create-redirects.js b/plugins/gatsby-transformer-versions-yaml/create-redirects.js new file mode 100644 index 00000000..bd6e2d3e --- /dev/null +++ b/plugins/gatsby-transformer-versions-yaml/create-redirects.js @@ -0,0 +1,65 @@ +const {appendFile, exists, readFile, writeFile} = require('fs-extra'); + +const HEADER_COMMENT = `## Created with gatsby-transformer-versions-yaml`; + +module.exports = async function writeRedirectsFile(redirects, publicFolder) { + if (!redirects.length) { + return null; + } + + const FILE_PATH = publicFolder(`_redirects`); + + // Map redirect data to the format Netlify expects + // https://www.netlify.com/docs/redirects/ + redirects = redirects.map(redirect => { + const { + fromPath, + isPermanent, + redirectInBrowser, // eslint-disable-line no-unused-vars + toPath, + ...rest + } = redirect; + + // The order of the first 3 parameters is significant. + // The order for rest params (key-value pairs) is arbitrary. + const pieces = [ + fromPath, + toPath, + isPermanent ? 301 : 302, // Status + ]; + + for (let key in rest) { + const value = rest[key]; + + if (typeof value === `string` && value.indexOf(` `) >= 0) { + console.warn( + `Invalid redirect value "${value}" specified for key "${key}". ` + + `Values should not contain spaces.`, + ); + } else { + pieces.push(`${key}=${value}`); + } + } + + return pieces.join(` `); + }); + + let appendToFile = false; + + // Websites may also have statically defined redirects + // In that case we should append to them (not overwrite) + // Make sure we aren't just looking at previous build results though + const fileExists = await exists(FILE_PATH); + if (fileExists) { + const fileContents = await readFile(FILE_PATH); + if (fileContents.indexOf(HEADER_COMMENT) < 0) { + appendToFile = true; + } + } + + const data = `${HEADER_COMMENT}\n\n${redirects.join(`\n`)}`; + + return appendToFile + ? appendFile(FILE_PATH, `\n\n${data}`) + : writeFile(FILE_PATH, data); +}; diff --git a/plugins/gatsby-transformer-versions-yaml/gatsby-node.js b/plugins/gatsby-transformer-versions-yaml/gatsby-node.js new file mode 100644 index 00000000..d5bca5d6 --- /dev/null +++ b/plugins/gatsby-transformer-versions-yaml/gatsby-node.js @@ -0,0 +1,32 @@ +const readFileSync = require('fs').readFileSync; +const resolve = require('path').resolve; +const safeLoad = require('js-yaml').safeLoad; +const createRedirects = require('./create-redirects'); +const path = require('path'); + +// Reads versions.yml data into GraphQL. +// This is used to generate redirect rules for older documentation versions. +exports.onPostBuild = async ({store}) => { + const path = resolve(__dirname, '../../content/versions.yml'); + const file = readFileSync(path, 'utf8'); + const versions = safeLoad(file); + + // versions.yml structure is [{title: string, path: string, url: string}, ...] + createRedirects( + versions.map(version => ({ + fromPath: version.path, + toPath: version.url, + })), + getPublicFolder(store), + ); +}; + +function buildPrefixer(prefix, ...paths) { + return (...subpaths) => path.join(prefix, ...paths, ...subpaths); +} + +function getPublicFolder(store) { + const {program} = store.getState(); + + return buildPrefixer(program.directory, `public`); +} diff --git a/plugins/gatsby-transformer-versions-yaml/package.json b/plugins/gatsby-transformer-versions-yaml/package.json new file mode 100644 index 00000000..dcfada5c --- /dev/null +++ b/plugins/gatsby-transformer-versions-yaml/package.json @@ -0,0 +1,4 @@ +{ + "name": "gatsby-transformer-versions-yaml", + "version": "0.0.1" +} \ No newline at end of file diff --git a/src/pages/versions.js b/src/pages/versions.js index 6d4d8b3a..2695da7b 100644 --- a/src/pages/versions.js +++ b/src/pages/versions.js @@ -11,6 +11,9 @@ import TitleAndMetaTags from 'components/TitleAndMetaTags'; import React from 'react'; import {sharedStyles} from 'theme'; +// $FlowFixMe This is a valid path +import versions from '../../content/versions.yml'; + const Versions = () => (
@@ -29,21 +32,13 @@ const Versions = () => (

Documentation for recent releases can also be accessed below:

diff --git a/static/_redirects b/static/_redirects index 37534ccf..7db75e0c 100644 --- a/static/_redirects +++ b/static/_redirects @@ -1,6 +1,2 @@ /html-jsx.html http://magic.reactjs.net/htmltojsx.htm 301 -/tips/controlled-input-null-value.html /docs/forms.html#controlled-input-null-value - -/version/16.2 https://5abc31d8be40f1556f06c4be--reactjs.netlify.com/ 301 -/version/16.1 https://5a1dbcf14c4b93299e65b9a9--reactjs.netlify.com/ 301 -/version/16.0 https://5a046bf5a6188f4b8fa4938a--reactjs.netlify.com/ 301 \ No newline at end of file +/tips/controlled-input-null-value.html /docs/forms.html#controlled-input-null-value \ No newline at end of file From d184d0292fa0c859a9a40da41764d3b098dab576 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sat, 14 Apr 2018 08:08:16 -0700 Subject: [PATCH 06/11] Added links to old release changelogs also --- content/versions.yml | 5 ++++- src/pages/versions.js | 29 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/content/versions.yml b/content/versions.yml index fae7e84b..0a849ec2 100644 --- a/content/versions.yml +++ b/content/versions.yml @@ -1,9 +1,12 @@ - title: '16.2.0' path: /version/16.2 url: https://5abc31d8be40f1556f06c4be--reactjs.netlify.com + changelog: https://github.com/facebook/react/blob/master/CHANGELOG.md#1620-november-28-2017 - title: '16.1.1' path: /version/16.1 url: https://5a1dbcf14c4b93299e65b9a9--reactjs.netlify.com + changelog: https://github.com/facebook/react/blob/master/CHANGELOG.md#1611-november-13-2017 - title: '16.0.0' path: /version/16.0 - url: https://5a046bf5a6188f4b8fa4938a--reactjs.netlify.com \ No newline at end of file + url: https://5a046bf5a6188f4b8fa4938a--reactjs.netlify.com + changelog: https://github.com/facebook/react/blob/master/CHANGELOG.md#1600-september-26-2017 \ No newline at end of file diff --git a/src/pages/versions.js b/src/pages/versions.js index 2695da7b..23d2b002 100644 --- a/src/pages/versions.js +++ b/src/pages/versions.js @@ -28,18 +28,25 @@ const Versions = () => ( target="_blank" rel="noopener"> in GitHub - . + . Documentation for recent releases can also be found below:

-

Documentation for recent releases can also be accessed below:

- + {versions.map(version => ( +
+

{version.title}

+ +
+ ))} From 6c094ab19294a41db8f5eb61b998742b0a91b018 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sat, 14 Apr 2018 10:15:17 -0700 Subject: [PATCH 07/11] Minor tidying up of the gatsby-transformer-versions-yaml plugin --- .../create-redirects.js | 20 ++++++++------- .../gatsby-node.js | 25 ++++++++----------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/plugins/gatsby-transformer-versions-yaml/create-redirects.js b/plugins/gatsby-transformer-versions-yaml/create-redirects.js index bd6e2d3e..af9c49a5 100644 --- a/plugins/gatsby-transformer-versions-yaml/create-redirects.js +++ b/plugins/gatsby-transformer-versions-yaml/create-redirects.js @@ -2,13 +2,16 @@ const {appendFile, exists, readFile, writeFile} = require('fs-extra'); const HEADER_COMMENT = `## Created with gatsby-transformer-versions-yaml`; -module.exports = async function writeRedirectsFile(redirects, publicFolder) { +// Patterned after the 'gatsby-plugin-netlify' plug-in: +// https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-netlify/src/create-redirects.js +module.exports = async function writeRedirectsFile( + redirects, + redirectsFilePath, +) { if (!redirects.length) { return null; } - const FILE_PATH = publicFolder(`_redirects`); - // Map redirect data to the format Netlify expects // https://www.netlify.com/docs/redirects/ redirects = redirects.map(redirect => { @@ -20,8 +23,7 @@ module.exports = async function writeRedirectsFile(redirects, publicFolder) { ...rest } = redirect; - // The order of the first 3 parameters is significant. - // The order for rest params (key-value pairs) is arbitrary. + // The order of these parameters is significant. const pieces = [ fromPath, toPath, @@ -49,9 +51,9 @@ module.exports = async function writeRedirectsFile(redirects, publicFolder) { // Websites may also have statically defined redirects // In that case we should append to them (not overwrite) // Make sure we aren't just looking at previous build results though - const fileExists = await exists(FILE_PATH); + const fileExists = await exists(redirectsFilePath); if (fileExists) { - const fileContents = await readFile(FILE_PATH); + const fileContents = await readFile(redirectsFilePath); if (fileContents.indexOf(HEADER_COMMENT) < 0) { appendToFile = true; } @@ -60,6 +62,6 @@ module.exports = async function writeRedirectsFile(redirects, publicFolder) { const data = `${HEADER_COMMENT}\n\n${redirects.join(`\n`)}`; return appendToFile - ? appendFile(FILE_PATH, `\n\n${data}`) - : writeFile(FILE_PATH, data); + ? appendFile(redirectsFilePath, `\n\n${data}`) + : writeFile(redirectsFilePath, data); }; diff --git a/plugins/gatsby-transformer-versions-yaml/gatsby-node.js b/plugins/gatsby-transformer-versions-yaml/gatsby-node.js index d5bca5d6..b47dd29e 100644 --- a/plugins/gatsby-transformer-versions-yaml/gatsby-node.js +++ b/plugins/gatsby-transformer-versions-yaml/gatsby-node.js @@ -7,26 +7,23 @@ const path = require('path'); // Reads versions.yml data into GraphQL. // This is used to generate redirect rules for older documentation versions. exports.onPostBuild = async ({store}) => { - const path = resolve(__dirname, '../../content/versions.yml'); - const file = readFileSync(path, 'utf8'); + const versionsFile = resolve(__dirname, '../../content/versions.yml'); + const file = readFileSync(versionsFile, 'utf8'); const versions = safeLoad(file); - // versions.yml structure is [{title: string, path: string, url: string}, ...] + const {program} = store.getState(); + const redirectsFilePath = path.join( + program.directory, + 'public', + '_redirects', + ); + + // versions.yml structure is [{path: string, url: string, ...}, ...] createRedirects( versions.map(version => ({ fromPath: version.path, toPath: version.url, })), - getPublicFolder(store), + redirectsFilePath, ); }; - -function buildPrefixer(prefix, ...paths) { - return (...subpaths) => path.join(prefix, ...paths, ...subpaths); -} - -function getPublicFolder(store) { - const {program} = store.getState(); - - return buildPrefixer(program.directory, `public`); -} From 7843bbe4a0fd395ec3a3daf7396339684a6fcc73 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 15 Apr 2018 07:47:01 -0700 Subject: [PATCH 08/11] Testing a 200 redirect proxy --- static/_redirects | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/static/_redirects b/static/_redirects index 7db75e0c..c2bbbaca 100644 --- a/static/_redirects +++ b/static/_redirects @@ -1,2 +1,5 @@ /html-jsx.html http://magic.reactjs.net/htmltojsx.htm 301 -/tips/controlled-input-null-value.html /docs/forms.html#controlled-input-null-value \ No newline at end of file +/tips/controlled-input-null-value.html /docs/forms.html#controlled-input-null-value + +## Testing +/version/16.2.0/* https://5abc31d8be40f1556f06c4be--reactjs.netlify.com/:splat 200 \ No newline at end of file From fbbddeea29b579000491b3748dcda8316104888f Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 15 Apr 2018 07:52:11 -0700 Subject: [PATCH 09/11] Removing redirect proxy test --- static/_redirects | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/static/_redirects b/static/_redirects index c2bbbaca..7db75e0c 100644 --- a/static/_redirects +++ b/static/_redirects @@ -1,5 +1,2 @@ /html-jsx.html http://magic.reactjs.net/htmltojsx.htm 301 -/tips/controlled-input-null-value.html /docs/forms.html#controlled-input-null-value - -## Testing -/version/16.2.0/* https://5abc31d8be40f1556f06c4be--reactjs.netlify.com/:splat 200 \ No newline at end of file +/tips/controlled-input-null-value.html /docs/forms.html#controlled-input-null-value \ No newline at end of file From 88bf29d3f31f5a52f11bec0ea43e64501a653204 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 15 Apr 2018 08:00:04 -0700 Subject: [PATCH 10/11] Added 16.3 changelog to version links --- content/versions.yml | 2 ++ .../gatsby-transformer-versions-yaml/gatsby-node.js | 2 +- src/pages/versions.js | 12 +++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/content/versions.yml b/content/versions.yml index 0a849ec2..443c748d 100644 --- a/content/versions.yml +++ b/content/versions.yml @@ -1,3 +1,5 @@ +- title: '16.3.1' + changelog: https://github.com/facebook/react/blob/master/CHANGELOG.md#1631-april-3-2018 - title: '16.2.0' path: /version/16.2 url: https://5abc31d8be40f1556f06c4be--reactjs.netlify.com diff --git a/plugins/gatsby-transformer-versions-yaml/gatsby-node.js b/plugins/gatsby-transformer-versions-yaml/gatsby-node.js index b47dd29e..e73b566f 100644 --- a/plugins/gatsby-transformer-versions-yaml/gatsby-node.js +++ b/plugins/gatsby-transformer-versions-yaml/gatsby-node.js @@ -20,7 +20,7 @@ exports.onPostBuild = async ({store}) => { // versions.yml structure is [{path: string, url: string, ...}, ...] createRedirects( - versions.map(version => ({ + versions.filter(version => version.path && version.url).map(version => ({ fromPath: version.path, toPath: version.url, })), diff --git a/src/pages/versions.js b/src/pages/versions.js index 23d2b002..e20f8fc5 100644 --- a/src/pages/versions.js +++ b/src/pages/versions.js @@ -39,11 +39,13 @@ const Versions = () => ( Changelog -
  • - - Documentation - -
  • + {version.path && ( +
  • + + Documentation + +
  • + )} ))} From 631f32cab01f9e9a9973fdf8d48e7032f260a6fd Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 16 Apr 2018 09:57:47 -0700 Subject: [PATCH 11/11] Replaced 16.3.1 link with 16.3.2 --- content/versions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/versions.yml b/content/versions.yml index 443c748d..e379ad32 100644 --- a/content/versions.yml +++ b/content/versions.yml @@ -1,5 +1,5 @@ -- title: '16.3.1' - changelog: https://github.com/facebook/react/blob/master/CHANGELOG.md#1631-april-3-2018 +- title: '16.3.2' + changelog: https://github.com/facebook/react/blob/master/CHANGELOG.md#1632-april-16-2018 - title: '16.2.0' path: /version/16.2 url: https://5abc31d8be40f1556f06c4be--reactjs.netlify.com