File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const LOW_VALUE_DOCS_SITEMAP_SEGMENTS = new Set ( [ 'examples' , 'community' ] )
2+
3+ const LOW_VALUE_DOCS_SITEMAP_SLUGS = new Set ( [
4+ 'community-resources' ,
5+ 'contributors' ,
6+ 'npm-stats' ,
7+ ] )
8+
9+ export function isHighValueDocsSlug ( slug : string ) {
10+ const segments = slug . split ( '/' ) . filter ( Boolean )
11+
12+ return (
13+ segments . length > 0 &&
14+ ! segments . some ( ( segment ) =>
15+ / ^ (?: d r a f t s | r e a d m e ) $ | \. d r a f t $ / i. test ( segment ) ,
16+ ) &&
17+ ! segments . some ( ( segment ) => LOW_VALUE_DOCS_SITEMAP_SEGMENTS . has ( segment ) ) &&
18+ ! LOW_VALUE_DOCS_SITEMAP_SLUGS . has ( slug )
19+ )
20+ }
Original file line number Diff line number Diff line change 1+ import { isHighValueDocsSlug } from './sitemap-docs'
12import { getStartExampleSitemapEntries } from './start-example-pages'
23import { getBranch , libraries } from '~/libraries'
34import type { LibrarySlim } from '~/libraries/types'
@@ -23,14 +24,6 @@ const HIGH_VALUE_NON_DOC_PAGES = [
2324 '/paid-support' ,
2425] as const satisfies ReadonlyArray < string >
2526
26- const LOW_VALUE_DOCS_SITEMAP_SEGMENTS = new Set ( [ 'examples' , 'community' ] )
27-
28- const LOW_VALUE_DOCS_SITEMAP_SLUGS = new Set ( [
29- 'community-resources' ,
30- 'contributors' ,
31- 'npm-stats' ,
32- ] )
33-
3427function trimTrailingSlash ( url : string ) {
3528 return url . replace ( / \/ $ / , '' )
3629}
@@ -62,16 +55,6 @@ function getLibraryEntries(): Array<SitemapEntry> {
6255 } )
6356}
6457
65- function isHighValueDocsSlug ( slug : string ) {
66- const segments = slug . split ( '/' ) . filter ( Boolean )
67-
68- return (
69- segments . length > 0 &&
70- ! segments . some ( ( segment ) => LOW_VALUE_DOCS_SITEMAP_SEGMENTS . has ( segment ) ) &&
71- ! LOW_VALUE_DOCS_SITEMAP_SLUGS . has ( slug )
72- )
73- }
74-
7558async function getLibraryDocsEntries (
7659 library : LibrarySlim ,
7760) : Promise < Array < SitemapEntry > > {
Original file line number Diff line number Diff line change 1+ import assert from 'node:assert/strict'
2+ import test from 'node:test'
3+ import { isHighValueDocsSlug } from '../src/utils/sitemap-docs'
4+
5+ test ( 'sitemap excludes repository artifacts while retaining public guides' , ( ) => {
6+ for ( const slug of [
7+ 'how-to/drafts/README' ,
8+ 'how-to/drafts/search-params-in-forms.draft' ,
9+ 'how-to/README' ,
10+ 'contributing/designs/source-failure/README' ,
11+ 'guide.draft' ,
12+ 'guides/readme' ,
13+ ] ) {
14+ assert . equal ( isHighValueDocsSlug ( slug ) , false , slug )
15+ }
16+ for ( const slug of [
17+ 'overview' ,
18+ 'framework/react/guides/query-keys' ,
19+ 'guides/draft' ,
20+ 'guides/readme-format' ,
21+ ] ) {
22+ assert . equal ( isHighValueDocsSlug ( slug ) , true , slug )
23+ }
24+ } )
25+ test ( 'existing sitemap exclusions remain excluded' , ( ) => {
26+ for ( const slug of [
27+ '' ,
28+ 'examples/basic' ,
29+ 'community/resources' ,
30+ 'community-resources' ,
31+ 'contributors' ,
32+ 'npm-stats' ,
33+ ] ) {
34+ assert . equal ( isHighValueDocsSlug ( slug ) , false , slug )
35+ }
36+ } )
You can’t perform that action at this time.
0 commit comments