Skip to content

Commit b832d42

Browse files
committed
feat: update community tab & gen-term logic
1 parent 312870b commit b832d42

File tree

12 files changed

+165
-55
lines changed

12 files changed

+165
-55
lines changed

website/docusaurus.config.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ const config = {
388388
label: "Community",
389389
position: "left",
390390
menuId: "community",
391-
activeBaseRegex: "/(ecosystem)/(history-and-hard-forks)",
391+
activeBaseRegex: "/(ecosystem|history-and-hard-forks)",
392392
primaryItems: [
393393
{
394394
title: "Projects",
@@ -405,21 +405,51 @@ const config = {
405405
icon: "squareHistory",
406406
activeBaseRegex: "/history-and-hard-forks/",
407407
},
408-
// TODO: Add Resources
408+
{
409+
title: "Contribute",
410+
description: "Ways to participate and support the network",
411+
href: "/docs/ecosystem/contribute",
412+
icon: "squareContribution",
413+
activeBaseRegex: "/ecosystem/contribute",
414+
},
409415
],
410-
otherLabel: "OTHER",
416+
otherLabel: "RESOURCES",
417+
otherCol: 2,
411418
otherItems: [
412419
{
413-
title: "Organizations",
414-
href: "/docs/ecosystem/organizations",
415-
icon: "organization",
416-
activeBaseRegex: "/ecosystem/organizations",
420+
title: "Positioning Paper",
421+
href: "https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0001-positioning/0001-positioning.md",
422+
external: true,
417423
},
418424
{
419-
title: "Contribute",
420-
href: "/docs/ecosystem/contribute",
421-
icon: "contribution",
422-
activeBaseRegex: "/ecosystem/contribute",
425+
title: "CKB RFCs",
426+
href: "https://github.com/nervosnetwork/rfcs",
427+
external: true,
428+
},
429+
{
430+
title: "Fiber Network",
431+
href: "https://www.fiber.world/docs",
432+
external: true,
433+
},
434+
{
435+
title: "Spore Protocol",
436+
href: "https://docs.spore.pro/",
437+
external: true,
438+
},
439+
{
440+
title: "CKB Academy",
441+
href: "https://academy.ckb.dev/",
442+
external: true,
443+
},
444+
{
445+
title: "CKB Cookbook",
446+
href: "https://cookbook.ckbdapps.com/",
447+
external: true,
448+
},
449+
{
450+
title: "CKB Dev Log",
451+
href: "https://github.com/nervosnetwork/ckb/discussions/categories/dev-log",
452+
external: true,
423453
},
424454
],
425455
},

website/scripts/generate-key-terms.mjs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,37 @@ const outputPath = path.join(
1515
__dirname,
1616
"../src/components/Tooltip/key-terms.json"
1717
);
18-
const docsPath = path.join(__dirname, "../docs/tech-explanation");
18+
19+
const docSections = [
20+
{
21+
slug: "tech-explanation",
22+
dir: path.join(__dirname, "../docs/tech-explanation"),
23+
},
24+
{
25+
slug: "ckb-fundamentals",
26+
dir: path.join(__dirname, "../docs/ckb-fundamentals"),
27+
},
28+
{
29+
slug: "assets-token-standards",
30+
dir: path.join(__dirname, "../docs/assets-token-standards"),
31+
},
32+
];
1933

2034
const glossaryContent = fs.readFileSync(glossaryPath, "utf8");
2135
const terms = {};
2236

37+
function resolveTermLink(normalizedTerm) {
38+
for (const section of docSections) {
39+
const md = path.join(section.dir, `${normalizedTerm}.md`);
40+
const mdx = path.join(section.dir, `${normalizedTerm}.mdx`);
41+
if (fs.existsSync(md) || fs.existsSync(mdx)) {
42+
return `/docs/${section.slug}/${normalizedTerm}`;
43+
}
44+
}
45+
// fallback to glossary anchor (same as before)
46+
return `/docs/tech-explanation/glossary#${normalizedTerm}`;
47+
}
48+
2349
remark()
2450
.use(() => (tree) => {
2551
let currentTerm = "";
@@ -59,17 +85,8 @@ remark()
5985
.toLowerCase()
6086
.replace(/[\s_]+/g, "-")
6187
.replace(/[()]/g, "");
62-
const termFilePathMd = path.join(docsPath, `${normalizedTerm}.md`);
63-
const termFilePathMdx = path.join(docsPath, `${normalizedTerm}.mdx`);
64-
if (fs.existsSync(termFilePathMd) || fs.existsSync(termFilePathMdx)) {
65-
terms[
66-
currentTerm.toLowerCase()
67-
].link = `/docs/tech-explanation/${normalizedTerm}`;
68-
} else {
69-
terms[
70-
currentTerm.toLowerCase()
71-
].link = `/docs/tech-explanation/glossary#${normalizedTerm}`;
72-
}
88+
89+
terms[currentTerm.toLowerCase()].link = resolveTermLink(normalizedTerm);
7390
}
7491
});
7592
})

website/sidebars.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export default {
296296
"Tech Explanation": [
297297
{
298298
type: "category",
299-
label: "What makes CKB unique",
299+
label: "What Makes CKB Unique",
300300
className: "category-ckb-features",
301301
collapsible: false,
302302
customProps: {
@@ -476,8 +476,13 @@ export default {
476476
},
477477
{
478478
type: "link",
479-
label: "CKB Dev Log",
480-
href: "https://github.com/nervosnetwork/ckb/discussions/categories/dev-log",
479+
label: "Fiber Network",
480+
href: "https://www.fiber.world/docs",
481+
},
482+
{
483+
type: "link",
484+
label: "Spore Protocol",
485+
href: "https://docs.spore.pro",
481486
},
482487
{
483488
type: "link",
@@ -491,13 +496,8 @@ export default {
491496
},
492497
{
493498
type: "link",
494-
label: "Fiber network",
495-
href: "https://www.fiber.world/docs",
496-
},
497-
{
498-
type: "link",
499-
label: "Spore Protocol",
500-
href: "https://docs.spore.pro",
499+
label: "CKB Dev Log",
500+
href: "https://github.com/nervosnetwork/ckb/discussions/categories/dev-log",
501501
},
502502
],
503503
},

website/src/components/Navbar/MegaMenuNavbarItem/index.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
// src/components/Navbar/MegaMenuNavbarItem.tsx
2-
31
import React, { useEffect, useMemo, useRef, useState } from "react";
42
import clsx from "clsx";
53
import Link from "@docusaurus/Link";
64
import { useLocation } from "@docusaurus/router";
75
import useBaseUrl from "@docusaurus/useBaseUrl";
8-
96
import ChevronDown from "/svg/icon-chevron-down.svg";
107
import { sidebarIconMap, SidebarIconName } from "../../../icons";
118
import styles from "./styles.module.css";
@@ -14,6 +11,7 @@ export type MegaMenuItem = {
1411
title: string;
1512
description?: string;
1613
href: string;
14+
external?: boolean;
1715
icon?: SidebarIconName;
1816
activeBaseRegex?: string;
1917
};
@@ -27,6 +25,7 @@ export type MegaMenuNavbarItemProps = {
2725
primaryItems: MegaMenuItem[];
2826
otherItems?: MegaMenuItem[];
2927
otherLabel?: string;
28+
otherCol?: 1 | 2;
3029
};
3130

3231
const EVENT_NAME = "nervos:megamenu-open";
@@ -39,6 +38,7 @@ const MegaMenuNavbarItem: React.FC<MegaMenuNavbarItemProps> = ({
3938
primaryItems,
4039
otherItems = [],
4140
otherLabel = "OTHER",
41+
otherCol = 1,
4242
}) => {
4343
const location = useLocation();
4444
const [open, setOpen] = useState(false);
@@ -183,15 +183,25 @@ const MegaMenuNavbarItem: React.FC<MegaMenuNavbarItemProps> = ({
183183
{otherItems.length > 0 && (
184184
<div className={styles.otherCol}>
185185
<div className={styles.otherLabel}>{otherLabel}</div>
186-
<div className={styles.otherList}>
186+
<div
187+
className={clsx(
188+
styles.otherList,
189+
otherCol === 2 && styles.otherListTwoCols
190+
)}
191+
>
187192
{otherItems.map((item) => {
188193
const Icon = item.icon ? sidebarIconMap[item.icon] : null;
194+
const External = sidebarIconMap["external"];
189195
const active = isItemActive(item);
190196

191197
return (
192198
<Link
193199
key={item.href}
194-
to={useBaseUrl(item.href)}
200+
to={item.external ? item.href : useBaseUrl(item.href)}
201+
{...(item.external && {
202+
target: "_blank",
203+
rel: "noopener noreferrer",
204+
})}
195205
className={clsx(
196206
styles.otherItem,
197207
active && styles.cardActive
@@ -205,6 +215,12 @@ const MegaMenuNavbarItem: React.FC<MegaMenuNavbarItemProps> = ({
205215
/>
206216
)}
207217
<span className={styles.otherTitle}>{item.title}</span>
218+
{item.external && (
219+
<External
220+
className={styles.externalIcon}
221+
aria-hidden="true"
222+
/>
223+
)}
208224
</Link>
209225
);
210226
})}

website/src/components/Navbar/MegaMenuNavbarItem/styles.module.css

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,12 @@
3535
right: 0;
3636
top: var(--ifm-navbar-height);
3737
z-index: 200;
38-
39-
opacity: 0;
4038
visibility: hidden;
4139
pointer-events: none;
42-
transition: opacity 160ms ease, visibility 160ms ease;
40+
transition: visibility 160ms ease;
4341
}
4442

4543
.panelWrapperOpen {
46-
opacity: 1;
4744
visibility: visible;
4845
pointer-events: auto;
4946
}
@@ -107,13 +104,17 @@
107104
}
108105

109106
.otherLabel {
110-
font-size: 1.125rem;
111-
font-weight: 700;
107+
font-size: 1rem;
112108
color: var(--text-tertiary);
109+
padding: 0.5rem 0;
113110
}
114111

115112
.otherList {
116113
display: grid;
114+
grid-template-columns: 1fr;
115+
}
116+
.otherListTwoCols {
117+
grid-template-columns: repeat(2, minmax(0, 1fr));
117118
}
118119

119120
.otherItem {
@@ -136,6 +137,12 @@
136137
color: var(--text-primary);
137138
}
138139

140+
.externalIcon {
141+
color: var(--text-tertiary);
142+
width: 18px;
143+
height: 18px;
144+
}
145+
139146
.otherTitle {
140147
font-weight: 700;
141148
font-size: 1.125rem;

website/src/icons/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Rust from "/svg/icon-sidebar-rust.svg";
2121
import JS from "/svg/icon-sidebar-js.svg";
2222
import Organization from "/svg/icon-sidebar-organization.svg";
2323
import Feature from "/svg/icon-sidebar-feature.svg";
24+
import External from "/svg/icon-sidebar-external.svg";
2425
import SquareRocket from "/svg/square-rocket.svg";
2526
import SquareDapp from "/svg/square-dapp.svg";
2627
import SquareScript from "/svg/square-script.svg";
@@ -32,6 +33,7 @@ import SquareProject from "/svg/square-project.svg";
3233
import SquareHistory from "/svg/square-history.svg";
3334
import SquareResource from "/svg/square-resource.svg";
3435
import SquareStructure from "/svg/square-structure.svg";
36+
import SquareContribution from "/svg/square-contribution.svg";
3537

3638
export const sidebarIconMap = {
3739
commonScript: CommonScript,
@@ -57,6 +59,7 @@ export const sidebarIconMap = {
5759
js: JS,
5860
organization: Organization,
5961
feature: Feature,
62+
external: External,
6063
squareRocket: SquareRocket,
6164
squareDapp: SquareDapp,
6265
squareScript: SquareScript,
@@ -68,6 +71,7 @@ export const sidebarIconMap = {
6871
squareHistory: SquareHistory,
6972
squareResource: SquareResource,
7073
squareStructure: SquareStructure,
74+
squareContribution: SquareContribution,
7175
};
7276

7377
export type SidebarIconName = keyof typeof sidebarIconMap;

website/src/pages/homeContents.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const homeCardContents: HomeCardProps[] = [
6868
{ title: "Run a Node", to: "/docs/node/node-overview", icon: "node" },
6969
{ title: "Mining", to: "/docs/mining/guide", icon: "mining" },
7070
{
71-
title: "Tech Explanation",
71+
title: "CKB Fundamentals",
7272
to: "/docs/ckb-fundamentals/nervos-blockchain",
7373
icon: "tech-explanation",
7474
},

website/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@ import { useNavbarMobileSidebar } from "@docusaurus/theme-common/internal";
77
import { useLocation } from "@docusaurus/router";
88
import useBaseUrl from "@docusaurus/useBaseUrl";
99
import styles from "./styles.module.css";
10+
import { MegaMenuItem } from "@site/src/components/Navbar/MegaMenuNavbarItem";
1011

1112
import { sidebarIconMap, type SidebarIconName } from "../../../../icons";
1213

1314
/* ---------- Types ---------- */
1415

15-
type MegaMenuItem = {
16-
title: string;
17-
description?: string;
18-
href: string;
19-
icon?: SidebarIconName;
20-
activeBaseRegex?: string;
21-
};
22-
2316
type MegaMenuNavbarItem = {
2417
type: "custom-megaMenu";
2518
label: string;
@@ -135,24 +128,34 @@ function OtherItem({
135128
item,
136129
pathname,
137130
onClick,
131+
external = false,
138132
}: {
139133
item: MegaMenuItem;
140134
pathname: string;
135+
external?: boolean;
141136
onClick: () => void;
142137
}) {
143138
const Icon = resolveIcon(item.icon);
139+
const External = sidebarIconMap["external"];
144140
const active = isActive(pathname, item);
145141

146142
return (
147143
<Link
148-
to={useBaseUrl(item.href)}
144+
to={item.external ? item.href : useBaseUrl(item.href)}
145+
{...(external && {
146+
target: "_blank",
147+
rel: "noopener noreferrer",
148+
})}
149149
className={clsx(styles.otherItem, active && styles.activeText)}
150150
onClick={onClick}
151151
>
152152
{Icon && <Icon width={24} height={24} aria-hidden />}
153153
<span className={clsx(styles.otherTitle, active && styles.activeText)}>
154154
{item.title}
155155
</span>
156+
{item.external && (
157+
<External className={styles.externalIcon} aria-hidden="true" />
158+
)}
156159
</Link>
157160
);
158161
}

0 commit comments

Comments
 (0)