@@ -7,6 +7,10 @@ import {
77} from 'axe-playwright' ;
88import Sitemapper from 'sitemapper' ;
99
10+ // We use the Lunaria config to get the list of languages rather than the Astro config as importing
11+ // the latter does not play well with Playwright.
12+ import lunariaConfig from '../lunaria.config.json' assert { type : 'json' } ;
13+
1014export { expect , type Locator } from '@playwright/test' ;
1115
1216const config : Config = {
@@ -17,29 +21,35 @@ const config: Config = {
1721 values : [ 'wcag2a' , 'wcag21a' , 'wcag2aa' , 'wcag21aa' , 'wcag22aa' , 'best-practice' ] ,
1822 } ,
1923 } ,
24+ // i18n specific configuration.
25+ i18n : {
26+ // A list of slugs to exclude from the sitemap for the default locale.
27+ // By default, all slugs for the default locale are included.
28+ exclude : [
29+ 'components/using-components' ,
30+ 'getting-started' ,
31+ 'guides/customization' ,
32+ 'guides/i18n' ,
33+ 'guides/overriding-components' ,
34+ 'guides/pages' ,
35+ 'guides/project-structure' ,
36+ 'guides/route-data' ,
37+ 'guides/site-search' ,
38+ 'manual-setup' ,
39+ 'reference/frontmatter' ,
40+ 'reference/overrides' ,
41+ 'reference/plugins' ,
42+ 'reference/route-data' ,
43+ ] ,
44+ // Locale-specific included slugs (non-default locale slugs are excluded by default).
45+ locales : {
46+ ja : [ 'guides/route-data' , 'reference/frontmatter' ] ,
47+ } ,
48+ } ,
2049 // A list of violation to ignore.
2150 ignore : [ { id : 'landmark-unique' , nodeMatcher : landmarkUniqueNodeMatcher } ] ,
2251 sitemap : {
2352 url : 'http://localhost:4321/sitemap-index.xml' ,
24- exclude : {
25- // A pattern to exclude URLs from the sitemap.
26- pattern : / \/ ( d e | z h - c n | f r | e s | p t - b r | p t - p t | i t | i d | k o | r u | t r | h i | d a | u k ) \/ .* / ,
27- // A list of slugs to exclude from the sitemap after processing the pattern.
28- slugs : [
29- 'components/using-components' ,
30- 'getting-started' ,
31- 'guides/customization' ,
32- 'guides/i18n' ,
33- 'guides/overriding-components' ,
34- 'guides/pages' ,
35- 'guides/project-structure' ,
36- 'guides/site-search' ,
37- 'manual-setup' ,
38- 'reference/frontmatter' ,
39- 'reference/overrides' ,
40- 'reference/plugins' ,
41- ] ,
42- } ,
4353 replace : {
4454 query : 'https://starlight.astro.build' ,
4555 value : 'http://localhost:4321' ,
@@ -50,6 +60,8 @@ const config: Config = {
5060process . env . ASTRO_TELEMETRY_DISABLED = 'true' ;
5161process . env . ASTRO_DISABLE_UPDATE_CHECK = 'true' ;
5262
63+ const locales = lunariaConfig . locales . map ( ( locale ) => locale . lang ) ;
64+
5365export const test = baseTest . extend < {
5466 docsSite : DocsSite ;
5567} > ( {
@@ -71,9 +83,24 @@ class DocsSite {
7183 const urls : string [ ] = [ ] ;
7284
7385 for ( const site of sites ) {
74- const url = site . replace ( config . sitemap . replace . query , config . sitemap . replace . value ) ;
75- if ( config . sitemap . exclude . pattern . test ( url ) ) continue ;
76- if ( config . sitemap . exclude . slugs . some ( ( slug ) => url . endsWith ( `/${ slug } /` ) ) ) continue ;
86+ const slug = site . replace ( config . sitemap . replace . query , '' ) ;
87+ const url = config . sitemap . replace . value + slug ;
88+
89+ // Default locale
90+ if ( ! locales . some ( ( locale ) => slug . startsWith ( `/${ locale } /` ) ) ) {
91+ // Skip default locale excluded slugs
92+ if ( config . i18n . exclude . some ( ( excludedSlug ) => slug . endsWith ( `/${ excludedSlug } /` ) ) )
93+ continue ;
94+ } else {
95+ // Get locale-specific config
96+ const locale = slug . split ( '/' ) [ 1 ] ! ;
97+ const localeConfig = config . i18n . locales [ locale ] ;
98+ // Skip non-configured locales
99+ if ( ! localeConfig ) continue ;
100+ // Skip locale-specific non-included slugs
101+ if ( ! localeConfig . some ( ( includedSlug ) => slug . endsWith ( `/${ includedSlug } /` ) ) ) continue ;
102+ }
103+
77104 urls . push ( url ) ;
78105 }
79106
@@ -129,6 +156,7 @@ function landmarkUniqueNodeMatcher(node: ViolationNode) {
129156
130157interface Config {
131158 axe : Parameters < typeof getViolations > [ 2 ] ;
159+ i18n : { exclude : string [ ] ; locales : Record < string , string [ ] > } ;
132160 ignore : Array <
133161 | string
134162 | {
@@ -140,10 +168,6 @@ interface Config {
140168 > ;
141169 sitemap : {
142170 url : string ;
143- exclude : {
144- pattern : RegExp ;
145- slugs : string [ ] ;
146- } ;
147171 replace : {
148172 query : string ;
149173 value : string ;
0 commit comments