Skip to content

Commit

Permalink
general refactoring to align with site information architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Oct 17, 2024
1 parent ccfcbbf commit ebb27b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions src/components/edit-on-github/edit-on-github.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import styles from "./edit-on-github.module.css";

const REPO_PREFIX = "https://github.com/ProjectEvergreen/www.greenwoodjs.dev/edit/main/src/pages/";

function convertRouteToSubLink(route) {
if (route === "/") return "index.md"; // root of diretory === index

const DIRS = ["guides", "ecosystem", "getting-started", "hosting", "tutorials"];

const routeParts = route.split("/").filter((param) => param !== "");
const trimmedRoute = routeParts.join("/");
const isDirectory = DIRS.includes(routeParts[routeParts.length - 1]);

return isDirectory ? `${trimmedRoute}/index.md` : `${trimmedRoute}.md`;
const REPO_PREFIX = "https://github.com/ProjectEvergreen/www.greenwoodjs.dev/edit/main/src/pages";
const MAX_ROUTE_DEPTH = 5;

// one / two segments - /guides/ -> /guides/index.md
// three (max) segments - /guides/getting-started/key-concepts/ -> /guides/getting-started/key-concepts.md
function convertRouteToEditLink(route) {
const segments = route.split("/");

// https://stackoverflow.com/a/5497365/417806
return segments.length === MAX_ROUTE_DEPTH
? `${route.replace(/\/([^/]*)$/, "")}.md`
: `${route}index.md`;
}

export default class EditOnGitHub extends HTMLElement {
connectedCallback() {
const label = "Edit on GitHub";
const route = this.getAttribute("route");
const href = `${REPO_PREFIX}${convertRouteToSubLink(route)}`;
const href = `${REPO_PREFIX}${convertRouteToEditLink(route)}`;

this.innerHTML = `
<div class="${styles.container}">
Expand Down
10 changes: 5 additions & 5 deletions src/components/edit-on-github/edit-on-github.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const Template = (props) => {
`;
};

export const Root = Template.bind(
export const PageRoot = Template.bind(
{},
{
args: {
route: "/",
route: "/guides/",
},
},
);

export const Directory = Template.bind(
export const SectionRoot = Template.bind(
{},
{
args: {
Expand All @@ -30,11 +30,11 @@ export const Directory = Template.bind(
},
);

export const Static = Template.bind(
export const Section = Template.bind(
{},
{
args: {
route: "/guides/hosting/netlify",
route: "/guides/hosting/netlify/",
},
},
);

0 comments on commit ebb27b1

Please sign in to comment.