Skip to content

Commit a019ad3

Browse files
committed
Update from the sky
1 parent 8bd7ad3 commit a019ad3

18 files changed

+92
-63
lines changed

components/Docs/NavGroup.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export const NavGroup: React.FunctionComponent<INavGroupProps> = ({
1717
const router = useRouter();
1818

1919
const getLinks = React.useMemo(() => {
20-
const { content } = item;
21-
const links = Array.from(content.matchAll(/^## (.*$)/gim));
20+
const { links } = item;
2221

2322
const crntWeight = item.weight || 99;
2423
const subItems = items.filter(i => i.weight && i.weight > crntWeight && i.weight < crntWeight + 1);
@@ -29,12 +28,12 @@ export const NavGroup: React.FunctionComponent<INavGroupProps> = ({
2928

3029
return (
3130
<ul className={`mt-2 space-y-2`}>
32-
{links.map((link, index) => {
31+
{(links && links.length > 0) && links.map((link, index) => {
3332
return (
3433
<li key={index}>
3534
<Link
36-
title={link[1]}
37-
link={`/docs/${item.slug !== "index" ? item.slug : ''}#${link[1].toLowerCase().replace(/\s/g, '-')}`}
35+
title={link}
36+
link={`/docs/${item.slug !== "index" ? item.slug : ''}#${link.toLowerCase().replace(/\s/g, '-')}`}
3837
/>
3938
</li>
4039
);

components/Link/ParentLink.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ChevronDownIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
22
import { useRouter } from 'next/router';
3-
import { default as NextLink } from 'next/link';
43
import * as React from 'react';
54
import { useEffect, useMemo, useState } from 'react';
65
import { PageFrontMatter } from '../../models/PageFrontMatter';
@@ -18,12 +17,11 @@ export const ParentLink: React.FunctionComponent<IParentLinkProps> = ({ title, l
1817
const [showChildren, setShowChildren] = useState(false);
1918

2019
const links = useMemo(() => {
21-
const { content } = item;
22-
const matches = Array.from(content.matchAll(/^## (.*$)/gim));
23-
return matches.map(match => ({
24-
title: match[1],
25-
link: match[1].toLowerCase().replace(/\s/g, '-'),
26-
relPath: `/docs/${item.slug !== "index" ? item.slug : ''}#${match[1].toLowerCase().replace(/\s/g, '-')}`
20+
const { links } = item;
21+
return links.map(match => ({
22+
title: match,
23+
link: match.toLowerCase().replace(/\s/g, '-'),
24+
relPath: `/docs/${item.slug !== "index" ? item.slug : ''}#${match.toLowerCase().replace(/\s/g, '-')}`
2725
}));
2826
}, [item]);
2927

@@ -47,8 +45,7 @@ export const ParentLink: React.FunctionComponent<IParentLinkProps> = ({ title, l
4745
};
4846

4947
useEffect(() => {
50-
const { content } = item;
51-
const links = Array.from(content.matchAll(/^## (.*$)/gim));
48+
const { links } = item;
5249
if (links && links.length > 0) {
5350
setHasChildren(true);
5451
return;

components/Link/Section.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ export const Section: React.FunctionComponent<React.PropsWithChildren<ISectionPr
2121

2222
useEffect(() => {
2323
const page = router.asPath;
24-
console.log(page, link);
2524
// Remove the last slash
2625
const crntLink = link.endsWith('/') ? link.slice(0, -1) : link;
27-
console.log(page, crntLink);
2826
setIsActive(page === crntLink || crntLink === `${page}/` || page.includes(`${crntLink}#`) || page.includes(`${crntLink}index`));
2927

3028
if (crntLink.split('/').length > 2) {

models/PageFrontMatter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ export interface PageFrontMatter {
44
description: string;
55
date: string;
66
lastmod: string;
7-
content: string;
7+
links: string[];
88
fileName: string;
99
weight?: number;
10-
}
10+
content?: string;
11+
}

pages/docs/[...slug].tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
66
import { Page } from '../../components/Docs/Page';
77
import { Markdown } from '../../components/Docs/Markdown';
88
import { DocsLayout } from '../../components/Page/DocsLayout';
9+
import { pageProcessing } from '../../utils/pageProcessing';
910

1011
export default function Documentation({ page, pages, title }: any) {
1112
const { t: strings } = useTranslation();
@@ -20,7 +21,7 @@ export default function Documentation({ page, pages, title }: any) {
2021
<Title value={page.title} />
2122
<Description value={page.description || strings(`documentation_description`)} />
2223
<OtherMeta image={`/assets/frontmatter-social.png`} />
23-
24+
2425
<DocsLayout navItems={pages} >
2526
<Page items={pages} page={page}>
2627
<Markdown content={page?.content} slug={page.slug.replace(/\//g, '-')} />
@@ -40,7 +41,7 @@ export async function getStaticProps({ params }: any) {
4041
'weight',
4142
'content',
4243
'fileName'
43-
]);
44+
]).map(pageProcessing);
4445

4546
const article: any = pages.find((b: any) => b.slug === params.slug.join('/'));
4647

pages/docs/index.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,28 @@ import { Description, OtherMeta, Title } from '../../components/Meta';
66
import { DocsLayout } from '../../components/Page/DocsLayout';
77
import { getAllPosts } from '../../lib/api';
88
import { PageFrontMatter } from '../../models/PageFrontMatter';
9+
import { pageProcessing } from '../../utils/pageProcessing';
910

10-
export default function Home({ pages }: { pages: PageFrontMatter[] }) {
11+
export default function Home({ pages, page }: { pages: PageFrontMatter[]; page: PageFrontMatter; }) {
1112
const { t: strings } = useTranslation();
1213

13-
const welcome = pages?.find(p => p.slug === "index");
14-
1514
return (
1615
<>
1716
<Title value={strings(`documentation_title`)} />
1817
<Description value={strings(`documentation_description`)} />
1918
<OtherMeta image={`/assets/frontmatter-social.png`} />
2019

2120
<DocsLayout navItems={pages} >
22-
<Page items={pages} page={welcome}>
23-
<Markdown content={welcome?.content} slug={welcome?.slug} />
21+
<Page items={pages} page={page}>
22+
<Markdown content={page?.content} slug={page?.slug} />
2423
</Page>
2524
</DocsLayout>
2625
</>
2726
)
2827
}
2928

3029
export const getStaticProps = async () => {
31-
const pages = getAllPosts('docs', [
30+
let pages = getAllPosts('docs', [
3231
'title',
3332
'slug',
3433
'description',
@@ -39,7 +38,11 @@ export const getStaticProps = async () => {
3938
'fileName'
4039
]);
4140

41+
const welcome = Object.assign({}, pages?.find(p => p.slug === "index"));
42+
43+
pages = pages.map(pageProcessing);
44+
4245
return {
43-
props: { pages },
46+
props: { pages, page: welcome },
4447
}
4548
}

public/config/content.pagefolders.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.pagefolders.schema.json",
44
"description": "Defines the settings for Front Matter page folder",
5-
"lastModified": "2023-11-12T01:41:30.154Z",
5+
"lastModified": "2023-11-12T03:21:43.077Z",
66
"type": "object",
77
"title": "Front Matter - page folder",
88
"properties": {

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-11-12T01:41:30.154Z",
5+
"lastModified": "2023-11-12T03:21:43.078Z",
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-11-12T01:41:30.154Z",
5+
"lastModified": "2023-11-12T03:21:43.079Z",
66
"type": "object",
77
"title": "Front Matter - snippet",
88
"required": [

public/config/custom.scripts.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/custom.scripts.schema.json",
44
"description": "Defines the settings for Front Matter custom script",
5-
"lastModified": "2023-11-12T01:41:30.154Z",
5+
"lastModified": "2023-11-12T03:21:43.077Z",
66
"type": "object",
77
"title": "Front Matter - custom script",
88
"properties": {

0 commit comments

Comments
 (0)