mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-06 23:43:45 +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, { FC, HTMLAttributes, memo } from "react"
|
||||||
import "react-perfect-scrollbar/dist/css/styles.css"
|
import "react-perfect-scrollbar/dist/css/styles.css"
|
||||||
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
|
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
|
||||||
import { humanize } from "../../utils"
|
import { getPath, humanize } from "../../utils"
|
||||||
import * as SC from "./styles"
|
import * as SC from "./styles"
|
||||||
import useBuildTree from "./useBuildTree"
|
import useBuildTree from "./useBuildTree"
|
||||||
|
|
||||||
@@ -30,8 +30,10 @@ function plantTree(item: IFileOrFolder, index?: number) {
|
|||||||
if (item.type === "file") {
|
if (item.type === "file") {
|
||||||
// remove the first elements, treat as hardcoded
|
// remove the first elements, treat as hardcoded
|
||||||
const [, , , ...cleanedUpPath] = item.path.split("/")
|
const [, , , ...cleanedUpPath] = item.path.split("/")
|
||||||
|
const path = getPath(item)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SC.PageLink key={item.title} to={item.path}>
|
<SC.PageLink key={item.title} to={path}>
|
||||||
{cleanedUpPath.map(node => (
|
{cleanedUpPath.map(node => (
|
||||||
// TODO: use helper to format path
|
// TODO: use helper to format path
|
||||||
<SC.NodePart key={node}>{humanize(node)}</SC.NodePart>
|
<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 React, { FC, HTMLAttributes, memo, useState } from "react"
|
||||||
import TriangleDown from "../../icons/triangle-down.svg"
|
import TriangleDown from "../../icons/triangle-down.svg"
|
||||||
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
|
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
|
||||||
import { humanize } from "../../utils"
|
import { getPath, humanize } from "../../utils"
|
||||||
import { Sidebar } from "../Sidebar"
|
import { Sidebar } from "../Sidebar"
|
||||||
import useBuildTree from "./../../hooks/useBuildTree"
|
import useBuildTree from "./../../hooks/useBuildTree"
|
||||||
import useSidebar from "./../../hooks/useSidebar"
|
import useSidebar from "./../../hooks/useSidebar"
|
||||||
@@ -30,8 +30,10 @@ const ALL_RESOURCES = graphql`
|
|||||||
|
|
||||||
function plantTree(item: IFileOrFolder, index?: number, firstLevel?: boolean) {
|
function plantTree(item: IFileOrFolder, index?: number, firstLevel?: boolean) {
|
||||||
if (item.type === "file") {
|
if (item.type === "file") {
|
||||||
|
const path = getPath(item)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SC.PageLink key={item.title} to={item.path} activeClassName="active">
|
<SC.PageLink key={item.title} to={path} activeClassName="active">
|
||||||
{humanize(item.title)}
|
{humanize(item.title)}
|
||||||
</SC.PageLink>
|
</SC.PageLink>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ export function humanize(str: string): string {
|
|||||||
return pipe(dashToSpace, specificWordsToUpper, removeDotMD)(str)
|
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(
|
export function traversePaths(
|
||||||
[head, ...tail]: string[],
|
[head, ...tail]: string[],
|
||||||
basePath: string
|
basePath: string
|
||||||
|
|||||||
Reference in New Issue
Block a user