Skip to content

Refactor home page #150

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

Merged
merged 10 commits into from
Nov 6, 2017
Merged

Refactor home page #150

merged 10 commits into from
Nov 6, 2017

Conversation

yangshun
Copy link
Contributor

@yangshun yangshun commented Oct 12, 2017

This PR is part one of the refactoring of the home page issue #97 . I didn't want the PR to become too big so I left out refactoring of the examples section. I wanted to get some opinions on the current approach before starting on the examples section as well.

This PR does a few things:

  • Shift templates/home.js to pages/index.js
  • Transfer the content of content/index.md into pages/index.js
  • Break up the home page marketing content into markdown files and load the data via GraphQL
  • Remove hardcoded class names from home page marketing section

I have removed most of the hardcoded class names. There are some leftover styles because I have yet to refactor the examples section. I intend to refactor that part in a similar fashion and extract out the text into Markdown files and also load them via GraphQL. Will follow up with another PR for the examples section later.

cc @bvaughn

@reactjs-bot
Copy link

reactjs-bot commented Oct 12, 2017

Deploy preview ready!

Built with commit 65f1ced

https://deploy-preview-150--reactjs.netlify.com

@@ -0,0 +1,8 @@
---
title: Component-Based
order: 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used to decide the ordering of the 3-column marketing content. order might not be the best name for this and suggestions are welcome! I briefly considered rank.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think order works for this. Kind of like flexbox order.

@@ -60,15 +60,7 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
allMarkdown.data.allMarkdownRemark.edges.forEach(edge => {
const slug = edge.node.fields.slug;

if (slug === '/index.html') {
Copy link
Contributor Author

@yangshun yangshun Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer need to programatically create home page because it is now within the pages directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it.

@@ -6,7 +6,7 @@

'use strict';

import ButtonLink from './components/ButtonLink';
import ButtonLink from '../templates/components/ButtonLink';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should <ButtonLink> be moved to src/components?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

border: 'none',
borderBottom: `1 solid ${colors.divider}`,
}} />
<section className="home-section">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will refactor the examples section in a later PR. Please bear with the hardcoding of class names for now.

src/types.js Outdated
@@ -23,6 +23,7 @@ export type Node = {
next?: string,
prev?: string,
title: string,
order?: number,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether this is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, since the order frontmatter field is only used in the GraphQL query (and not in any Flow-covered code).

@@ -0,0 +1,8 @@
---
title: Component-Based
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered putting the title inside the content instead but I think putting it in the frontmatter makes more sense so we leave the formatting of the title outside this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me.

@yangshun
Copy link
Contributor Author

@bvaughn Have fixed according to your comments. Do have a look again 😄

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me so long to get back to this. I had less time during the work week this week to review website PRs.

I left some thoughts. Also it looks like we have a merge conflict now that needs to be addressed. Maybe you could rebase or merge master into this branch?

Let's talk more if any of my comments are unclear. The biggest remaining "TODO" really is to move the remaining hard-coded content into markdown files. Otherwise I dig this 👍

@@ -0,0 +1,8 @@
---
title: Component-Based
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me.

@@ -0,0 +1,8 @@
---
title: Component-Based
order: 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think order works for this. Kind of like flexbox order.

@@ -60,15 +60,7 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
allMarkdown.data.allMarkdownRemark.edges.forEach(edge => {
const slug = edge.node.fields.slug;

if (slug === '/index.html') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it.

@@ -6,7 +6,7 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for the / route but not for /index.html

We need to add an explicit redirect to gatsby-node.js to handle this:

  // Without this, /index.html won't redirect to root.
  createRedirect({
    fromPath: '/index.html',
    redirectInBrowser: true,
    toPath: '/',
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks for this!

<div className="example">
<h3>A Simple Component</h3>
<p>
React components implement a `render()` method that takes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content for these sections also needs to come from markdown files (so it can be localized).

JSX is optional and not required to use React.
</strong>{' '}
Try the{' '}
<a href="http://babeljs.io/repl#?babili=false&browsers=&build=&builtIns=false&code_lz=MYGwhgzhAEASCmIQHsCy8pgOb2vAHgC7wB2AJjAErxjCEB0AwsgLYAOyJph0A3gFABIAE6ky8YQAoAlHyEj4hAK7CS0ADxkAlgDcAfAiTI-hABZaI9NsORtLJMC3gBfdQHpt-gNxDn_P_zUtIQAIgDyqPSi5BKS6oYo6Jg40A5OALwARCHwOlokmdBuegA00CzISiSEAHLI4tJeQA&debug=false&circleciRepo=&evaluate=false&lineWrap=false&presets=react&prettier=true&targets=&version=6.26.0">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what might be cool? To auto-generate the URL for this from the actual code example (so the two will always stay in-sync). Babel's REPL just uses the lz-string module to serialize and deserialize code so we could copy it. 😁 It isn't likely to change because it's important to Babel to maintain backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this link will be part of the markdown, how do we generate the URL for this? Do we generate after render and modify the href in the markup?

@yangshun
Copy link
Contributor Author

yangshun commented Oct 23, 2017

Thanks for the review @bvaughn! I fixed the index.html redirect issue and rebased on master.

Regarding the content for the examples, I intend to address and fix them in a follow up PR so that this PR does not get too big. As for the refactoring of the marketing content, I think they are good to be merged. WDYT?

@bvaughn
Copy link
Contributor

bvaughn commented Oct 23, 2017

As for the refactoring of the marketing content, I think they are good to be merged. WDYT?

I think we should do it all as one PR, to be honest. We have localization/translation efforts going on right now and I don't want to temporarily pull a bunch of home page content out of the pipeline and cause confusion.

Also cc @ericnakagawa about this change.

@yangshun
Copy link
Contributor Author

I see. Ok I'll continue on this branch then 😄

@yangshun
Copy link
Contributor Author

@bvaughn I extracted out the examples content into markdown files following the same approach for the marketing content. I intend to also move the code out into separate files but I'm not too sure how the mountCodeExample hacks can be improved on. Could you provide more guidance regarding how to fix the TODOs tagged to renderExamplePlaceholder and mountCodeExample?

As far as the localization/translation efforts goes, this PR should be ok given that I have extracted out both the marketing and examples content into markdown files.

@yangshun
Copy link
Contributor Author

You know what might be cool? To auto-generate the URL for this from the actual code example (so the two will always stay in-sync). Babel's REPL just uses the lz-string module to serialize and deserialize code so we could copy it. 😁 It isn't likely to change because it's important to Babel to maintain backwards compatibility.

If this link will be part of the markdown, how do we generate the URL for this? Do we generate after render and modify the href in the markup?

@bvaughn
Copy link
Contributor

bvaughn commented Oct 25, 2017

I dig the general direction this PR is heading 😁 Thanks for driving this!

Could we move the new directories content/marketing and content/examples into a shared parent folder, content/home (just to more clearly organize the content). Particularly given other efforts like #138 and #162, I'm concerned "examples" might be confusing and "marketing" is a bit ambiguous.

I intend to also move the code out into separate files but I'm not too sure how the mountCodeExample hacks can be improved on. Could you provide more guidance regarding how to fix the TODOs tagged to renderExamplePlaceholder and mountCodeExample?

Maybe we should ignore the TODO about moving the hard-coded examples, for now, at least pending the outcome of #138 and #162.

What I was thinking was that we could move the example JS snippets near the markdown, but if we did that we wouldn't be able to import/require them in the template without either (a) passing them through via markdown (kind of hacky) or (b) overriding the Webpack config to allow it to resolve paths within content (since it's outside of source) and both seem kind of blah.

Maybe for now, we should just rename the code snippet constant names to better match the names of their corresponding markdown files.

If this link will be part of the markdown, how do we generate the URL for this? Do we generate after render and modify the href in the markup?

It's fine to do this as a follow-up. Actually I'd be happy to do it b'c it sounds fun. 😄 The idea though is that we could come up with a new syntax for linking to an example file and then we could maybe write a custom Remark transform plugin that generates the actual link (with lz compression) from it during build time so they were guaranteed to stay in sync.

@bvaughn
Copy link
Contributor

bvaughn commented Oct 31, 2017

Friendly follow up with @yangshun 😄

Also cc @ericnakagawa

@bvaughn
Copy link
Contributor

bvaughn commented Nov 5, 2017

One last friendly follow up 😄

If I don't hear back in a day or so, I'm going to take over this PR and implement my own requested changes. (This is totally okay, of course.)

@yangshun
Copy link
Contributor Author

yangshun commented Nov 5, 2017

@bvaughn Very sorry for the delay! This PR slipped my mind. I shifted the files into /home/marketing/ and /home/examples/. Is there anything else you want me to do in this PR?

@bvaughn
Copy link
Contributor

bvaughn commented Nov 6, 2017

No worries at all. Let me take a look.

@bvaughn bvaughn merged commit 65f1ced into reactjs:master Nov 6, 2017
@bvaughn
Copy link
Contributor

bvaughn commented Nov 6, 2017

Thank you!

I've added to this PR by moving the example JavaScript code into /home/content as well (see f5aaf4c) and tying it together with a new local plugin, gatsby-transformer-home-example-code.

BetterZxx pushed a commit to BetterZxx/react.dev that referenced this pull request Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants