Skip to content

Commit 84f1920

Browse files
committed
Use __ghEditHref in layouts
1 parent 7a98e08 commit 84f1920

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

common/DocFrontmatter.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/DocFrontmatter.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ type t = {
22
title: string,
33
description: Js.null<string>,
44
canonical: Js.null<string>,
5+
ghEditHref: string,
56
}
67

78
let decode = (json): result<t, string> => {
@@ -10,6 +11,7 @@ let decode = (json): result<t, string> => {
1011
title: field("title", string, json),
1112
description: optional(field("description", string), json)->Js.Null.fromOption,
1213
canonical: optional(field("canonical", string), json)->Js.Null.fromOption,
14+
ghEditHref: field("__ghEditHref", string, json),
1315
}) catch {
1416
| DecodeError(errMsg) => Error(errMsg)
1517
}

layouts/DocsLayout.js

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

layouts/DocsLayout.res

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ let make = (
120120
| None => title
121121
}
122122

123-
let metaElement = switch frontmatter {
123+
let (metaElement, editHref) = switch frontmatter {
124124
| Some(frontmatter) =>
125125
switch DocFrontmatter.decode(frontmatter) {
126126
| Ok(fm) =>
@@ -130,14 +130,15 @@ let make = (
130130
| Some(titleCategory) => fm.title ++ (" | " ++ titleCategory)
131131
| None => title
132132
}
133-
<Meta title ?description ?canonical />
134-
| Error(_) => React.null
133+
let meta = <Meta title ?description ?canonical />
134+
(meta, Some(fm.ghEditHref))
135+
| Error(_) => (React.null, None)
135136
}
136-
| None => React.null
137+
| None => (React.null, None)
137138
}
138139

139140
<SidebarLayout
140-
metaTitle theme components sidebarState=(isSidebarOpen, setSidebarOpen) sidebar ?breadcrumbs>
141+
metaTitle theme components sidebarState=(isSidebarOpen, setSidebarOpen) sidebar ?breadcrumbs ?editHref>
141142
metaElement children
142143
</SidebarLayout>
143144
}

layouts/SidebarLayout.js

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

layouts/SidebarLayout.res

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ let make = (
204204
~metaTitle: string,
205205
~theme: ColorTheme.t,
206206
~components: Mdx.Components.t,
207+
~editHref: option<string>=?,
207208
~sidebarState: (bool, (bool => bool) => unit),
208209
// (Sidebar, toggleSidebar) ... for toggling sidebar in mobile view
209210
~sidebar: React.element,
@@ -243,6 +244,11 @@ let make = (
243244
)
244245
}, [])
245246

247+
let editLinkEl = switch editHref {
248+
| Some(href) => <a href className="inline text-14 hover:underline text-fire" target="_blank" rel="noopener noreferrer"> {React.string("Edit")} </a>
249+
| None => React.null
250+
}
251+
246252
<>
247253
<Meta title=metaTitle />
248254
<div className={"mt-16 min-w-320 " ++ theme}>
@@ -263,7 +269,9 @@ let make = (
263269
toggleSidebar()
264270
}}
265271
/>
266-
<div className="truncate overflow-x-auto touch-scroll"> breadcrumbs </div>
272+
<div className="truncate overflow-x-auto touch-scroll flex items-center space-x-4 md:justify-between mr-4 w-full">
273+
breadcrumbs editLinkEl
274+
</div>
267275
</div>
268276
<div className={hasBreadcrumbs ? "mt-10" : "-mt-4"}>
269277
<Mdx.Provider components> children </Mdx.Provider>
@@ -273,7 +281,7 @@ let make = (
273281
</div>
274282
</div>
275283
</div>
276-
<Footer/>
284+
<Footer />
277285
</div>
278286
</>
279287
}

0 commit comments

Comments
 (0)