Skip to content

Commit

Permalink
Rename getTree function
Browse files Browse the repository at this point in the history
  • Loading branch information
cdedreuille committed Jul 11, 2024
1 parent 02ea13f commit 6b3f9cc
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions apps/frontpage/app/docs-all/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MetadataRoute } from 'next';
import { generateDocsTree } from '../../lib/get-tree';
import { getDocsTreeFromPath } from '../../lib/get-docs-tree-from-path';
import { docsVersions } from '@repo/utils';
import {
FlatTreeNode,
Expand All @@ -12,7 +12,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
const listofTrees = docsVersions.map((version) => {
return {
version: version,
tree: generateDocsTree(`content/docs/${version.id}`),
tree: getDocsTreeFromPath(`content/docs/${version.id}`),
};
});

Expand Down
10 changes: 5 additions & 5 deletions apps/frontpage/app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { latestVersion, cn } from '@repo/utils';
import { getVersion } from '../../../lib/get-version';
import { getPageData } from '../../../lib/get-page';
import { Renderers } from '../../../components/docs/renderers';
import { generateDocsTree } from '../../../lib/get-tree';
import { getDocsTreeFromPath } from '../../../lib/get-docs-tree-from-path';
import { DocsFooter } from '../../../components/docs/footer/footer';
import { Metadata } from 'next';
import { TableOfContent } from '../../../components/docs/table-of-content';
Expand Down Expand Up @@ -37,7 +37,7 @@ const latestVersionId = latestVersion.id;

export const generateStaticParams = () => {
const result: { slug: string[] }[] = [];
const tree = generateDocsTree();
const tree = getDocsTreeFromPath();

const getSlugs = (data: TreeProps[]) => {
data.forEach((item) => {
Expand Down Expand Up @@ -86,10 +86,10 @@ export default async function Page({ params: { slug } }: PageProps) {

return (
<>
<div className="flex-1 w-full min-w-0 py-12">
<div className="w-full min-w-0 flex-1 py-12">
<main className="mx-auto max-w-[720px]">
{!isLatest && (
<div className="flex flex-col items-start gap-4 p-4 mb-8 text-sm text-red-900 bg-red-200 rounded-md md:flex-row md:items-center md:justify-between md:gap-6 md:py-3 md:pl-5 md:pr-3">
<div className="mb-8 flex flex-col items-start gap-4 rounded-md bg-red-200 p-4 text-sm text-red-900 md:flex-row md:items-center md:justify-between md:gap-6 md:py-3 md:pl-5 md:pr-3">
You are viewing documentation for a previous version of Storybook
<Link
href="/docs"
Expand All @@ -100,7 +100,7 @@ export default async function Page({ params: { slug } }: PageProps) {
</div>
)}
<h1
className="relative mt-0 mb-6 text-4xl font-bold text-black transition-colors duration-200 group-hover:text-blue-500 dark:text-white"
className="relative mb-6 mt-0 text-4xl font-bold text-black transition-colors duration-200 group-hover:text-blue-500 dark:text-white"
data-docs-heading
>
{page.title || 'Title is missing'}
Expand Down
7 changes: 3 additions & 4 deletions apps/frontpage/app/docs/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { Header, Footer, Container } from '@repo/ui';
import Image from 'next/image';
import { fetchGithubCount } from '@repo/utils';
import { Sidebar } from '../../components/docs/sidebar/sidebar';
import { TableOfContent } from '../../components/docs/table-of-content';
import { NavDocs } from '../../components/docs/sidebar/docs-nav';
import { generateDocsTree } from '../../lib/get-tree';
import { getDocsTreeFromPath } from '../../lib/get-docs-tree-from-path';
import { DocsProvider } from './provider';
import { Submenu } from '../../components/docs/submenu';
import { DocsMainNav } from '../../components/docs/sidebar/docs-main-nav';
Expand All @@ -18,7 +17,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
const listofTrees = docsVersions.map((version) => {
return {
version: version.id,
tree: generateDocsTree(`content/docs/${version.id}`),
tree: getDocsTreeFromPath(`content/docs/${version.id}`),
};
});

Expand All @@ -31,7 +30,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
/>
<Image
alt="Storybook Docs"
className="absolute top-0 left-0 w-full -z-10"
className="absolute left-0 top-0 -z-10 w-full"
height={339}
priority
src="/bubbles.png"
Expand Down
4 changes: 2 additions & 2 deletions apps/frontpage/app/docs/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MetadataRoute } from 'next';
import { generateDocsTree } from '../../lib/get-tree';
import { getDocsTreeFromPath } from '../../lib/get-docs-tree-from-path';
import { docsVersions } from '@repo/utils';
import { getUrl } from '../../lib/get-url';
import { getFlatTreeSitemap } from '../../lib/get-flat-tree-sitemap';
Expand All @@ -8,7 +8,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
const latestVersion = docsVersions[0];

// Generate docs tree for the latest version only
const tree = generateDocsTree(`content/docs/${latestVersion.id}`);
const tree = getDocsTreeFromPath(`content/docs/${latestVersion.id}`);

// We flatten the tree
const flatTree = getFlatTreeSitemap(tree);
Expand Down
4 changes: 2 additions & 2 deletions apps/frontpage/components/docs/footer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { z } from 'zod';
import type { TreeProps } from '@repo/utils';
import { docsVersions } from '@repo/utils';
import { buildPathWithVersion } from '../../../lib/build-path-with-version';
import { generateDocsTree } from '../../../lib/get-tree';
import { getDocsTreeFromPath } from '../../../lib/get-docs-tree-from-path';

const siteUrl = process.env.VERCEL_ENV === 'production';

Expand Down Expand Up @@ -37,7 +37,7 @@ function addSlugs(tree: TreeProps[]) {
}

versions.forEach((v) => {
const tree = generateDocsTree(`content/docs/${v}`);
const tree = getDocsTreeFromPath(`content/docs/${v}`);
addSlugs(tree);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ function shouldParse(fileOrPath: string) {
return !fileOrPath.endsWith('/versions');
}

export const generateDocsTree = (pathToFiles?: string, docsRoot?: string) => {
export const getDocsTreeFromPath = (
pathToFiles?: string,
docsRoot?: string,
) => {
const newPath = pathToFiles || 'content/docs';
const newDocsRoot = docsRoot || newPath;

Expand All @@ -40,7 +43,7 @@ export const generateDocsTree = (pathToFiles?: string, docsRoot?: string) => {
const isDirectory = fs.lstatSync(filePath).isDirectory();

if (isDirectory) {
const childItems = generateDocsTree(filePath, newDocsRoot);
const childItems = getDocsTreeFromPath(filePath, newDocsRoot);

if (childItems) {
const indexFile = childItems.find(
Expand Down
4 changes: 2 additions & 2 deletions apps/frontpage/lib/get-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Video,
YouTubeCallout,
} from '../components/docs/mdx';
import { generateDocsTree } from './get-tree';
import { getDocsTreeFromPath } from './get-docs-tree-from-path';

export const getPageData = async (
path: string[],
Expand Down Expand Up @@ -91,7 +91,7 @@ export const getPageData = async (
? `${rootPath}/${pathString}`.split('/').slice(0, -1).join('/')
: `${rootPath}/${pathString}`;

const parent = generateDocsTree(pathToFiles);
const parent = getDocsTreeFromPath(pathToFiles);

const sorted = parent.sort((a, b) =>
a.tab?.order && b.tab?.order ? a.tab.order - b.tab.order : 0,
Expand Down

0 comments on commit 6b3f9cc

Please sign in to comment.