mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-07 16:06:12 +02:00
feat: standarize titles
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import pipe from "ramda/es/pipe"
|
|
||||||
import React from "react"
|
import React from "react"
|
||||||
|
|
||||||
import ChevronUp from "../../icons/chevron-up.svg"
|
import ChevronUp from "../../icons/chevron-up.svg"
|
||||||
import { traversePaths } from "../../utils"
|
import { humanize, traversePaths } from "../../utils"
|
||||||
import { IFileOrFolder } from "../ResourcesSidebar/index"
|
import { IFileOrFolder } from "../ResourcesSidebar/index"
|
||||||
import * as SC from "./styles"
|
import * as SC from "./styles"
|
||||||
|
|
||||||
@@ -10,24 +9,6 @@ interface IResourceBreadcrumbProps {
|
|||||||
relativePath: any
|
relativePath: any
|
||||||
}
|
}
|
||||||
|
|
||||||
function capitalize(str: string): string {
|
|
||||||
return str
|
|
||||||
.split(" ")
|
|
||||||
.map(word => `${word.charAt(0).toUpperCase()}${word.substring(1)}`)
|
|
||||||
.join(" ")
|
|
||||||
}
|
|
||||||
|
|
||||||
function dashToSpace(str: string): string {
|
|
||||||
return str.replace("-", " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
function humanize(str: string): string {
|
|
||||||
return pipe(
|
|
||||||
dashToSpace,
|
|
||||||
capitalize
|
|
||||||
)(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Link({ item }: { item: IFileOrFolder }) {
|
function Link({ item }: { item: IFileOrFolder }) {
|
||||||
return <SC.StyledLink to={item.path}>{humanize(item.title)}</SC.StyledLink>
|
return <SC.StyledLink to={item.path}>{humanize(item.title)}</SC.StyledLink>
|
||||||
}
|
}
|
||||||
@@ -51,7 +32,7 @@ export function ResourceBreadcrumb({ relativePath }: IResourceBreadcrumbProps) {
|
|||||||
<SC.ResourceBreadcrumbWrapper>
|
<SC.ResourceBreadcrumbWrapper>
|
||||||
<SC.LinkWrapper>
|
<SC.LinkWrapper>
|
||||||
<Link
|
<Link
|
||||||
item={{ path: "/", title: "Home", type: "folder", children: [] }}
|
item={{ path: "/", title: "home", type: "folder", children: [] }}
|
||||||
/>
|
/>
|
||||||
<ChevronUp />
|
<ChevronUp />
|
||||||
</SC.LinkWrapper>
|
</SC.LinkWrapper>
|
||||||
@@ -59,7 +40,7 @@ export function ResourceBreadcrumb({ relativePath }: IResourceBreadcrumbProps) {
|
|||||||
<Link
|
<Link
|
||||||
item={{
|
item={{
|
||||||
path: "/resources",
|
path: "/resources",
|
||||||
title: "Resources",
|
title: "resources",
|
||||||
type: "folder",
|
type: "folder",
|
||||||
children: [],
|
children: [],
|
||||||
}}
|
}}
|
||||||
@@ -76,7 +57,11 @@ export function ResourceBreadcrumb({ relativePath }: IResourceBreadcrumbProps) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <SC.CurrentPage key={item.path}>{item.title}</SC.CurrentPage>
|
return (
|
||||||
|
<SC.CurrentPage key={item.path}>
|
||||||
|
{humanize(item.title)}
|
||||||
|
</SC.CurrentPage>
|
||||||
|
)
|
||||||
})}
|
})}
|
||||||
</SC.ResourceBreadcrumbWrapper>
|
</SC.ResourceBreadcrumbWrapper>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { graphql, useStaticQuery } from "gatsby"
|
|||||||
import React, { memo } from "react"
|
import React, { 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/index"
|
||||||
import * as SC from "./styles"
|
import * as SC from "./styles"
|
||||||
import useBuildTree from "./useBuildTree"
|
import useBuildTree from "./useBuildTree"
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ function plantTree(item: IFileOrFolder, index?: number) {
|
|||||||
<SC.PageLink key={item.title} to={item.path}>
|
<SC.PageLink key={item.title} to={item.path}>
|
||||||
{cleanedUpPath.map(node => (
|
{cleanedUpPath.map(node => (
|
||||||
// TODO: use helper to format path
|
// TODO: use helper to format path
|
||||||
<SC.NodePart key={node}>{node.replace(".md", "")}</SC.NodePart>
|
<SC.NodePart key={node}>{humanize(node)}</SC.NodePart>
|
||||||
))}
|
))}
|
||||||
</SC.PageLink>
|
</SC.PageLink>
|
||||||
)
|
)
|
||||||
@@ -44,7 +45,7 @@ function plantTree(item: IFileOrFolder, index?: number) {
|
|||||||
const Language = memo(({ item }: { item: IFolder; index: number }) => {
|
const Language = memo(({ item }: { item: IFolder; index: number }) => {
|
||||||
return (
|
return (
|
||||||
<SC.TreeWrapper>
|
<SC.TreeWrapper>
|
||||||
<SC.LanguageLabel>{item.title}</SC.LanguageLabel>
|
<SC.LanguageLabel>{humanize(item.title)}</SC.LanguageLabel>
|
||||||
<SC.Children>{item.children.map(node => plantTree(node))}</SC.Children>
|
<SC.Children>{item.children.map(node => plantTree(node))}</SC.Children>
|
||||||
</SC.TreeWrapper>
|
</SC.TreeWrapper>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import "react-perfect-scrollbar/dist/css/styles.css"
|
|||||||
import TriangleDown from "../../icons/triangle-down.svg"
|
import TriangleDown from "../../icons/triangle-down.svg"
|
||||||
import Banner from "../../images/tph-banner.svg"
|
import Banner from "../../images/tph-banner.svg"
|
||||||
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
|
import { IAllResourcesQuery, IFileOrFolder, IFolder } from "../../types"
|
||||||
|
import { humanize } from "../../utils"
|
||||||
import { ThemeToggler } from "../ThemeToggler"
|
import { ThemeToggler } from "../ThemeToggler"
|
||||||
import useSidebar from "./../../hooks/useSidebar"
|
import useSidebar from "./../../hooks/useSidebar"
|
||||||
import * as SC from "./styles"
|
import * as SC from "./styles"
|
||||||
@@ -33,7 +34,7 @@ function plantTree(item: IFileOrFolder, index?: number, firstLevel?: boolean) {
|
|||||||
if (item.type === "file") {
|
if (item.type === "file") {
|
||||||
return (
|
return (
|
||||||
<SC.PageLink key={item.title} to={item.path} activeClassName="active">
|
<SC.PageLink key={item.title} to={item.path} activeClassName="active">
|
||||||
{item.title}
|
{humanize(item.title)}
|
||||||
</SC.PageLink>
|
</SC.PageLink>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -55,7 +56,7 @@ function Folder({ item }: { item: IFolder }) {
|
|||||||
return (
|
return (
|
||||||
<SC.TreeWrapper collapsed={collapsed}>
|
<SC.TreeWrapper collapsed={collapsed}>
|
||||||
<SC.Label onClick={toggleCollapse}>
|
<SC.Label onClick={toggleCollapse}>
|
||||||
<TriangleDown /> {item.title}
|
<TriangleDown /> {humanize(item.title)}
|
||||||
</SC.Label>
|
</SC.Label>
|
||||||
<SC.Children>{item.children.map(node => plantTree(node))}</SC.Children>
|
<SC.Children>{item.children.map(node => plantTree(node))}</SC.Children>
|
||||||
</SC.TreeWrapper>
|
</SC.TreeWrapper>
|
||||||
@@ -73,7 +74,7 @@ const FirstLevelFolder = memo(
|
|||||||
className={!collapsed ? "active" : undefined}
|
className={!collapsed ? "active" : undefined}
|
||||||
onClick={() => setCurrent(index)}
|
onClick={() => setCurrent(index)}
|
||||||
>
|
>
|
||||||
{item.title}
|
{humanize(item.title)}
|
||||||
<SC.CollapseToggler />
|
<SC.CollapseToggler />
|
||||||
</SC.FirstLabel>
|
</SC.FirstLabel>
|
||||||
<SC.Children>{item.children.map(node => plantTree(node))}</SC.Children>
|
<SC.Children>{item.children.map(node => plantTree(node))}</SC.Children>
|
||||||
|
|||||||
@@ -1,8 +1,35 @@
|
|||||||
import chain from "ramda/es/chain"
|
import chain from "ramda/es/chain"
|
||||||
import partition from "ramda/es/partition"
|
import partition from "ramda/es/partition"
|
||||||
|
import pipe from "ramda/es/pipe"
|
||||||
|
|
||||||
import { IFile, IFileOrFolder, IFolder } from "../types"
|
import { IFile, IFileOrFolder, IFolder } from "../types"
|
||||||
|
|
||||||
|
function specificWordsToUpper(str: string): string {
|
||||||
|
const wordsToUpper = ["pdo", "c"]
|
||||||
|
const toUpper = (word: string) =>
|
||||||
|
wordsToUpper.includes(word.toLowerCase()) ? word.toUpperCase() : word
|
||||||
|
return str
|
||||||
|
.split(" ")
|
||||||
|
.map(toUpper)
|
||||||
|
.join(" ")
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeDotMD(str: string): string {
|
||||||
|
return str.replace(".md", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
function dashToSpace(str: string): string {
|
||||||
|
return str.replace(/-/g, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function humanize(str: string): string {
|
||||||
|
return pipe(
|
||||||
|
dashToSpace,
|
||||||
|
specificWordsToUpper,
|
||||||
|
removeDotMD
|
||||||
|
)(str)
|
||||||
|
}
|
||||||
|
|
||||||
export function traversePaths(
|
export function traversePaths(
|
||||||
[head, ...tail]: string[],
|
[head, ...tail]: string[],
|
||||||
basePath: string = "/resources"
|
basePath: string = "/resources"
|
||||||
|
|||||||
Reference in New Issue
Block a user