Skip to content

Commit 0a3cdd4

Browse files
committed
Updated navigation
1 parent ea78731 commit 0a3cdd4

14 files changed

+227
-90
lines changed

components/Docs/NavGroup.tsx

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

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: 34 additions & 9 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,46 @@ 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>> = ({ title, link, children }: React.PropsWithChildren<ISectionProps>) => {
1213
const router = useRouter();
1314
const [isActive, setIsActive] = React.useState(false);
15+
const [showChildren, setShowChildren] = React.useState<boolean | undefined>(undefined);
1416

1517
useEffect(() => {
1618
const page = router.asPath;
1719
setIsActive(page === link || link === `${page}/` || page.includes(`${link}#`) || page.includes(`${link}index`));
1820
}, [router.asPath, link]);
19-
21+
2022
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>
23+
<>
24+
<div className='flex justify-between mb-3 lg:mb-3'>
25+
<Link
26+
href={link}
27+
title={title}
28+
className={`uppercase tracking-wide font-semibold text-sm ${isActive ? "text-teal-500" : "text-whisper-500"} hover:text-teal-900`}
29+
>
30+
{title}
31+
</Link>
32+
33+
<button
34+
title={`Show children of ${title.toLowerCase()}`}
35+
onClick={() => setShowChildren(prev => !prev)} >
36+
{
37+
((isActive && typeof showChildren === "undefined") || showChildren) ? (
38+
<ChevronDownIcon className='h-4' />
39+
) : (
40+
<ChevronRightIcon className='h-4' />
41+
)
42+
}
43+
</button>
44+
</div>
45+
46+
{
47+
(
48+
(isActive && typeof showChildren === "undefined") ||
49+
(showChildren && typeof showChildren !== "undefined")
50+
) && children
51+
}
52+
</>
2853
);
2954
};

content/changelog/CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# Change Log
22

3-
## [9.3.0] - 2023-xx-xx - [Release notes](https://beta.frontmatter.codes/updates/v9.3.0)
3+
## [9.4.0] - 2023-xx-xx
4+
5+
### ✨ New features
6+
7+
### 🎨 Enhancements
8+
9+
- [#686](https://github.com/estruyf/vscode-front-matter/issues/686): Allow script authors to ask questions during script execution
10+
- [#688](https://github.com/estruyf/vscode-front-matter/issues/688): Allow to show the scheduled articles in the content dashboard (filter and group)
11+
12+
### ⚡️ Optimizations
13+
14+
- Dashboard layout grid optimizations
15+
16+
### 🐞 Fixes
17+
18+
- [#685](https://github.com/estruyf/vscode-front-matter/issues/685): Fix when using non-string values in the tag picker
19+
- [#691](https://github.com/estruyf/vscode-front-matter/issues/691): Silent authentication retrieval for GitHub sponsors
20+
21+
## [9.3.0] - 2023-10-06 - [Release notes](https://beta.frontmatter.codes/updates/v9.3.0)
422

523
### ✨ New features
624

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:09:01.211Z",
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:09:01.211Z",
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:09:01.212Z",
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:09:01.211Z",
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:09:01.211Z",
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:09:01.211Z",
66
"type": "object",
77
"title": "Front Matter - data folder",
88
"properties": {

0 commit comments

Comments
 (0)