mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 09:15:58 +02:00
Merge pull request #197 from the-programmers-hangout/feat-link-to-resource-home
feat(resources): link to resources home from intro
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user