@@ -2,25 +2,31 @@ const { existsSync } = require("fs");
22const { writeFile } = require ( "fs/promises" ) ;
33const { join } = require ( "path" ) ;
44const { format } = require ( "prettier" ) ;
5- const { findAllPages } = require ( "./find-all-pages" ) ;
5+ const {
6+ clean,
7+ EXCLUDED_PAGES ,
8+ findAllPages,
9+ LOCALES ,
10+ pathWithoutLocaleReducer
11+ } = require ( "./find-all-pages" ) ;
612
713const BASE_URL = "https://hyperjump.tech" ;
814// Next.js export directory
915const OUTPUT_DIR = join ( process . cwd ( ) , "out" ) ;
10- const LOCALES = [ "en" , "id" ] ;
11- const EXCLUDED_PAGES = [ "_not-found" , "404" ] ;
1216
1317await ( async function generateSitemap ( ) {
1418 if ( ! existsSync ( OUTPUT_DIR ) ) {
1519 console . error ( "❌ Output directory 'out' not found." ) ;
1620 return ;
1721 }
1822
19- const sitemapUrls = findAllPages ( OUTPUT_DIR )
23+ const paths = findAllPages ( OUTPUT_DIR )
2024 . filter ( ( path ) => ! EXCLUDED_PAGES . includes ( path ) )
21- . filter ( removePathWithLocale )
22- . sort ( )
23- . map ( ( path ) => generateSitemapURL ( path ) . join ( "\n " ) ) ;
25+ . reduce ( pathWithoutLocaleReducer , [ ] )
26+ . sort ( ) ;
27+ const sitemapUrls = paths . map ( ( path ) =>
28+ generateSitemapURL ( path ) . join ( "\n " )
29+ ) ;
2430
2531 await writeFile (
2632 join ( OUTPUT_DIR , "sitemap.xml" ) ,
@@ -29,17 +35,12 @@ await (async function generateSitemap() {
2935 } ) ,
3036 "utf8"
3137 ) ;
32- console . log ( "✅ Sitemap generated" ) ;
33- } ) ( ) ;
3438
35- function removePathWithLocale ( path ) {
36- for ( const locale of LOCALES ) {
37- if ( path . startsWith ( locale ) ) {
38- return false ;
39- }
39+ for ( const path of paths ) {
40+ console . info ( `Generated sitemap: /${ path } ` ) ;
4041 }
41- return true ;
42- }
42+ console . info ( "✅ Sitemap generated" ) ;
43+ } ) ( ) ;
4344
4445function generateSitemapURL ( path ) {
4546 return LOCALES . map (
@@ -52,10 +53,6 @@ function generateSitemapURL(path) {
5253 ) ;
5354}
5455
55- function clean ( path ) {
56- return path ? `/${ path } ` : "" ;
57- }
58-
5956function alternateLinks ( path ) {
6057 return LOCALES . map ( ( locale ) =>
6158 `<xhtml:link rel="alternate" hreflang="${ locale } " href="${ BASE_URL } /${ locale } ${ clean ( path ) } "/>` . trim ( )
0 commit comments