Files
posthog.com/gatsby/utils.ts
Eli Kinsey 8cd20fcc15 Add "Copy as Markdown" button (#11588)
* add copy as markdown button

* remove frontmatter

* add copy as markdown button (#11719)

Co-authored-by: Eli Kinsey <eli@ekinsey.dev>

* resolving snippet imports within snippets (#11797)

* resolving snippet imports within snippets

* idk where this came from

* Update gatsby/snippetUtils.ts

Co-authored-by: Vincent (Wen Yu) Ge <29069505+gewenyu99@users.noreply.github.com>

* remove snippet restriction

---------

Co-authored-by: Eli Kinsey <eli@ekinsey.dev>
Co-authored-by: Vincent (Wen Yu) Ge <29069505+gewenyu99@users.noreply.github.com>

* remove rawBody query

* Hoist recursion logic for clean code that makes uncle bob proud (#11808)

Co-authored-by: Vincent (Wen Yu) Ge <29069505+gewenyu99@users.noreply.github.com>
Co-authored-by: edwinyjlim <edwinyjlim@gmail.com>
Co-authored-by: Eli Kinsey <eli@ekinsey.dev>

---------

Co-authored-by: Vincent (Wen Yu) Ge <29069505+gewenyu99@users.noreply.github.com>
Co-authored-by: Edwin Lim <edwin@posthog.com>
Co-authored-by: edwinyjlim <edwinyjlim@gmail.com>
2025-06-11 11:14:52 -07:00

28 lines
864 B
TypeScript

// Replacing '/' would result in empty string which is invalid
export const replacePath = (path: string) => (path === `/` ? path : path.replace(/\/$/, ``))
export function flattenMenu(items, breadcrumb = []) {
return items.reduce((acc, item) => {
if (item.url) {
acc.push({
url: item.url,
name: item.name,
breadcrumb: [...breadcrumb, { url: item.url, name: item.name }],
})
}
if (item.children) {
acc.push(
...flattenMenu(item.children, [
...breadcrumb,
{ name: item.name, url: item.url || item.children[0].url },
])
)
}
return acc
}, [])
}
export const stripFrontmatter = (body: string) => {
return body.replace(/^---[\s\S]*?---\n*/m, '')
}