feat(apps/docs): fix contributors path
This commit is contained in:
parent
924edc017a
commit
26e099e2cf
1 changed files with 129 additions and 114 deletions
|
@ -4,7 +4,7 @@ type Props = {
|
||||||
path: string;
|
path: string;
|
||||||
};
|
};
|
||||||
const { path } = Astro.props as Props;
|
const { path } = Astro.props as Props;
|
||||||
const resolvedPath = `examples/docs/${path}`;
|
const resolvedPath = `apps/docs/${path}`;
|
||||||
const url = `https://api.github.com/repos/ayoayco/astro-reactive-library/commits?path=${resolvedPath}`;
|
const url = `https://api.github.com/repos/ayoayco/astro-reactive-library/commits?path=${resolvedPath}`;
|
||||||
const commitsURL = `https://github.com/ayoayco/astro-reactive-library/commits/main/${resolvedPath}`;
|
const commitsURL = `https://github.com/ayoayco/astro-reactive-library/commits/main/${resolvedPath}`;
|
||||||
|
|
||||||
|
@ -17,20 +17,20 @@ type Commit = {
|
||||||
|
|
||||||
async function getCommits(url: string) {
|
async function getCommits(url: string) {
|
||||||
try {
|
try {
|
||||||
const token = import.meta.env.SNOWPACK_PUBLIC_GITHUB_TOKEN ?? 'hello';
|
const token = import.meta.env.SNOWPACK_PUBLIC_GITHUB_TOKEN ?? "hello";
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Cannot find "SNOWPACK_PUBLIC_GITHUB_TOKEN" used for escaping rate-limiting.'
|
'Cannot find "SNOWPACK_PUBLIC_GITHUB_TOKEN" used for escaping rate-limiting.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auth = `Basic ${Buffer.from(token, 'binary').toString('base64')}`;
|
const auth = `Basic ${Buffer.from(token, "binary").toString("base64")}`;
|
||||||
|
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: 'GET',
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: auth,
|
Authorization: auth,
|
||||||
'User-Agent': 'astro-docs/1.0',
|
"User-Agent": "astro-docs/1.0",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ async function getCommits(url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeDups(arr: Commit[]) {
|
function removeDups(arr: Commit[]) {
|
||||||
const map = new Map<string, Commit['author']>();
|
const map = new Map<string, Commit["author"]>();
|
||||||
|
|
||||||
for (let item of arr) {
|
for (let item of arr) {
|
||||||
const author = item.author;
|
const author = item.author;
|
||||||
|
@ -71,8 +71,12 @@ const additionalContributors = unique.length - recentContributors.length; // lis
|
||||||
|
|
||||||
<!-- Thanks to @5t3ph for https://smolcss.dev/#smol-avatar-list! -->
|
<!-- Thanks to @5t3ph for https://smolcss.dev/#smol-avatar-list! -->
|
||||||
<div class="contributors">
|
<div class="contributors">
|
||||||
<ul class="avatar-list" style={`--avatar-count: ${recentContributors.length}`}>
|
<ul
|
||||||
{recentContributors.map((item) => (
|
class="avatar-list"
|
||||||
|
style={`--avatar-count: ${recentContributors.length}`}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
recentContributors.map((item) => (
|
||||||
<li>
|
<li>
|
||||||
<a href={`https://github.com/${item.login}`}>
|
<a href={`https://github.com/${item.login}`}>
|
||||||
<img
|
<img
|
||||||
|
@ -84,15 +88,20 @@ const additionalContributors = unique.length - recentContributors.length; // lis
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
{additionalContributors > 0 && (
|
{
|
||||||
|
additionalContributors > 0 && (
|
||||||
<span>
|
<span>
|
||||||
<a href={commitsURL}>{`and ${additionalContributors} additional contributor${
|
<a
|
||||||
additionalContributors > 1 ? 's' : ''
|
href={commitsURL}
|
||||||
|
>{`and ${additionalContributors} additional contributor${
|
||||||
|
additionalContributors > 1 ? "s" : ""
|
||||||
}.`}</a>
|
}.`}</a>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
{unique.length === 0 && <a href={commitsURL}>Contributors</a>}
|
{unique.length === 0 && <a href={commitsURL}>Contributors</a>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -106,7 +115,10 @@ const additionalContributors = unique.length - recentContributors.length; // lis
|
||||||
/* Default to displaying most of the avatar to
|
/* Default to displaying most of the avatar to
|
||||||
enable easier access on touch devices, ensuring
|
enable easier access on touch devices, ensuring
|
||||||
the WCAG touch target size is met or exceeded */
|
the WCAG touch target size is met or exceeded */
|
||||||
grid-template-columns: repeat(var(--avatar-count), max(44px, calc(var(--avatar-size) / 1.15)));
|
grid-template-columns: repeat(
|
||||||
|
var(--avatar-count),
|
||||||
|
max(44px, calc(var(--avatar-size) / 1.15))
|
||||||
|
);
|
||||||
/* `padding` matches added visual dimensions of
|
/* `padding` matches added visual dimensions of
|
||||||
the `box-shadow` to help create a more accurate
|
the `box-shadow` to help create a more accurate
|
||||||
computed component size */
|
computed component size */
|
||||||
|
@ -118,7 +130,10 @@ const additionalContributors = unique.length - recentContributors.length; // lis
|
||||||
.avatar-list {
|
.avatar-list {
|
||||||
/* We create 1 extra cell to enable the computed
|
/* We create 1 extra cell to enable the computed
|
||||||
width to match the final visual width */
|
width to match the final visual width */
|
||||||
grid-template-columns: repeat(calc(var(--avatar-count) + 1), calc(var(--avatar-size) / 1.75));
|
grid-template-columns: repeat(
|
||||||
|
calc(var(--avatar-count) + 1),
|
||||||
|
calc(var(--avatar-size) / 1.75)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue