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

gist support #37

Closed
dferber90 opened this issue Oct 21, 2022 · 1 comment
Closed

gist support #37

dferber90 opened this issue Oct 21, 2022 · 1 comment

Comments

@dferber90
Copy link

first of all, this project is amazing and top-notch quality!

i noticed there's support for files in github hosted files already.

it would be really cool if it could support gists as well.

for example, if I paste a url like https://gist.github.com/databus23/848f60539956284e504605d4d9c01bc1

it could load info via https://api.github.com/gists/:gistId and then show the json/yaml file

that way i could have a swagger viewer link which always points to the latest version of a gist 🥳

@dferber90
Copy link
Author

something like this works as a starting point if used as the getServerSideProps of pages/spec/[id].tsx

export const getServerSideProps: GetServerSideProps = async (context) => {
  const id = context.params.id as string;

  const decodedUrl = decodeURIComponent(b64.urlDecode(id));
  let url: string;
  const match = decodedUrl.match(/^https:\/\/gist.github\.com\/([^\s/]+)\/([^\s/]+)$/);
  console.log(match);

  if (match) {
    const data = await fetch(`https://api.github.com/gists/${match[2]}`).then((res) => res.json());
    console.log(data);

    url = Object.values(data.files)[0].raw_url;
  } else {
    url = decodedUrl;
  }

  const ret = ghUtil.extractUrlMeta(url);
  const ogImageUrl = ret ? buildOgImageUrl(ret) : null;

  return {
    props: {
      ogImageUrl,
      url,
    },
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant