mirror of
				https://github.com/mastermindzh/rickvanlieshout.com
				synced 2025-10-31 16:49:49 +01:00 
			
		
		
		
	Merge pull request #70 from yodahuang/master
Refactor the React logic and introduce Fragment
This commit is contained in:
		| @@ -4,8 +4,8 @@ import Post from '../Post'; | |||||||
| class CategoryTemplateDetails extends React.Component { | class CategoryTemplateDetails extends React.Component { | ||||||
|   render() { |   render() { | ||||||
|     const items = []; |     const items = []; | ||||||
|     const { category } = this.props.pathContext; |     const { category } = this.props.category; | ||||||
|     const posts = this.props.data.allMarkdownRemark.edges; |     const posts = this.props.posts; | ||||||
|     posts.forEach((post) => { |     posts.forEach((post) => { | ||||||
|       items.push(<Post data={post} key={post.node.fields.slug} />); |       items.push(<Post data={post} key={post.node.fields.slug} />); | ||||||
|     }); |     }); | ||||||
|   | |||||||
| @@ -19,15 +19,12 @@ class Disqus extends Component { | |||||||
|     this.setState({ toasts }); |     this.setState({ toasts }); | ||||||
|   } |   } | ||||||
|   render() { |   render() { | ||||||
|     const { postNode, siteMetadata } = this.props; |     const { postNode, shortName, url: siteUrl } = this.props; | ||||||
|     if (!siteMetadata.disqusShortname) { |  | ||||||
|       return null; |  | ||||||
|     } |  | ||||||
|     const post = postNode.frontmatter; |     const post = postNode.frontmatter; | ||||||
|     const url = siteMetadata.url + postNode.fields.slug; |     const url = siteUrl + postNode.fields.slug; | ||||||
|     return ( |     return ( | ||||||
|       <ReactDisqusComments |       <ReactDisqusComments | ||||||
|         shortname={siteMetadata.disqusShortname} |         shortname={shortName} | ||||||
|         identifier={post.title} |         identifier={post.title} | ||||||
|         title={post.title} |         title={post.title} | ||||||
|         url={url} |         url={url} | ||||||
|   | |||||||
| @@ -4,11 +4,11 @@ import './style.scss'; | |||||||
|  |  | ||||||
| class PageTemplateDetails extends React.Component { | class PageTemplateDetails extends React.Component { | ||||||
|   render() { |   render() { | ||||||
|     const page = this.props.data.markdownRemark; |     const page = this.props.page; | ||||||
|  |  | ||||||
|     return ( |     return ( | ||||||
|       <div> |       <div> | ||||||
|         <Sidebar {...this.props} /> |         <Sidebar siteMetadata={this.props.siteMetadata} /> | ||||||
|         <div className="content"> |         <div className="content"> | ||||||
|           <div className="content__inner"> |           <div className="content__inner"> | ||||||
|             <div className="page"> |             <div className="page"> | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ import './style.scss'; | |||||||
|  |  | ||||||
| class PostTemplateDetails extends React.Component { | class PostTemplateDetails extends React.Component { | ||||||
|   render() { |   render() { | ||||||
|     const { subtitle, author } = this.props.data.site.siteMetadata; |     const { subtitle, author, disqusShortname, url } = this.props.siteMetadata; | ||||||
|     const post = this.props.data.markdownRemark; |     const post = this.props.post; | ||||||
|     const tags = post.fields.tagSlugs; |     const tags = post.fields.tagSlugs; | ||||||
|  |  | ||||||
|     const homeBlock = ( |     const homeBlock = ( | ||||||
| @@ -32,7 +32,7 @@ class PostTemplateDetails extends React.Component { | |||||||
|  |  | ||||||
|     const commentsBlock = ( |     const commentsBlock = ( | ||||||
|       <div> |       <div> | ||||||
|         <Disqus postNode={post} siteMetadata={this.props.data.site.siteMetadata} /> |         <Disqus postNode={post} shortName={disqusShortname} url={url} /> | ||||||
|       </div> |       </div> | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
| @@ -56,7 +56,7 @@ class PostTemplateDetails extends React.Component { | |||||||
|                 <br /> <strong>{author.name}</strong> on Twitter |                 <br /> <strong>{author.name}</strong> on Twitter | ||||||
|               </a> |               </a> | ||||||
|             </p> |             </p> | ||||||
|             {commentsBlock} |             {disqusShortname && commentsBlock} | ||||||
|           </div> |           </div> | ||||||
|         </div> |         </div> | ||||||
|       </div> |       </div> | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ import './style.scss'; | |||||||
| class Sidebar extends React.Component { | class Sidebar extends React.Component { | ||||||
|   render() { |   render() { | ||||||
|     const { location } = this.props; |     const { location } = this.props; | ||||||
|     const { author, subtitle, copyright, menu } = this.props.data.site.siteMetadata; |     const { author, subtitle, copyright, menu } = this.props.siteMetadata; | ||||||
|     const isHomePage = get(location, 'pathname', '/') === '/'; |     const isHomePage = get(location, 'pathname', '/') === '/'; | ||||||
|  |  | ||||||
|     /* eslint-disable jsx-a11y/img-redundant-alt */ |     /* eslint-disable jsx-a11y/img-redundant-alt */ | ||||||
| @@ -58,3 +58,25 @@ class Sidebar extends React.Component { | |||||||
| } | } | ||||||
|  |  | ||||||
| export default Sidebar; | export default Sidebar; | ||||||
|  |  | ||||||
|  | export const conponentQuery = graphql` | ||||||
|  |   fragment sidebarFragment on siteMetadata_2{ | ||||||
|  |     title | ||||||
|  |     subtitle | ||||||
|  |     copyright | ||||||
|  |     menu { | ||||||
|  |       label | ||||||
|  |       path | ||||||
|  |     } | ||||||
|  |     author { | ||||||
|  |       name | ||||||
|  |       email | ||||||
|  |       telegram | ||||||
|  |       twitter | ||||||
|  |       github | ||||||
|  |       rss | ||||||
|  |       vk | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | `; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,8 +4,8 @@ import Post from '../Post'; | |||||||
| class TagTemplateDetails extends React.Component { | class TagTemplateDetails extends React.Component { | ||||||
|   render() { |   render() { | ||||||
|     const items = []; |     const items = []; | ||||||
|     const tagTitle = this.props.pathContext.tag; |     const tagTitle = this.props.tag; | ||||||
|     const posts = this.props.data.allMarkdownRemark.edges; |     const posts = this.props.posts; | ||||||
|     posts.forEach((post) => { |     posts.forEach((post) => { | ||||||
|       items.push(<Post data={post} key={post.node.fields.slug} />); |       items.push(<Post data={post} key={post.node.fields.slug} />); | ||||||
|     }); |     }); | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ class NotFoundRoute extends React.Component { | |||||||
|   render() { |   render() { | ||||||
|     return ( |     return ( | ||||||
|       <div> |       <div> | ||||||
|         <Sidebar {...this.props} /> |         <Sidebar siteMetadata={this.props.data.site.siteMetadata} /> | ||||||
|         <div className="content"> |         <div className="content"> | ||||||
|           <div className="content__inner"> |           <div className="content__inner"> | ||||||
|             <div className="page"> |             <div className="page"> | ||||||
| @@ -27,22 +27,7 @@ export const pageQuery = graphql` | |||||||
|   query NotFoundQuery { |   query NotFoundQuery { | ||||||
|     site { |     site { | ||||||
|       siteMetadata { |       siteMetadata { | ||||||
|         title |         ...sidebarFragment | ||||||
|         subtitle |  | ||||||
|         copyright |  | ||||||
|         menu { |  | ||||||
|           label |  | ||||||
|           path |  | ||||||
|         } |  | ||||||
|         author { |  | ||||||
|           name |  | ||||||
|           email |  | ||||||
|           telegram |  | ||||||
|           twitter |  | ||||||
|           github |  | ||||||
|           rss |  | ||||||
|           vk |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ class CategoriesRoute extends React.Component { | |||||||
|     return ( |     return ( | ||||||
|       <div> |       <div> | ||||||
|         <Helmet title={`All Categories - ${title}`} /> |         <Helmet title={`All Categories - ${title}`} /> | ||||||
|         <Sidebar {...this.props} /> |         <Sidebar siteMetadata={this.props.data.site.siteMetadata} /> | ||||||
|         <div className="content"> |         <div className="content"> | ||||||
|           <div className="content__inner"> |           <div className="content__inner"> | ||||||
|             <div className="page"> |             <div className="page"> | ||||||
| @@ -44,22 +44,7 @@ export const pageQuery = graphql` | |||||||
|   query CategoryesQuery { |   query CategoryesQuery { | ||||||
|     site { |     site { | ||||||
|       siteMetadata { |       siteMetadata { | ||||||
|         title |         ...sidebarFragment | ||||||
|         subtitle |  | ||||||
|         copyright |  | ||||||
|         menu { |  | ||||||
|           label |  | ||||||
|           path |  | ||||||
|         } |  | ||||||
|         author { |  | ||||||
|           name |  | ||||||
|           email |  | ||||||
|           telegram |  | ||||||
|           twitter |  | ||||||
|           github |  | ||||||
|           rss |  | ||||||
|           vk |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     allMarkdownRemark( |     allMarkdownRemark( | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ class IndexRoute extends React.Component { | |||||||
|           <title>{title}</title> |           <title>{title}</title> | ||||||
|           <meta name="description" content={subtitle} /> |           <meta name="description" content={subtitle} /> | ||||||
|         </Helmet> |         </Helmet> | ||||||
|         <Sidebar {...this.props} /> |         <Sidebar siteMetadata={this.props.data.site.siteMetadata} /> | ||||||
|         <div className="content"> |         <div className="content"> | ||||||
|           <div className="content__inner"> |           <div className="content__inner"> | ||||||
|             {items} |             {items} | ||||||
| @@ -35,22 +35,7 @@ export const pageQuery = graphql` | |||||||
|   query IndexQuery { |   query IndexQuery { | ||||||
|     site { |     site { | ||||||
|       siteMetadata { |       siteMetadata { | ||||||
|         title |         ...sidebarFragment | ||||||
|         subtitle |  | ||||||
|         copyright |  | ||||||
|         menu { |  | ||||||
|           label |  | ||||||
|           path |  | ||||||
|         } |  | ||||||
|         author { |  | ||||||
|           name |  | ||||||
|           email |  | ||||||
|           telegram |  | ||||||
|           twitter |  | ||||||
|           github |  | ||||||
|           rss |  | ||||||
|           vk |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     allMarkdownRemark( |     allMarkdownRemark( | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ class TagsRoute extends React.Component { | |||||||
|     return ( |     return ( | ||||||
|       <div> |       <div> | ||||||
|         <Helmet title={`All Tags - ${title}`} /> |         <Helmet title={`All Tags - ${title}`} /> | ||||||
|         <Sidebar {...this.props} /> |         <Sidebar siteMetadata={this.props.data.site.siteMetadata} /> | ||||||
|         <div className="content"> |         <div className="content"> | ||||||
|           <div className="content__inner"> |           <div className="content__inner"> | ||||||
|             <div className="page"> |             <div className="page"> | ||||||
| @@ -44,22 +44,7 @@ export const pageQuery = graphql` | |||||||
|   query TagsQuery { |   query TagsQuery { | ||||||
|     site { |     site { | ||||||
|       siteMetadata { |       siteMetadata { | ||||||
|         title |         ...sidebarFragment | ||||||
|         subtitle |  | ||||||
|         copyright |  | ||||||
|         menu { |  | ||||||
|           label |  | ||||||
|           path |  | ||||||
|         } |  | ||||||
|         author { |  | ||||||
|           name |  | ||||||
|           email |  | ||||||
|           telegram |  | ||||||
|           twitter |  | ||||||
|           github |  | ||||||
|           rss |  | ||||||
|           vk |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     allMarkdownRemark( |     allMarkdownRemark( | ||||||
|   | |||||||
| @@ -5,14 +5,15 @@ import CategoryTemplateDetails from '../components/CategoryTemplateDetails'; | |||||||
|  |  | ||||||
| class CategoryTemplate extends React.Component { | class CategoryTemplate extends React.Component { | ||||||
|   render() { |   render() { | ||||||
|     const { title } = this.props.data.site.siteMetadata; |     const title = this.props.data.site.siteMetadata.title; | ||||||
|     const { category } = this.props.pathContext; |     const category = this.props.pathContext.category; | ||||||
|  |     const posts = this.props.data.allMarkdownRemark.edges; | ||||||
|  |  | ||||||
|     return ( |     return ( | ||||||
|       <div> |       <div> | ||||||
|         <Helmet title={`${category} - ${title}`} /> |         <Helmet title={`${category} - ${title}`} /> | ||||||
|         <Sidebar {...this.props} /> |         <Sidebar siteMetadata={this.props.data.site.siteMetadata} /> | ||||||
|         <CategoryTemplateDetails {...this.props} /> |         <CategoryTemplateDetails category={category} posts={posts} /> | ||||||
|       </div> |       </div> | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| @@ -24,22 +25,7 @@ export const pageQuery = graphql` | |||||||
|   query CategoryPage($category: String) { |   query CategoryPage($category: String) { | ||||||
|     site { |     site { | ||||||
|       siteMetadata { |       siteMetadata { | ||||||
|         title |         ...sidebarFragment | ||||||
|         subtitle |  | ||||||
|         copyright |  | ||||||
|         menu { |  | ||||||
|           label |  | ||||||
|           path |  | ||||||
|         } |  | ||||||
|         author { |  | ||||||
|           name |  | ||||||
|           email |  | ||||||
|           telegram |  | ||||||
|           twitter |  | ||||||
|           github |  | ||||||
|           rss |  | ||||||
|           vk |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     allMarkdownRemark( |     allMarkdownRemark( | ||||||
|   | |||||||
| @@ -4,7 +4,8 @@ import PageTemplateDetails from '../components/PageTemplateDetails'; | |||||||
|  |  | ||||||
| class PageTemplate extends React.Component { | class PageTemplate extends React.Component { | ||||||
|   render() { |   render() { | ||||||
|     const { title, subtitle } = this.props.data.site.siteMetadata; |     const siteMetadata = this.props.data.site.siteMetadata; | ||||||
|  |     const { title, subtitle } = siteMetadata; | ||||||
|     const page = this.props.data.markdownRemark; |     const page = this.props.data.markdownRemark; | ||||||
|     const { title: pageTitle, description: pageDescription } = page.frontmatter; |     const { title: pageTitle, description: pageDescription } = page.frontmatter; | ||||||
|     const description = pageDescription !== null ? pageDescription : subtitle; |     const description = pageDescription !== null ? pageDescription : subtitle; | ||||||
| @@ -15,7 +16,10 @@ class PageTemplate extends React.Component { | |||||||
|           <title>{`${pageTitle} - ${title}`}</title> |           <title>{`${pageTitle} - ${title}`}</title> | ||||||
|           <meta name="description" content={description} /> |           <meta name="description" content={description} /> | ||||||
|         </Helmet> |         </Helmet> | ||||||
|         <PageTemplateDetails {...this.props} /> |         <PageTemplateDetails | ||||||
|  |           siteMetadata={siteMetadata} | ||||||
|  |           page={page} | ||||||
|  |         /> | ||||||
|       </div> |       </div> | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| @@ -27,22 +31,7 @@ export const pageQuery = graphql` | |||||||
|   query PageBySlug($slug: String!) { |   query PageBySlug($slug: String!) { | ||||||
|     site { |     site { | ||||||
|       siteMetadata { |       siteMetadata { | ||||||
|         title |         ...sidebarFragment | ||||||
|         subtitle |  | ||||||
|         copyright |  | ||||||
|         menu { |  | ||||||
|           label |  | ||||||
|           path |  | ||||||
|         } |  | ||||||
|         author { |  | ||||||
|           name |  | ||||||
|           email |  | ||||||
|           telegram |  | ||||||
|           twitter |  | ||||||
|           github |  | ||||||
|           rss |  | ||||||
|           vk |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     markdownRemark(fields: { slug: { eq: $slug } }) { |     markdownRemark(fields: { slug: { eq: $slug } }) { | ||||||
|   | |||||||
| @@ -4,7 +4,8 @@ import PostTemplateDetails from '../components/PostTemplateDetails'; | |||||||
|  |  | ||||||
| class PostTemplate extends React.Component { | class PostTemplate extends React.Component { | ||||||
|   render() { |   render() { | ||||||
|     const { title, subtitle } = this.props.data.site.siteMetadata; |     const siteMetadata = this.props.data.site.siteMetadata; | ||||||
|  |     const { title, subtitle } = siteMetadata; | ||||||
|     const post = this.props.data.markdownRemark; |     const post = this.props.data.markdownRemark; | ||||||
|     const { title: postTitle, description: postDescription } = post.frontmatter; |     const { title: postTitle, description: postDescription } = post.frontmatter; | ||||||
|     const description = postDescription !== null ? postDescription : subtitle; |     const description = postDescription !== null ? postDescription : subtitle; | ||||||
| @@ -15,7 +16,7 @@ class PostTemplate extends React.Component { | |||||||
|           <title>{`${postTitle} - ${title}`}</title> |           <title>{`${postTitle} - ${title}`}</title> | ||||||
|           <meta name="description" content={description} /> |           <meta name="description" content={description} /> | ||||||
|         </Helmet> |         </Helmet> | ||||||
|         <PostTemplateDetails {...this.props} /> |         <PostTemplateDetails siteMetadata={siteMetadata} post={post} /> | ||||||
|       </div> |       </div> | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| @@ -29,7 +30,6 @@ export const pageQuery = graphql` | |||||||
|       siteMetadata { |       siteMetadata { | ||||||
|         title |         title | ||||||
|         subtitle |         subtitle | ||||||
|         copyright |  | ||||||
|         author { |         author { | ||||||
|           name |           name | ||||||
|           twitter |           twitter | ||||||
|   | |||||||
| @@ -11,8 +11,8 @@ class TagTemplate extends React.Component { | |||||||
|     return ( |     return ( | ||||||
|       <div> |       <div> | ||||||
|         <Helmet title={`All Posts tagged as "${tag}" - ${title}`} /> |         <Helmet title={`All Posts tagged as "${tag}" - ${title}`} /> | ||||||
|         <Sidebar {...this.props} /> |         <Sidebar siteMetadata={this.props.data.site.siteMetadata} /> | ||||||
|         <TagTemplateDetails {...this.props} /> |         <TagTemplateDetails posts={this.props.data.allMarkdownRemark.edges} tag={tag} /> | ||||||
|       </div> |       </div> | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| @@ -24,22 +24,7 @@ export const pageQuery = graphql` | |||||||
|   query TagPage($tag: String) { |   query TagPage($tag: String) { | ||||||
|     site { |     site { | ||||||
|       siteMetadata { |       siteMetadata { | ||||||
|         title |         ...sidebarFragment | ||||||
|         subtitle |  | ||||||
|         copyright |  | ||||||
|         menu { |  | ||||||
|           label |  | ||||||
|           path |  | ||||||
|         } |  | ||||||
|         author { |  | ||||||
|           name |  | ||||||
|           email |  | ||||||
|           telegram |  | ||||||
|           twitter |  | ||||||
|           github |  | ||||||
|           rss |  | ||||||
|           vk |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     allMarkdownRemark( |     allMarkdownRemark( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user