Skip to content

Commit 90ee93f

Browse files
authored
Merge pull request #163 from kevanstannard/syntax-lookup-widget-slug
Add item.id to use as syntax lookup widget slug
2 parents 7a04b3c + 0a7d303 commit 90ee93f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/components/SyntaxLookupWidget.js

+7-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/SyntaxLookupWidget.res

+8-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module Category = {
4646
}
4747

4848
type item = {
49+
id: string,
4950
keywords: array<string>,
5051
name: string,
5152
summary: string,
@@ -55,27 +56,31 @@ type item = {
5556

5657
let allItems = [
5758
{
59+
id: "module-decorator",
5860
keywords: ["@bs.module"],
5961
name: "@module",
6062
summary: "This is the `@module` decorator.",
6163
category: Decorators,
6264
component: decorator_module,
6365
},
6466
{
67+
id: "as-decorator",
6568
keywords: ["@bs.as"],
6669
name: "@as",
6770
summary: "This is the `@as` decorator.",
6871
category: Decorators,
6972
component: decorator_as,
7073
},
7174
{
75+
id: "if-else",
7276
keywords: ["if", "else", "if else"],
7377
name: "if / else",
7478
summary: "This is the `if / else` control flow structure.",
7579
category: ControlFlow,
7680
component: controlflow_ifelse,
7781
},
7882
{
83+
id: "uncurried-function",
7984
keywords: ["uncurried"],
8085
name: "(.) => {}",
8186
summary: "This is an `uncurried` function.",
@@ -152,7 +157,7 @@ let make = () => {
152157
switch getAnchor(router.asPath) {
153158
| Some(anchor) =>
154159
Js.Array2.find(allItems, item =>
155-
GithubSlugger.slug(item.name) === anchor
160+
GithubSlugger.slug(item.id) === anchor
156161
)->Belt.Option.forEach(item => {
157162
setState(_ => ShowDetails(item))
158163
})
@@ -172,15 +177,15 @@ let make = () => {
172177
React.useEffect1(() => {
173178
switch (state, getAnchor(router.asPath)) {
174179
| (ShowDetails(item), Some(anchor)) =>
175-
let slug = GithubSlugger.slug(item.name)
180+
let slug = GithubSlugger.slug(item.id)
176181

177182
if slug !== anchor {
178183
router->Next.Router.replace("syntax-lookup#" ++ anchor)
179184
} else {
180185
()
181186
}
182187
| (ShowDetails(item), None) =>
183-
router->Next.Router.replace("syntax-lookup#" ++ GithubSlugger.slug(item.name))
188+
router->Next.Router.replace("syntax-lookup#" ++ GithubSlugger.slug(item.id))
184189
| (_, Some(_)) => router->Next.Router.replace("syntax-lookup")
185190
| _ => ()
186191
}

0 commit comments

Comments
 (0)