Skip to content

Commit 0c79053

Browse files
committed
Refactor package.json
1 parent 0eb03a9 commit 0c79053

30 files changed

+307
-305
lines changed

asset/big.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
padding-right: calc(1em + 1ex);
1919
}
2020

21-
.landing .article {
22-
padding: calc(6 * (1em + 1ex) / 1.125) calc(3 * (1em + 1ex) / 1.125);
23-
}
24-
2521
.article {
2622
font-size: 1.125em;
2723
padding-left: calc(3 * (1em + 1ex) / 1.125);
2824
padding-right: calc(3 * (1em + 1ex) / 1.125);
2925
}
3026

27+
.landing .article {
28+
padding: calc(6 * (1em + 1ex) / 1.125) calc(3 * (1em + 1ex) / 1.125);
29+
}
30+
3131
.x-hide-l {
3232
display: none;
3333
}

asset/dark.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ body {
4444
0 -12px 36px -8px rgb(0 0 0 / 2.5%);
4545
}
4646

47+
.more {
48+
border-color: black;
49+
}
50+
4751
.releases {
4852
background-color: rgb(0 0 0 / 20%);
4953
}
@@ -53,10 +57,6 @@ body {
5357
background-color: var(--gray-9);
5458
}
5559

56-
.more {
57-
border-color: black;
58-
}
59-
6060
.tag {
6161
color: var(--blue-3);
6262
background-color: var(--blue-7);

asset/search.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {searchResults as packageResults} from '../generate/component/package/sea
4141
import {searchPreview as projectPreview} from '../generate/component/project/search-preview.js'
4242
import {searchEmpty as projectEmpty} from '../generate/component/project/search-empty.js'
4343
import {searchResults as projectResults} from '../generate/component/project/search-results.js'
44-
import {unique} from '../generate/util/unique.js'
4544
import {asc, desc} from '../generate/util/sort.js'
4645

4746
const Index = flexsearch.Index
@@ -80,7 +79,7 @@ function init() {
8079
create(search) {
8180
return new Promise((resolve) => {
8281
window.requestAnimationFrame(() => {
83-
keywords.forEach((d) => search.index.add(d, d))
82+
for (const d of keywords) search.index.add(d, d)
8483
resolve(undefined)
8584
})
8685
})
@@ -106,7 +105,7 @@ function init() {
106105
create(search) {
107106
return new Promise((resolve) => {
108107
window.requestAnimationFrame(() => {
109-
topics.forEach((d) => search.index.add(d, d))
108+
for (const d of topics) search.index.add(d, d)
110109
resolve(undefined)
111110
})
112111
})
@@ -143,12 +142,11 @@ function init() {
143142
const end = start + size
144143
const slice = names.slice(start, end)
145144

146-
slice.forEach((d) =>
145+
for (const d of slice)
147146
search.index.add(
148147
d,
149148
d.split('/').join(' ') + ' ' + data.packageByName[d].description
150149
)
151-
)
152150

153151
if (slice.length === 0) {
154152
resolve(undefined)
@@ -189,12 +187,12 @@ function init() {
189187
const end = start + size
190188
const slice = repos.slice(start, end)
191189

192-
slice.forEach((d) => {
190+
for (const d of slice) {
193191
search.index.add(
194192
d,
195193
d.split('/').join(' ') + ' ' + data.projectByRepo[d].description
196194
)
197-
})
195+
}
198196

199197
if (slice.length === 0) {
200198
resolve(undefined)
@@ -257,16 +255,16 @@ function init() {
257255
}
258256

259257
/**
260-
* @param {HTMLElementEventMap['submit']} ev
258+
* @param {HTMLElementEventMap['submit']} event
261259
* @returns {undefined}
262260
*/
263-
function onsubmit(ev) {
261+
function onsubmit(event) {
264262
const url = new URL(loc.href)
265263
const current = clean(url.searchParams.get(parameter))
266264
assert($input instanceof HTMLInputElement)
267265
const value = clean($input.value)
268266

269-
ev.preventDefault()
267+
event.preventDefault()
270268

271269
if (current === value) {
272270
return
@@ -278,7 +276,11 @@ function init() {
278276
url.searchParams.delete(parameter)
279277
}
280278

281-
history.pushState({}, '', url.pathname + url.search.replace(/%20/g, '+'))
279+
history.pushState(
280+
{},
281+
'',
282+
url.pathname + url.search.replaceAll('%20', '+')
283+
)
282284

283285
search(value)
284286
}
@@ -295,16 +297,18 @@ function init() {
295297

296298
if (!query) {
297299
$release.style.removeProperty('display')
298-
searches.forEach((search) => replace(search, [], query))
300+
for (const search of searches) replace(search, [], query)
299301
return
300302
}
301303

302304
$release.style.display = 'block'
303305

304-
searches.forEach((search) => {
306+
for (const search of searches) {
305307
search.index.searchAsync(query, {suggest: true}, (result) => {
306-
const clean = /** @type {Array<string>} */ (result.filter(unique))
307-
const weighted = desc(clean, weight)
308+
const clean = [...new Set(/** @type {Array<string>} */ (result))]
309+
const weighted = desc(clean, function (d) {
310+
return search.weight(d)
311+
})
308312

309313
replace(search, asc(clean, combined), query)
310314

@@ -316,15 +320,7 @@ function init() {
316320
return (clean.indexOf(d) + weighted.indexOf(d)) / 2
317321
}
318322
})
319-
320-
/**
321-
* @param {string} d
322-
* @returns {number}
323-
*/
324-
function weight(d) {
325-
return search.weight(d)
326-
}
327-
})
323+
}
328324
}
329325
})
330326
}

crawl/ecosystem.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ import randomUseragent from 'random-useragent'
152152
import pAll from 'p-all'
153153
import bytes from 'bytes'
154154
import dotenv from 'dotenv'
155-
import {unique} from '../generate/util/unique.js'
156155
import {constantTopic} from '../generate/util/constant-topic.js'
157156
import {constantCollective} from '../generate/util/constant-collective.js'
158157

@@ -186,7 +185,7 @@ const orgRepos = await pAll(
186185
{concurrency: 1}
187186
)
188187

189-
const repos = [...topicRepos.flat(), ...orgRepos.flat()].filter(unique)
188+
const repos = [...new Set([...topicRepos.flat(), ...orgRepos.flat()])]
190189

191190
const results = await pAll(
192191
repos.map(function (repo) {
@@ -296,7 +295,7 @@ await fs.writeFile(
296295
'',
297296
'/**',
298297
' * @typedef Package',
299-
' * @property {string} description',
298+
' * @property {string} [description]',
300299
' * @property {Root} [descriptionRich]',
301300
' * @property {number} downloads',
302301
' * @property {number} [gzip]',
@@ -345,7 +344,7 @@ async function findPackages(projects) {
345344
project.hasPackages = true
346345

347346
const readmeName =
348-
packageInfo.name.replace(/^@/g, '').replace(/\//g, '-') + '.md'
347+
packageInfo.name.replaceAll(/^@/g, '').replaceAll('/', '-') + '.md'
349348

350349
await fs.writeFile(
351350
new URL('../data/readme/' + readmeName, import.meta.url),
@@ -642,10 +641,15 @@ async function crawlRepo(repo) {
642641
// Size of repo in bytes.
643642
size: repository.diskUsage * 1024,
644643
stars: repository.stargazers?.totalCount || 0,
645-
topics: (repository.repositoryTopics?.nodes || [])
646-
.map((d) => d.topic.name)
647-
.filter(validTag)
648-
.filter(unique),
644+
topics: [
645+
...new Set(
646+
(repository.repositoryTopics?.nodes || [])
647+
.map((d) => d.topic.name)
648+
.filter(function (d) {
649+
return validTag(d)
650+
})
651+
)
652+
],
649653
url: repository.homepageUrl || undefined
650654
},
651655
releases
@@ -807,7 +811,13 @@ async function getPackage(project, manifest, packageJson) {
807811

808812
return {
809813
description,
810-
keywords: keywords.filter(validTag).filter(unique),
814+
keywords: [
815+
...new Set(
816+
keywords.filter(function (d) {
817+
return validTag(d)
818+
})
819+
)
820+
],
811821
latest,
812822
license,
813823
name,

generate/atom/macro/list.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export function list(names, map, options) {
4040
values = names.slice(0, max - 1)
4141
}
4242

43-
const children = values.flatMap(map)
43+
const children = values.flatMap(function (d) {
44+
return map(d)
45+
})
4446

4547
if (trail) {
4648
children.push(trail)

generate/atom/micro/description.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import {h} from 'hastscript'
66

77
/**
8-
* @param {string} value
8+
* @param {string | undefined} value
99
* @param {Parents | undefined} [rich]
1010
* @returns {Element}
1111
*/

generate/atom/micro/url.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import {link as icon} from '../icon/link.js'
88

99
/**
1010
* @param {string} value
11-
* @param {Properties | undefined} [linkProps]
11+
* @param {Properties | undefined} [linkProperties]
1212
* @returns {ElementContent}
1313
*/
14-
export function url(value, linkProps) {
14+
export function url(value, linkProperties) {
1515
return h(
1616
'li.ellipsis',
17-
h('a.tap-target', {...linkProps, href: value}, [icon(), ' ', fmtUrl(value)])
17+
h('a.tap-target', {...linkProperties, href: value}, [
18+
icon(),
19+
' ',
20+
fmtUrl(value)
21+
])
1822
)
1923
}

generate/component/keyword/helper-filter.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ export function helperFilter(data, names, min) {
1616
const {packagesByKeyword} = data
1717
const value = min || defaults
1818

19-
return names.filter(filter)
20-
21-
/**
22-
* @param {string} d
23-
* @returns {boolean}
24-
*/
25-
function filter(d) {
19+
return names.filter(function (d) {
2620
return (packagesByKeyword[d] || []).length > value
27-
}
21+
})
2822
}

generate/component/keyword/list-small.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import {itemSmall} from './item-small.js'
1212
* @returns {Element}
1313
*/
1414
export function listSmall(data, d) {
15-
return h('.block', {}, h('ol.flow', {}, d.map(map)))
16-
17-
/**
18-
* @param {string} d
19-
* @returns {ElementContent}
20-
*/
21-
function map(d) {
22-
return itemSmall(data, d)
23-
}
15+
return h(
16+
'.block',
17+
{},
18+
h(
19+
'ol.flow',
20+
{},
21+
d.map(function (d) {
22+
return itemSmall(data, d)
23+
})
24+
)
25+
)
2426
}

generate/component/member/helper-sort.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,27 @@ export function helperSort(data, d) {
2121
/** @type {Record<string, number>} */
2222
const scores = {}
2323

24-
data.teams.forEach(team)
25-
26-
return sort(d, score)
27-
28-
/**
29-
* @param {Human} d
30-
* @returns {number}
31-
*/
32-
function score(d) {
33-
return scores[d.github]
34-
}
35-
36-
/**
37-
* @param {Team} team
38-
* @returns {undefined}
39-
*/
40-
function team(team) {
24+
for (const team of data.teams) {
4125
const members = team.humans
4226

43-
Object.keys(members).forEach((d) => {
44-
const role = members[d]
27+
for (const [d, role] of Object.entries(members)) {
4528
const active = Boolean(team.collective && role === 'maintainer')
4629

4730
scores[d] =
4831
(scores[d] || 0) +
4932
(roles[role] || 1) *
5033
// Note: ternary is just for TS, JS works fine without it.
5134
collective[active ? 'true' : 'false']
52-
})
35+
}
36+
}
37+
38+
return sort(d, score)
39+
40+
/**
41+
* @param {Human} d
42+
* @returns {number}
43+
*/
44+
function score(d) {
45+
return scores[d.github]
5346
}
5447
}

0 commit comments

Comments
 (0)