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

Implement basic AvatarList.astro #17

Merged
merged 11 commits into from
Jun 24, 2021
Merged

Implement basic AvatarList.astro #17

merged 11 commits into from
Jun 24, 2021

Conversation

jasikpark
Copy link
Contributor

@jasikpark jasikpark commented Jun 22, 2021

Currently the images are hotlinked, so it might be the case where it makes more sense to pull in the images as assets programmatically and then reference them locally, but that's for once Astro has images figured out a bit more.

I fixed the editHref to actually point to this repo

There needs to be a Github Personal Access Token with public_repo permissions set to SNOWPACK_PUBLIC_GITHUB_TOKEN to remove Github rate limiting.

// .env
SNOWPACK_PUBLIC_GITHUB_TOKEN=username:token

image

@vercel
Copy link

vercel bot commented Jun 22, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/astro-docs-preview/32dRV2xb4RUojQufitZsMCGxxWj6
✅ Preview: https://astro-docs-preview-git-fork-jasikpark-main-pikapkg.vercel.app

@jasikpark
Copy link
Contributor Author

I still need to make it detect rate-limiting from Github and such..

It probably makes sense to use https://www.npmjs.com/package/octokit#user-content-octokit-api-client, but I had problems running it, snowpack was complaining about not installing esbuild..

@jasikpark
Copy link
Contributor Author

I'm getting a 403 Forbidden through my personal token, but I can load the URL fine in Firefox... so A. It's probably a good idea for me to figure out how to use Octokit and B. auth is confusing

@jasikpark
Copy link
Contributor Author

Design suggested by @mrbrianhinton:

image

I artificially increased the number of contributors for this screenshot by not deduplicating the commits, but it shows only the last three contributors as avatars + the rest are just a number!

@jasikpark jasikpark changed the title Actually request icons for AvatarList.astro. Fully Implement basic AvatarList.astro Jun 23, 2021
@jasikpark jasikpark changed the title Fully Implement basic AvatarList.astro Implement basic AvatarList.astro Jun 23, 2021
export let path;
// fetch all commits for just this page's path
let url = `https://api.github.com/repos/snowpackjs/astro-docs/commits?path=${path}`;
let token = import.meta.env.SNOWPACK_PUBLIC_GITHUB_TOKEN ?? throw Error('You might not have "SNOWPACK_PUBLIC_GITHUB_TOKEN added for escaping rate-limiting.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we leave this as optional? It would be a big point of friction to need to generate an access token just to start up dev.

If it's a concern that this throws an error when rate limited: we can catch that error, ignore it, and then return an empty avatar list. This would only happen in dev, but then still let you provide your own token if you need to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That certainly sounds reasonable

Authorization: auth,
"User-Agent": "astro-docs/1.0"
},
}).then((res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

astro supports top-level await! It would be nice to see this instead:

const res = await fetch(...
const data = await res.json();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can certainly do that, I just like scoped vars is all!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I always hate that await-fetch requires that unnecessary res var when all I want is the JSON

@FredKSchott
Copy link
Member

LGTM with a few comments! just added the secret, redeploying now

Currently the images are hotlinked, so it might be the case where it makes more sense to pull in the images as assets programmatically and then reference them locally, but that's for once Astro has images figured out a bit more.

I fixed the editHref to actually point to this repo

There needs to be a Github Personal Access Token with `public_repo` permissions set to `SNOWPACK_PUBLIC_GITHUB_TOKEN` to remove Github rate limiting.
…oesn't seem to support throws from what I can tell though?
@jasikpark
Copy link
Contributor Author

Something fun is that since we're sending all snowpack warnings into the void, I can't see the output of console.warn if I call that in my component, so I had to go with console.log

@FredKSchott
Copy link
Member

I think that was removed in 0.14.0, we shouldn't be swallowing anything anymore.

err... looks like we are doing some console.warn trapping in build(). If you don't mind filing an issue for that, I think that's worth fixing (we could just silence the exact warnings coming from vue, instead of a blanket "swallow all")

@FredKSchott
Copy link
Member

Success! I had to add the secret env variable to Vercel, not Github

@jasikpark
Copy link
Contributor Author

jasikpark commented Jun 24, 2021

hmm I don't seem to see the images showing up on the site though... (nvm) I just clicked on an old deploy or something

@jasikpark
Copy link
Contributor Author

Could someone review this? It should be good to go for merging.

@itskitto itskitto merged commit 83cb977 into withastro:main Jun 24, 2021
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

Successfully merging this pull request may close these issues.

3 participants