diff --git a/src/layouts/css-component-layout.tsx b/src/layouts/css-component-layout.tsx index a1f1c0d8a..41e6d0b8c 100644 --- a/src/layouts/css-component-layout.tsx +++ b/src/layouts/css-component-layout.tsx @@ -15,6 +15,7 @@ import {ComponentPageNav} from '../components/component-page-nav' export const query = graphql` query CssComponentPageQuery($parentPath: String!) { sitePage(path: {eq: $parentPath}) { + id path context { frontmatter { @@ -36,6 +37,16 @@ export default function CssComponentLayout({data}) { const description = data.sitePage?.context.frontmatter.description || '' const stories = [{id: `deprecated-${name}--default`}] + const baseUrl = (() => { + const slugMatch = data.sitePage.id.match(/\/components\/(\w+)\//) + + if (slugMatch) { + return `/components/${slugMatch[1]}` + } + + return data.sitePage.path; + })() + return ( @@ -47,7 +58,7 @@ export default function CssComponentLayout({data}) { ) : null} { - return str - ?.toLowerCase() - .replace(/([A-Z])/g, ' $1') - .replace(/^./, function (str) { - return str.toUpperCase() - }) -} - const lastUpdated = date => { return `Updated ${new Date(date).toLocaleDateString('en-GB', {year: 'numeric', month: 'short', day: 'numeric'})}` } @@ -77,6 +69,16 @@ export default function FigmaComponentLayout({data}) { ], } + const baseUrl = (() => { + const slugMatch = data.sitePage.id.match(/\/components\/(\w+)\//) + + if (slugMatch) { + return `/components/${slugMatch[1]}` + } + + return data.sitePage.path; + })() + return ( @@ -88,7 +90,7 @@ export default function FigmaComponentLayout({data}) { ) : null} { + const slugMatch = data.sitePage.id.match(/\/components\/(\w+)\//) + + if (slugMatch) { + return `/components/${slugMatch[1]}` + } + + return data.sitePage.path; + })() + return ( @@ -363,7 +374,7 @@ export default function RailsComponentLayout({data}) { ) : null} {statuses.length > 1 && - + } diff --git a/src/layouts/react-component-layout.tsx b/src/layouts/react-component-layout.tsx index b7dced909..c0035aa9e 100644 --- a/src/layouts/react-component-layout.tsx +++ b/src/layouts/react-component-layout.tsx @@ -21,6 +21,7 @@ export const query = graphql` version } sitePage(path: {eq: $parentPath}) { + id path context { frontmatter { @@ -111,6 +112,16 @@ export default function ReactComponentLayout({data}) { // this component has a dedicated page for its deprecated version if (data.deprecatedMdx?.id !== undefined) statuses.push("deprecated") + const baseUrl = (() => { + const slugMatch = data.sitePage.id.match(/\/components\/(\w+)\//) + + if (slugMatch) { + return `/components/${slugMatch[1]}` + } + + return data.sitePage.path; + })() + return ( @@ -122,7 +133,7 @@ export default function ReactComponentLayout({data}) { ) : null} - + }