feat(resources): link to resources home from intro

This commit is contained in:
Jean-Philippe Sirois
2019-12-15 19:48:02 -05:00
parent 4003ae0b7c
commit b40d6aeb58
3 changed files with 15 additions and 4 deletions
+4 -2
View File
@@ -2,7 +2,7 @@ import { graphql, useStaticQuery } from "gatsby"
import React, { FC, HTMLAttributes, memo } from "react"
import "react-perfect-scrollbar/dist/css/styles.css"
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
import { humanize } from "../../utils"
import { getPath, humanize } from "../../utils"
import * as SC from "./styles"
import useBuildTree from "./useBuildTree"
@@ -30,8 +30,10 @@ function plantTree(item: IFileOrFolder, index?: number) {
if (item.type === "file") {
// remove the first elements, treat as hardcoded
const [, , , ...cleanedUpPath] = item.path.split("/")
const path = getPath(item)
return (
<SC.PageLink key={item.title} to={item.path}>
<SC.PageLink key={item.title} to={path}>
{cleanedUpPath.map(node => (
// TODO: use helper to format path
<SC.NodePart key={node}>{humanize(node)}</SC.NodePart>
+4 -2
View File
@@ -2,7 +2,7 @@ import { graphql, useStaticQuery } from "gatsby"
import React, { FC, HTMLAttributes, memo, useState } from "react"
import TriangleDown from "../../icons/triangle-down.svg"
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
import { humanize } from "../../utils"
import { getPath, humanize } from "../../utils"
import { Sidebar } from "../Sidebar"
import useBuildTree from "./../../hooks/useBuildTree"
import useSidebar from "./../../hooks/useSidebar"
@@ -30,8 +30,10 @@ const ALL_RESOURCES = graphql`
function plantTree(item: IFileOrFolder, index?: number, firstLevel?: boolean) {
if (item.type === "file") {
const path = getPath(item)
return (
<SC.PageLink key={item.title} to={item.path} activeClassName="active">
<SC.PageLink key={item.title} to={path} activeClassName="active">
{humanize(item.title)}
</SC.PageLink>
)
+7
View File
@@ -26,6 +26,13 @@ export function humanize(str: string): string {
return pipe(dashToSpace, specificWordsToUpper, removeDotMD)(str)
}
export function getPath({ path, title }: IFileOrFolder) {
const depth = path.replace("/resources", "").split("/").length - 2
const isLanguageIntro = depth === 1 && title.includes("intro")
return isLanguageIntro ? path.replace("intro.md", "") : path
}
export function traversePaths(
[head, ...tail]: string[],
basePath: string