@@ -32,7 +32,7 @@ pub fn sidebar(slug: &str, locale: Locale) -> Result<MetaSidebar, DocError> {
32
32
}
33
33
if !matches ! (
34
34
main_object. as_ref( ) ,
35
- "Proxy" | "Atomics" | "Math" | "Intl" | "JSON" | "Reflect" ,
35
+ "Proxy" | "Atomics" | "Math" | "Intl" | "JSON" | "Reflect" | "Temporal" ,
36
36
) {
37
37
// %Base% is the default inheritance when the class has no extends clause:
38
38
// instances inherit from Object.prototype, and class inherits from Function.prototype
@@ -264,7 +264,7 @@ impl JSRefItem {
264
264
}
265
265
}
266
266
267
- const ASYNC_GENERATOR : & [ Cow < ' static , str > ] = & [ Cow :: Borrowed ( "AsyncGenerator" ) ] ;
267
+ const ASYNC_ITERATOR : & [ Cow < ' static , str > ] = & [ Cow :: Borrowed ( "AsyncGenerator" ) ] ;
268
268
const FUNCTION : & [ Cow < ' static , str > ] = & [
269
269
Cow :: Borrowed ( "AsyncFunction" ) ,
270
270
Cow :: Borrowed ( "AsyncGeneratorFunction" ) ,
@@ -275,6 +275,7 @@ const TYPED_ARRAY: &[Cow<'static, str>] = &[
275
275
Cow :: Borrowed ( "TypedArray" ) ,
276
276
Cow :: Borrowed ( "BigInt64Array" ) ,
277
277
Cow :: Borrowed ( "BigUint64Array" ) ,
278
+ Cow :: Borrowed ( "Float16Array" ) ,
278
279
Cow :: Borrowed ( "Float32Array" ) ,
279
280
Cow :: Borrowed ( "Float64Array" ) ,
280
281
Cow :: Borrowed ( "Int8Array" ) ,
@@ -297,12 +298,18 @@ const ERROR: &[Cow<'static, str>] = &[
297
298
Cow :: Borrowed ( "URIError" ) ,
298
299
] ;
299
300
301
+ static INTL_SUBPAGES : LazyLock < Vec < Cow < ' static , str > > > =
302
+ LazyLock :: new ( || namespace_subpages ( "Intl" ) ) ;
303
+ static TEMPORAL_SUBPAGES : LazyLock < Vec < Cow < ' static , str > > > =
304
+ LazyLock :: new ( || namespace_subpages ( "Temporal" ) ) ;
305
+
300
306
// Related pages
301
- fn get_group ( main_obj : & str , inheritance : & [ Cow < ' _ , str > ] ) -> Vec < Cow < ' static , str > > {
302
- static GROUP_DATA : LazyLock < Vec < & [ Cow < ' static , str > ] > > = LazyLock :: new ( || {
307
+ pub fn get_group ( main_obj : & str , inheritance : & [ Cow < ' _ , str > ] ) -> Vec < Cow < ' static , str > > {
308
+ static GROUP_DATA : LazyLock < Vec < & [ Cow < ' _ , str > ] > > = LazyLock :: new ( || {
303
309
vec ! [
304
310
ERROR ,
305
311
& INTL_SUBPAGES ,
312
+ & TEMPORAL_SUBPAGES ,
306
313
& [
307
314
Cow :: Borrowed ( "Intl/Segmenter/segment/Segments" ) ,
308
315
Cow :: Borrowed ( "Intl.Segmenter" ) ,
@@ -312,7 +319,7 @@ fn get_group(main_obj: &str, inheritance: &[Cow<'_, str>]) -> Vec<Cow<'static, s
312
319
]
313
320
} ) ;
314
321
for g in GROUP_DATA . iter ( ) {
315
- if g. iter ( ) . any ( |x| main_obj == x ) {
322
+ if g. contains ( & Cow :: Borrowed ( main_obj) ) {
316
323
return g
317
324
. iter ( )
318
325
. filter ( |x| !inheritance. contains ( x) )
@@ -325,7 +332,7 @@ fn get_group(main_obj: &str, inheritance: &[Cow<'_, str>]) -> Vec<Cow<'static, s
325
332
326
333
fn inheritance_data ( obj : & str ) -> Option < & str > {
327
334
match obj {
328
- o if ASYNC_GENERATOR . iter ( ) . any ( |x| x == o) => Some ( "AsyncIterator" ) ,
335
+ o if ASYNC_ITERATOR . iter ( ) . any ( |x| x == o) => Some ( "AsyncIterator" ) ,
329
336
o if FUNCTION . iter ( ) . any ( |x| x == o) => Some ( "Function" ) ,
330
337
o if ITERATOR . iter ( ) . any ( |x| x == o) => Some ( "Iterator" ) ,
331
338
o if TYPED_ARRAY [ 1 ..] . iter ( ) . any ( |x| x == o) => Some ( "TypedArray" ) ,
@@ -334,21 +341,31 @@ fn inheritance_data(obj: &str) -> Option<&str> {
334
341
}
335
342
}
336
343
337
- static INTL_SUBPAGES : LazyLock < Vec < Cow < ' static , str > > > = LazyLock :: new ( || {
338
- once ( Cow :: Borrowed ( "Intl" ) )
344
+ /// Intl and Temporal are big namespaces with many classes underneath it. The classes
345
+ /// are shown as related pages.
346
+ fn namespace_subpages ( namespace : & str ) -> Vec < Cow < ' _ , str > > {
347
+ once ( Cow :: Borrowed ( namespace) )
339
348
. chain (
340
349
get_sub_pages (
341
- "/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl" ,
350
+ & format ! (
351
+ "/en-US/docs/Web/JavaScript/Reference/Global_Objects/{}" ,
352
+ namespace
353
+ ) ,
342
354
Some ( 1 ) ,
343
355
Default :: default ( ) ,
344
356
)
345
357
. unwrap_or_default ( )
346
358
. iter ( )
347
- . filter ( |page| page. page_type ( ) == PageType :: JavascriptClass )
359
+ . filter ( |page| {
360
+ matches ! (
361
+ page. page_type( ) ,
362
+ PageType :: JavascriptClass | PageType :: JavascriptNamespace
363
+ )
364
+ } )
348
365
. map ( |page| Cow :: Owned ( slug_to_object_name ( page. slug ( ) ) . to_string ( ) ) ) ,
349
366
)
350
367
. collect ( )
351
- } ) ;
368
+ }
352
369
353
370
fn slug_to_object_name ( slug : & str ) -> Cow < ' _ , str > {
354
371
let sub_path = slug
@@ -360,18 +377,24 @@ fn slug_to_object_name(slug: &str) -> Cow<'_, str> {
360
377
if sub_path. starts_with ( "Proxy/Proxy" ) {
361
378
return "Proxy/handler" . into ( ) ;
362
379
}
363
- if let Some ( intl) = sub_path. strip_prefix ( "Intl/" ) {
364
- if intl
365
- . chars ( )
366
- . next ( )
367
- . map ( |c| c. is_ascii_lowercase ( ) )
368
- . unwrap_or_default ( )
369
- {
370
- return "Intl" . into ( ) ;
380
+ for namespace in & [ "Intl/" , "Temporal/" ] {
381
+ if let Some ( sub_sub_path) = sub_path. strip_prefix ( namespace) {
382
+ if sub_sub_path
383
+ . chars ( )
384
+ . next ( )
385
+ . map ( |c| c. is_ascii_lowercase ( ) )
386
+ . unwrap_or_default ( )
387
+ {
388
+ return Cow :: Borrowed ( & namespace[ ..namespace. len ( ) - 1 ] ) ;
389
+ }
390
+ return Cow :: Owned (
391
+ sub_path[ ..sub_sub_path
392
+ . find ( '/' )
393
+ . map ( |i| i + namespace. len ( ) )
394
+ . unwrap_or ( sub_path. len ( ) ) ]
395
+ . replace ( '/' , "." ) ,
396
+ ) ;
371
397
}
372
- return Cow :: Owned (
373
- sub_path[ ..intl. find ( '/' ) . map ( |i| i + 5 ) . unwrap_or ( sub_path. len ( ) ) ] . replace ( '/' , "." ) ,
374
- ) ;
375
398
}
376
399
377
400
sub_path[ ..sub_path. find ( '/' ) . unwrap_or ( sub_path. len ( ) ) ] . into ( )
@@ -397,6 +420,16 @@ mod test {
397
420
) ,
398
421
"Intl.DateTimeFormat"
399
422
) ;
423
+ assert_eq ! (
424
+ slug_to_object_name( "Web/JavaScript/Reference/Global_Objects/Temporal/Now" ) ,
425
+ "Temporal.Now"
426
+ ) ;
427
+ assert_eq ! (
428
+ slug_to_object_name(
429
+ "Web/JavaScript/Reference/Global_Objects/Temporal/Now/plainDateISO"
430
+ ) ,
431
+ "Temporal.Now"
432
+ ) ;
400
433
assert_eq ! (
401
434
slug_to_object_name(
402
435
"Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength"
0 commit comments