Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Edit on GitHub" link for guides / docs pages #97

Open
thescientist13 opened this issue Sep 29, 2024 · 0 comments
Open

"Edit on GitHub" link for guides / docs pages #97

thescientist13 opened this issue Sep 29, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@thescientist13
Copy link
Member

Summary

On the old website, we had an "Edit on GitHub" at the bottom of a number of pages, which when clicked would link to the file in the GitHub repo.
Screenshot 2024-09-29 at 6 42 47 PM

<script>
  window.onload = () => {
    const editButton = document.getElementById('github-edit-button');
    const path = window.location.pathname;
    const params = path.split('/').filter(param => param !== "");
    const filePath = params.length <= 1 ? `${params[0]}/index.md` : `${params.join("/")}.md`

    document.getElementsByTagName('app-shelf')[0].setAttribute('page', params[0]);
    editButton.href = `https://github.com/ProjectEvergreen/greenwood/tree/master/www/pages/${filePath}`
  }
</script>

Details

Basically we just need the same functionality here, maybe using --color-prism-bg for the background color though I think we can just make it a basic Light DOM component instead of having to rely on JavaScript.

<app-edit-on-github route="${globalThis.page.route}"></app-edit-on-github>
// src/components/edit-on-github/edit-on-github.js
import styles from './edit-on-github.module.css';

const REPO_PREFIX = 'https://github.com/ProjectEvergreen/www.greenwoodjs.dev/tree/main/www/pages/';

function convertRouteToSubLink(route) {
  // clean up leading forward slash
  return ...;
}

export default class EditOnGitHub extends HTMLElement {
  connectedCallback() {
    const route = this.getAttribute('route');
    const subLink = convertRouteToSubLink(route);

    this.innerHTML = `
      <div class="${styles.container}">
        <a title="Edit on GitHub" href="${REPO_PREFIX}${subLink}" target="_blank">Edit on GitHub</a>
      </div>
    `
  }
}

customElements.define('app-edit-on-github', EditOnGitHub);

We should also add a basic Storybook and test case to validate the static output.

@thescientist13 thescientist13 added enhancement New feature or request good first issue Good for newcomers labels Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant