mirror of
https://github.com/BillyOutlast/posthog.com.git
synced 2026-02-04 03:11:21 +01:00
* 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>
28 lines
864 B
TypeScript
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, '')
|
|
}
|