From b40d6aeb5856719d4b0cdef2af6a2c21c29ae693 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Sirois Date: Sun, 15 Dec 2019 19:47:31 -0500 Subject: [PATCH] feat(resources): link to resources home from intro --- src/components/ResourcesList/index.tsx | 6 ++++-- src/components/ResourcesSidebar/index.tsx | 6 ++++-- src/utils/index.ts | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/ResourcesList/index.tsx b/src/components/ResourcesList/index.tsx index eead565..1f973bf 100644 --- a/src/components/ResourcesList/index.tsx +++ b/src/components/ResourcesList/index.tsx @@ -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 ( - + {cleanedUpPath.map(node => ( // TODO: use helper to format path {humanize(node)} diff --git a/src/components/ResourcesSidebar/index.tsx b/src/components/ResourcesSidebar/index.tsx index af316ee..13ab293 100644 --- a/src/components/ResourcesSidebar/index.tsx +++ b/src/components/ResourcesSidebar/index.tsx @@ -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 ( - + {humanize(item.title)} ) diff --git a/src/utils/index.ts b/src/utils/index.ts index c98ea99..76d49a1 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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