feat(resources): create intro page for each language

This commit is contained in:
Jean-Philippe Sirois
2019-12-15 16:22:43 -05:00
parent f54bf61817
commit 97e9b8ce53
10 changed files with 168 additions and 2 deletions
+23 -2
View File
@@ -12,6 +12,7 @@ const ALL_RESOURCES = graphql`
edges {
node {
relativePath
relativeDirectory
childMarkdownRemark {
frontmatter {
authors
@@ -51,9 +52,29 @@ const Language = memo(({ item }: { item: IFolder; index: number }) => {
)
})
export const ResourcesList: FC<HTMLAttributes<HTMLDivElement>> = props => {
interface IResourcesList extends HTMLAttributes<HTMLDivElement> {
relativeDirectory?: string
}
export const ResourcesList: FC<IResourcesList> = props => {
const resources = useStaticQuery<IAllResourcesQuery>(ALL_RESOURCES)
const tree = useBuildTree(resources)
const filteredResources = {
...resources,
allFile: {
...resources.allFile,
edges: resources.allFile.edges.filter(({ node }) => {
if (!props.relativeDirectory) {
return true
}
const [language] = node.relativeDirectory.split("/")
return props.relativeDirectory === language
}),
},
}
const tree = useBuildTree(filteredResources)
const sortedTree = tree.sort((a, b) => a.title.localeCompare(b.title))
return (
+10
View File
@@ -0,0 +1,10 @@
---
authors:
- "veksen#1565"
created_at: 2019/12/15
title: C++
---
## C++
The C++ resources ^\_-
+10
View File
@@ -0,0 +1,10 @@
---
authors:
- "veksen#1565"
created_at: 2019/12/15
title: Java
---
## Java
The Java resources ^\_-
+10
View File
@@ -0,0 +1,10 @@
---
authors:
- "veksen#1565"
created_at: 2019/12/15
title: Javascript
---
## Javascript
The Javascript resources ^\_-
+10
View File
@@ -0,0 +1,10 @@
---
authors:
- "veksen#1565"
created_at: 2019/12/15
title: Kotlin
---
## Kotlin
The Kotlin resources ^\_-
+10
View File
@@ -0,0 +1,10 @@
---
authors:
- "veksen#1565"
created_at: 2019/12/15
title: PHP
---
## PHP
The PHP resources ^\_-
+10
View File
@@ -0,0 +1,10 @@
---
authors:
- "veksen#1565"
created_at: 2019/12/15
title: Python
---
## Python
The Python resources ^\_-
+62
View File
@@ -0,0 +1,62 @@
import { graphql } from "gatsby"
import React, { FC, Fragment } from "react"
import { Header } from "../components/Header"
import { Markdown } from "../components/Markdown"
import { ResourcesList } from "../components/ResourcesList"
import { SEO } from "../components/SEO"
// @todo maybe find alternative type for data
const LanguageHome: FC<any> = ({ data, pageContext }) => {
const { relativePath } = data.file
const { html, excerpt, fields, frontmatter, timeToRead } = data.file.post
return (
<Fragment>
<SEO title={frontmatter.title} description={excerpt} />
<Header
relativePath={relativePath}
basePath="/resources"
title={frontmatter.title}
authors={fields.authors}
createdAt={frontmatter.created_at}
timeToRead={timeToRead}
recommendedReading={frontmatter.recommended_reading}
externalResources={frontmatter.external_resources}
/>
<Markdown content={html} />
<ResourcesList relativeDirectory={pageContext.language} />
</Fragment>
)
}
export default LanguageHome
export const query = graphql`
query LanguageHome($language: String!) {
file(
sourceInstanceName: { eq: "resources" }
relativeDirectory: { eq: $language }
base: { eq: "intro.md" }
) {
relativePath
post: childMarkdownRemark {
html
excerpt
fields {
authors {
name
hash
avatar
}
}
frontmatter {
created_at
title
recommended_reading
external_resources
}
timeToRead
}
}
}
`
+1
View File
@@ -22,6 +22,7 @@ export interface IFileQuery {
export interface IFileResourceQuery {
node: {
relativePath: string
relativeDirectory: string
childMarkdownRemark: {
frontmatter: {
author: string