Skip to content

Commit 068d55e

Browse files
committed
cleanup description will not end by "." & links will not end with #readme
1 parent c6142cf commit 068d55e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

apps/svelte.dev/src/lib/packages-meta.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,18 +585,18 @@ function supports_svelte_versions(version_range: string): {
585585
return result;
586586
}
587587

588-
function dont_end_by(str: string, not_all_allowed: string[]): string {
589-
for (const nope of not_all_allowed) {
590-
if (str.endsWith(nope)) {
591-
return str.slice(0, -nope.length);
588+
function remove_ending_by(str: string, endings: string[]): string {
589+
for (const ending of endings) {
590+
if (str.endsWith(ending)) {
591+
return str.slice(0, -ending.length);
592592
}
593593
}
594594
return str;
595595
}
596596

597597
function calculate_description(pkg: PackageKey & PackageNpm): string {
598598
const found = FEATURED.flatMap((f) => f.packages).find((p) => p.name === pkg.name);
599-
if (found && found.description) return dont_end_by(found.description, ['.']);
599+
if (found && found.description) return remove_ending_by(found.description, ['.']);
600600

601601
let desc = pkg.npm_description ?? 'NO DESCRIPTION!';
602602
const replaces = [
@@ -606,14 +606,20 @@ function calculate_description(pkg: PackageKey & PackageNpm): string {
606606
for (const { key, value } of replaces) {
607607
desc = desc.replace(key, value);
608608
}
609-
return dont_end_by(desc, ['.']);
609+
return remove_ending_by(desc, ['.']);
610+
}
611+
612+
function calculate_homepage(pkg: PackageKey & PackageNpm): string {
613+
return remove_ending_by(pkg.homepage ?? '', ['#readme']);
610614
}
611615

612616
export const PACKAGES_META = {
613617
FEATURED,
614618

619+
calculate_description,
620+
calculate_homepage,
621+
615622
is_official,
616623
is_outdated,
617-
supports_svelte_versions,
618-
calculate_description
624+
supports_svelte_versions
619625
};

apps/svelte.dev/src/lib/server/content.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ function create_registry() {
249249
const json = JSON.parse(frontmatter);
250250

251251
json.description = PACKAGES_META.calculate_description(json);
252+
json.homepage = PACKAGES_META.calculate_homepage(json);
252253
json.official = PACKAGES_META.is_official(json.name);
253254
json.outdated = PACKAGES_META.is_outdated(json.updated);
254255
json.svelte = PACKAGES_META.supports_svelte_versions(json.svelte_range);

0 commit comments

Comments
 (0)