1
+ import fs from 'fs' ;
2
+ import { globby } from 'globby' ;
3
+ import prettier from 'prettier' ;
4
+
5
+ async function generate ( ) {
6
+ const prettierConfig = await prettier . resolveConfig ( './.prettierrc' ) ;
7
+
8
+ // Get static pages
9
+ const pages = await globby ( [
10
+ 'app/**/page.tsx' ,
11
+ '!app/**/_*/**' ,
12
+ '!app/**/api/**' ,
13
+ '!app/docs/**' , // Exclude docs directory as we'll handle it separately
14
+ ] ) ;
15
+
16
+ // Get doc pages from the build output
17
+ const docPages = await globby ( [ 'out/docs/**/*.html' ] )
18
+ . then ( pages => pages
19
+ . map ( page => page
20
+ . replace ( 'out' , '' )
21
+ . replace ( '/index.html' , '' )
22
+ . replace ( '.html' , '' )
23
+ )
24
+ . filter ( page => ! page . includes ( '/_' ) )
25
+ ) ;
26
+
27
+ // Get blog pages from the build output
28
+ const blogPages = await globby ( [ 'out/blog/**/*.html' ] )
29
+ . then ( pages => pages
30
+ . map ( page => page
31
+ . replace ( 'out' , '' )
32
+ . replace ( '/index.html' , '' )
33
+ . replace ( '.html' , '' )
34
+ )
35
+ . filter ( page => ! page . includes ( '/_' ) && ! page . includes ( '/blog/index' ) )
36
+ ) ;
37
+
38
+ const baseUrl = 'https://amical.ai' ;
39
+
40
+ const sitemap = `
41
+ <?xml version="1.0" encoding="UTF-8"?>
42
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
43
+ ${ [
44
+ // Add static pages
45
+ ...pages . map ( ( page ) => {
46
+ const path = page
47
+ . replace ( 'app' , '' )
48
+ . replace ( '/page.tsx' , '' )
49
+ . replace ( '/(home)' , '' )
50
+ . replace ( / \[ \[ \. \. \. .* ?\] \] / , '' ) ;
51
+
52
+ // Skip dynamic routes with parameters
53
+ if ( path . includes ( '[' ) || path . includes ( ']' ) ) {
54
+ return '' ;
55
+ }
56
+
57
+ const route = path === '' ? '' : path ;
58
+
59
+ return `
60
+ <url>
61
+ <loc>${ baseUrl } ${ route } </loc>
62
+ <lastmod>${ new Date ( ) . toISOString ( ) } </lastmod>
63
+ <changefreq>daily</changefreq>
64
+ <priority>0.7</priority>
65
+ </url>
66
+ ` ;
67
+ } ) ,
68
+ // Add docs index page
69
+ `
70
+ <url>
71
+ <loc>${ baseUrl } /docs</loc>
72
+ <lastmod>${ new Date ( ) . toISOString ( ) } </lastmod>
73
+ <changefreq>daily</changefreq>
74
+ <priority>0.7</priority>
75
+ </url>
76
+ ` ,
77
+ // Add doc pages
78
+ ...docPages . map ( ( path ) => `
79
+ <url>
80
+ <loc>${ baseUrl } ${ path } </loc>
81
+ <lastmod>${ new Date ( ) . toISOString ( ) } </lastmod>
82
+ <changefreq>daily</changefreq>
83
+ <priority>0.7</priority>
84
+ </url>
85
+ ` ) ,
86
+ // Add blog index page
87
+ `
88
+ <url>
89
+ <loc>${ baseUrl } /blog</loc>
90
+ <lastmod>${ new Date ( ) . toISOString ( ) } </lastmod>
91
+ <changefreq>weekly</changefreq>
92
+ <priority>0.8</priority>
93
+ </url>
94
+ ` ,
95
+ // Add blog pages
96
+ ...blogPages . map ( ( path ) => `
97
+ <url>
98
+ <loc>${ baseUrl } ${ path } </loc>
99
+ <lastmod>${ new Date ( ) . toISOString ( ) } </lastmod>
100
+ <changefreq>weekly</changefreq>
101
+ <priority>0.7</priority>
102
+ </url>
103
+ ` ) ,
104
+ ]
105
+ . filter ( Boolean )
106
+ . join ( '' ) }
107
+ </urlset>
108
+ ` ;
109
+
110
+ const formatted = await prettier . format ( sitemap , {
111
+ ...prettierConfig ,
112
+ parser : 'html' ,
113
+ } ) ;
114
+
115
+ fs . writeFileSync ( 'public/sitemap.xml' , formatted ) ;
116
+ fs . writeFileSync ( 'out/sitemap.xml' , formatted ) ;
117
+
118
+ console . log ( '✅ Generated sitemap.xml' ) ;
119
+ }
120
+
121
+ generate ( ) . catch ( ( err ) => {
122
+ console . error ( err ) ;
123
+ process . exit ( 1 ) ;
124
+ } ) ;
0 commit comments