@@ -13,6 +13,10 @@ const PATHS = {
1313 cname : BUILD_DIR + "/CNAME" ,
1414} ;
1515
16+ function normalizeLineEndings ( text : string ) {
17+ return text . replace ( / \r \n / g, "\n" ) ;
18+ }
19+
1620function generateSitemapXml ( ) {
1721 const date = new Date ( ) ;
1822 const lastModified = `${ date . getFullYear ( ) } -${ date . getMonth ( ) + 1 } -${ date . getDate ( ) } ` ;
@@ -43,16 +47,16 @@ function generateSitemapXml() {
4347 ${ pages . join ( "" ) }
4448</urlset>` ;
4549
46- return sitemap . trim ( ) ;
50+ return normalizeLineEndings ( sitemap . trim ( ) ) ;
4751}
4852
4953function generateRobotsTxt ( ) {
5054 const sitemapUrl = BASE_URL + PATHS . sitemapXml . replace ( BUILD_DIR + "/" , "" ) ;
5155
52- return `# https://www.robotstxt.org/robotstxt.html
56+ return normalizeLineEndings ( `# https://www.robotstxt.org/robotstxt.html
5357User-agent: *
5458Disallow:
55- Sitemap: ${ sitemapUrl } ` ;
59+ Sitemap: ${ sitemapUrl } ` ) ;
5660}
5761
5862function generateCname ( ) {
@@ -73,7 +77,7 @@ function generateTemplate(html: string) {
7377 fs . writeFileSync ( path , html , { flag : "w+" } ) ;
7478 console . log ( `- ${ ANSI . fg . cyan } ${ path } ${ ANSI . reset } ` ) ;
7579
76- return html ;
80+ return normalizeLineEndings ( html ) ;
7781}
7882
7983/**
@@ -125,13 +129,13 @@ function stage() {
125129 console . log ( `Context: ${ ANSI . decoration . bold } ${ name } ${ ANSI . reset } \n` ) ;
126130 console . log ( `${ ANSI . fg . yellow } Staging build...${ ANSI . reset } ` ) ;
127131
128- const files : [ string , ( ) => string ] [ ] = [
132+ const metaFiles : [ string , ( ) => string ] [ ] = [
129133 [ PATHS . sitemapXml , generateSitemapXml ] ,
130134 [ PATHS . robotsTxt , generateRobotsTxt ] ,
131135 [ PATHS . cname , generateCname ] ,
132136 ] ;
133137
134- files . forEach ( ( [ path , generateContent ] ) => {
138+ metaFiles . forEach ( ( [ path , generateContent ] ) => {
135139 const directory = path . substring ( 0 , path . lastIndexOf ( "/" ) ) ;
136140 if ( directory != "" && ! fs . existsSync ( directory ) )
137141 fs . mkdirSync ( directory , { recursive : true } ) ;
0 commit comments