Skip to content

Commit

Permalink
corrected example links
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Feb 20, 2024
1 parent 50e18ed commit bdb00fe
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions website/components/ExampleHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,34 @@ const A = (props: ComponentPropsWithoutRef<"a">) => (

const getHeader = (segments: string[]) => {
switch (segments.length) {
case 3:
return `${segments[0]}: ${segments[2]} (${segments[1]})`;
case 2:
return `${segments[0]}: ${segments[1]}`;
case 5:
return `${segments[2]}: ${segments[4]} (${segments[3]})`;
case 4:
return `${segments[2]}: ${segments[3]}`;
default:
return "Example";
}
};
const ExampleHeader = () => {
const segments = usePathname()
.replace("examples", "example")
.split("/")
.slice(2);

const startCasedSegments = segments.map(startCase);
const getGitPiece = (segments: string[]) => {
if (segments.length > 2) {
const pathPiece = segments.slice(3).join("/");

switch (segments[1]) {
case "virtual":
return `nowaalex/af-utils/tree/master/examples/src/virtual/react/${pathPiece}`;
case "scrollend-polyfill":
return `nowaalex/af-utils/tree/master/examples/src/scrollend-polyfill/${pathPiece}`;
}
}

const pathPiece = segments.slice(1).join("/");
const gitPiece = `nowaalex/af-utils/tree/master/examples/src/virtual/react/${pathPiece}`;
throw new Error("Wrong segments");
};

const ExampleHeader = () => {
const segments = usePathname().replace("examples", "example").split("/");
const startCasedSegments = segments.map(startCase);
const gitPiece = getGitPiece(segments);

return (
<div className="flex flex-wrap gap-x-10 gap-y-4 items-center mb-6">
Expand Down

0 comments on commit bdb00fe

Please sign in to comment.