Skip to content

Commit f5baa4c

Browse files
committed
Merge branch 'main' of github.com:FrontMatter/web-documentation-nextjs
2 parents 87ab4f2 + 043b15d commit f5baa4c

14 files changed

+232
-92
lines changed

components/Docs/CodeHighlighting.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ export const CodeHighlighting: React.FunctionComponent<ICodeHighlightingProps> =
8383

8484
shiki.setCDN(`../../`);
8585

86-
console.log(language);
87-
8886
shiki.getHighlighter({
8987
langs: [language as any],
9088
theme: `the-unnamed`

components/Docs/NavGroup.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import * as React from 'react';
2+
import { Section } from '../Link/Section';
3+
import { PageFrontMatter } from '../../models';
4+
import { Link } from '../Link/Link';
5+
import { ParentLink } from '../Link/ParentLink';
6+
import { useRouter } from 'next/router';
7+
8+
export interface INavGroupProps {
9+
items: PageFrontMatter[];
10+
item: PageFrontMatter;
11+
}
12+
13+
export const NavGroup: React.FunctionComponent<INavGroupProps> = ({
14+
items,
15+
item
16+
}: React.PropsWithChildren<INavGroupProps>) => {
17+
const router = useRouter();
18+
19+
const getLinks = React.useMemo(() => {
20+
const { content } = item;
21+
const links = Array.from(content.matchAll(/^## (.*$)/gim));
22+
23+
const crntWeight = item.weight || 99;
24+
const subItems = items.filter(i => i.weight && i.weight > crntWeight && i.weight < crntWeight + 1);
25+
26+
if ((!links || links.length === 0) && (!subItems || subItems.length === 0)) {
27+
return null;
28+
}
29+
30+
return (
31+
<ul className={`mt-2 space-y-2`}>
32+
{links.map((link, index) => {
33+
return (
34+
<li key={index}>
35+
<Link
36+
title={link[1]}
37+
link={`/docs/${item.slug !== "index" ? item.slug : ''}#${link[1].toLowerCase().replace(/\s/g, '-')}`}
38+
/>
39+
</li>
40+
);
41+
})}
42+
43+
{subItems.map((subItem) => (
44+
<li key={subItem.slug} className={`group`}>
45+
<ParentLink
46+
title={subItem.title}
47+
link={`/docs/${subItem.slug}`}
48+
item={subItem}
49+
/>
50+
</li>
51+
))}
52+
</ul>
53+
);
54+
}, [item, items, router.asPath]);
55+
56+
return (
57+
<Section
58+
title={item.title}
59+
link={`/docs/${item.slug !== "index" ? item.slug : ''}`}>
60+
{getLinks}
61+
</Section>
62+
);
63+
};

components/Docs/Sidebar.tsx

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as React from 'react';
22
import { PageFrontMatter } from '../../models/PageFrontMatter';
3-
import { Link } from '../Link/Link';
4-
import { ParentLink } from '../Link/ParentLink';
5-
import { Section } from '../Link/Section';
3+
import { NavGroup } from './NavGroup';
64

75
export interface ISidebarProps {
86
items: PageFrontMatter[];
@@ -16,49 +14,14 @@ export const Sidebar: React.FunctionComponent<ISidebarProps> = ({ items, classNa
1614
// Retrieve only the root sections, not the sub-sections
1715
sorted = sorted.filter((item) => (item.weight || 99) % 1 === 0);
1816

19-
const getLinks = (item: PageFrontMatter) => {
20-
const { content } = item;
21-
const links = Array.from(content.matchAll(/^## (.*$)/gim));
22-
23-
const crntWeight = item.weight || 99;
24-
const subItems = items.filter(i => i.weight && i.weight > crntWeight && i.weight < crntWeight + 1);
25-
26-
if ((!links || links.length === 0) && (!subItems || subItems.length === 0)) {
27-
return null;
28-
}
29-
30-
return (
31-
<ul className={`mt-2 space-y-2`}>
32-
{links.map((link, index) => (
33-
<li key={index}>
34-
<Link
35-
title={link[1]}
36-
link={`/docs/${item.slug !== "index" ? item.slug : ''}#${link[1].toLowerCase().replace(/\s/g, '-')}`}
37-
/>
38-
</li>
39-
))}
40-
41-
{subItems.map((subItem, index) => (
42-
<li key={subItem.slug} className={`group`}>
43-
<ParentLink
44-
title={subItem.title}
45-
link={`/docs/${subItem.slug}`}
46-
item={subItem}
47-
/>
48-
</li>
49-
))}
50-
</ul>
51-
);
52-
}
53-
5417
return (
5518
<nav role={`navigation`} className={className || ""}>
5619
{sorted.map((item, index) => {
5720
return (
5821
<div key={index}>
59-
<Section title={item.title} link={`/docs/${item.slug !== "index" ? item.slug : ''}`} />
60-
61-
{getLinks(item)}
22+
<NavGroup
23+
items={items}
24+
item={item} />
6225
</div>
6326
);
6427
})}

components/Link/Section.tsx

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ChevronDownIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
12
import Link from 'next/link';
23
import { useRouter } from 'next/router';
34
import * as React from 'react';
@@ -8,22 +9,64 @@ export interface ISectionProps {
89
link: string;
910
}
1011

11-
export const Section: React.FunctionComponent<ISectionProps> = ({title, link}: React.PropsWithChildren<ISectionProps>) => {
12+
export const Section: React.FunctionComponent<React.PropsWithChildren<ISectionProps>> = ({
13+
title,
14+
link,
15+
children
16+
}: React.PropsWithChildren<ISectionProps>) => {
1217
const router = useRouter();
1318
const [isActive, setIsActive] = React.useState(false);
19+
const [showChildren, setShowChildren] = React.useState<boolean | undefined>(undefined);
20+
const [hasActiveLink, setHasActiveLink] = React.useState<boolean | undefined>(undefined);
1421

1522
useEffect(() => {
1623
const page = router.asPath;
17-
setIsActive(page === link || link === `${page}/` || page.includes(`${link}#`) || page.includes(`${link}index`));
24+
console.log(page, link);
25+
// Remove the last slash
26+
const crntLink = link.endsWith('/') ? link.slice(0, -1) : link;
27+
console.log(page, crntLink);
28+
setIsActive(page === crntLink || crntLink === `${page}/` || page.includes(`${crntLink}#`) || page.includes(`${crntLink}index`));
29+
30+
if (crntLink.split('/').length > 2) {
31+
setHasActiveLink(page.includes(crntLink))
32+
}
1833
}, [router.asPath, link]);
19-
34+
2035
return (
21-
<Link
22-
href={link}
23-
title={title}
24-
className={`mb-3 lg:mb-3 uppercase tracking-wide font-semibold text-sm ${isActive ? "text-teal-500" : "text-whisper-500"} hover:text-teal-900`}
25-
>
26-
{title}
27-
</Link>
36+
<>
37+
<div className='flex justify-between mb-3 lg:mb-3'>
38+
<Link
39+
href={link}
40+
title={title}
41+
className={`uppercase tracking-wide font-semibold text-sm ${isActive ? "text-teal-500" : "text-whisper-500"} hover:text-teal-900`}
42+
>
43+
{title}
44+
</Link>
45+
46+
<button
47+
title={`Show children of ${title.toLowerCase()}`}
48+
onClick={() => setShowChildren(prev => !prev)} >
49+
{
50+
(
51+
(isActive && typeof showChildren === "undefined") ||
52+
(hasActiveLink && typeof showChildren === "undefined") ||
53+
showChildren
54+
) ? (
55+
<ChevronDownIcon className='h-4' />
56+
) : (
57+
<ChevronRightIcon className='h-4' />
58+
)
59+
}
60+
</button>
61+
</div>
62+
63+
{
64+
(
65+
(isActive && typeof showChildren === "undefined") ||
66+
(hasActiveLink && typeof showChildren === "undefined") ||
67+
(showChildren && typeof showChildren !== "undefined")
68+
) && children
69+
}
70+
</>
2871
);
2972
};

public/config/content.pagefolders.schema.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/content.pagefolders.schema.json",
44
"description": "Defines the settings for Front Matter page folder",
5-
"lastModified": "2023-09-14T10:40:53.199Z",
5+
"lastModified": "2023-10-24T09:28:57.205Z",
66
"type": "object",
77
"title": "Front Matter - page folder",
88
"properties": {
@@ -40,6 +40,11 @@
4040
"items": {
4141
"type": "string"
4242
}
43+
},
44+
"disableCreation": {
45+
"type": "boolean",
46+
"default": false,
47+
"description": "Disable the creation of new content in the folder."
4348
}
4449
},
4550
"required": [

public/config/content.placeholders.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/content.placeholders.schema.json",
44
"description": "Defines the settings for Front Matter placeholder",
5-
"lastModified": "2023-09-14T10:40:53.199Z",
5+
"lastModified": "2023-10-24T09:28:57.206Z",
66
"type": "object",
77
"title": "Front Matter - placeholder",
88
"properties": {

public/config/content.snippets.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/content.snippets.schema.json",
44
"description": "Defines the settings for Front Matter snippet",
5-
"lastModified": "2023-09-14T10:40:53.199Z",
5+
"lastModified": "2023-10-24T09:28:57.206Z",
66
"type": "object",
77
"title": "Front Matter - snippet",
88
"required": [

public/config/custom.scripts.schema.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/custom.scripts.schema.json",
44
"description": "Defines the settings for Front Matter custom script",
5-
"lastModified": "2023-09-14T10:40:53.198Z",
5+
"lastModified": "2023-10-24T09:28:57.205Z",
66
"type": "object",
77
"title": "Front Matter - custom script",
88
"properties": {
@@ -96,6 +96,13 @@
9696
}
9797
}
9898
}
99+
},
100+
"contentTypes": {
101+
"type": "array",
102+
"description": "Define the content types for which the script will be used. If none are defined, it will be available to all types.",
103+
"items": {
104+
"type": "string"
105+
}
99106
}
100107
},
101108
"required": [

public/config/data.files.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/data.files.schema.json",
44
"description": "Defines the settings for Front Matter data file",
5-
"lastModified": "2023-09-14T10:40:53.199Z",
5+
"lastModified": "2023-10-24T09:28:57.206Z",
66
"type": "object",
77
"title": "Front Matter - data file",
88
"properties": {

public/config/data.folders.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$id": "https://beta.frontmatter.codes/config/data.folders.schema.json",
44
"description": "Defines the settings for Front Matter data folder",
5-
"lastModified": "2023-09-14T10:40:53.199Z",
5+
"lastModified": "2023-10-24T09:28:57.206Z",
66
"type": "object",
77
"title": "Front Matter - data folder",
88
"properties": {

0 commit comments

Comments
 (0)