Skip to content

Commit feaec5b

Browse files
committed
fix: Repo lists
1 parent 2b1e4c9 commit feaec5b

File tree

2 files changed

+74
-24
lines changed

2 files changed

+74
-24
lines changed

public/og.png

2.98 MB
Loading

src/pages/index.astro

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,59 @@ interface Repo {
88
private: boolean;
99
fork: boolean;
1010
archived: boolean;
11+
description: string;
12+
homepage: string;
1113
}
1214
1315
const backupData = [
16+
{
17+
name: 'Image Prompt Builder/Collector ',
18+
homepage: 'https://prompts.inpyjamas.dev/',
19+
description:
20+
'Allows you to build image prompts and collect them in local storage',
21+
},
1422
{
1523
name: 'Named CSS Colors Search',
16-
html_url: 'https://colornames.inpyjamas.dev/',
24+
homepage: 'https://colornames.inpyjamas.dev/',
1725
description: 'Search for named CSS colors',
1826
},
1927
{
2028
name: 'Timers',
21-
html_url: 'https://timers.inpyjamas.dev/',
29+
homepage: 'https://timers.inpyjamas.dev/',
2230
description: 'A timer app. Control it by adding URL params ?secs=600',
2331
},
2432
{
2533
name: 'Notepad for Thoughts',
26-
html_url: 'https://notes.inpyjamas.dev/',
34+
homepage: 'https://notes.inpyjamas.dev/',
2735
description: 'Write down things, keep them in local storage',
2836
},
2937
{
3038
name: 'Ratios',
31-
html_url: 'https://ratios.inpyjamas.dev/',
39+
homepage: 'https://ratios.inpyjamas.dev/',
3240
description: 'A tool for calculating aspect ratios',
3341
},
3442
{
3543
name: 'Assets Library',
36-
html_url: 'https://assets.qawsed.site/',
44+
homepage: 'https://assets.qawsed.site/',
3745
description: 'A collection of assets for projects, reset.css, etc.',
3846
},
3947
{
4048
name: 'Easing Functions',
41-
html_url: 'https://easing.inpyjamas.dev/',
49+
homepage: 'https://easing.inpyjamas.dev/',
4250
description:
4351
'Easing functions based on Robert Penners work, intended for p5.js',
4452
},
4553
{
4654
name: 'p5.js Sandbox',
47-
html_url: 'https://p5.inpyjamas.dev/',
55+
homepage: 'https://p5.inpyjamas.dev/',
4856
description:
4957
'A sandbox for p5.js sketches with live preview, kept in local storage',
5058
},
59+
{
60+
name: 'p5.js Starter Kit',
61+
homepage: 'https://p5kit.inpyjamas.dev/',
62+
description: 'An opinionated starter kit for p5.js projects',
63+
},
5164
{
5265
name: 'ws-broadcast',
5366
html_url: 'https://github.com/inpyjamas/ws-broadcast',
@@ -70,7 +83,7 @@ const backupData = [
7083
},
7184
{
7285
name: 'all hex colors',
73-
html_url: 'https://allhexcolors.inpyjamas.dev/',
86+
homepage: 'https://allhexcolors.inpyjamas.dev/',
7487
description:
7588
'little experiment calculating all possible hex colors and displaying them',
7689
},
@@ -100,28 +113,59 @@ async function load() {
100113
html_url: repo.html_url,
101114
stargazers_count: repo.stargazers_count,
102115
updated_at: repo.updated_at,
116+
description: repo.description,
117+
homepage: repo.homepage,
103118
}
104119
: {};
105120
});
106121
122+
console.log(repos);
123+
107124
data = (
108125
repos.filter((repo) => Object.keys(repo).length !== 0) as Repo[]
109126
).sort((a, b) => b.stargazers_count - a.stargazers_count);
110127
// @ts-ignore
111128
data.push(...backupData);
112129
data = Array.from(new Set(data));
113-
data = Array.from(
114-
data.reduce((map, item) => {
115-
const existing = map.get(item.name);
116-
map.set(item.name, existing ? { ...existing, ...item } : item);
117-
return map;
118-
}, new Map<string, (typeof data)[0]>()),
119-
).map(([_, value]) => value);
130+
const uniqueMap = data.reduce((map, item) => {
131+
// Normalize URLs by removing trailing slashes
132+
const normalizeUrl = (url) => url?.replace(/\/$/, '') || '';
133+
134+
const primaryKey =
135+
item.homepage && item.homepage.startsWith('https')
136+
? normalizeUrl(item.homepage)
137+
: normalizeUrl(item.html_url);
138+
139+
// Check if this item already exists under either possible key
140+
const homepageKey =
141+
item.homepage && item.homepage.startsWith('https')
142+
? normalizeUrl(item.homepage)
143+
: null;
144+
const htmlKey = normalizeUrl(item.html_url);
145+
146+
const existingByHomepage = homepageKey ? map.get(homepageKey) : null;
147+
const existingByHtml = map.get(htmlKey);
148+
const existing = existingByHomepage || existingByHtml;
149+
150+
// Remove any existing entries to avoid duplicates
151+
if (existingByHomepage && homepageKey) map.delete(homepageKey);
152+
if (existingByHtml) map.delete(htmlKey);
153+
154+
map.set(primaryKey, existing ? { ...item, ...existing } : item);
155+
return map;
156+
}, new Map<string, (typeof data)[0]>());
157+
data = Array.from(uniqueMap.values());
120158
} else {
121159
data = backupData;
122160
}
123161
}
124-
await load();
162+
await load()
163+
.then(() => {
164+
// console.log(data);
165+
})
166+
.catch((err) => {
167+
console.error(err);
168+
});
125169
---
126170

127171
<html lang="en">
@@ -249,14 +293,20 @@ await load();
249293
Until then checkout these repos and projects
250294
<ul>
251295
{
252-
data.map((repo) => (
253-
<li>
254-
<a href={repo.html_url} target="_blank">
255-
{repo.name}
256-
</a>{' '}
257-
- {repo.description}
258-
</li>
259-
))
296+
data.map((repo) => {
297+
const linkUrl =
298+
repo.homepage && repo.homepage.startsWith('https')
299+
? repo.homepage
300+
: repo.html_url;
301+
return (
302+
<li>
303+
<a href={linkUrl} target="_blank">
304+
{repo.name}
305+
</a>{' '}
306+
- {repo.description}
307+
</li>
308+
);
309+
})
260310
}
261311
</ul>
262312
</p>

0 commit comments

Comments
 (0)