11import { createWriteStream } from 'fs' ;
2- import { resolve as resolvePath } from 'path' ;
3- import { SitemapStream } from 'sitemap' ;
4- import { UserConfig , DefaultTheme } from 'vitepress' ;
52import fs from 'fs/promises' ;
3+ import { resolve as resolvePath } from 'path' ;
4+
65import algoliasearch from 'algoliasearch' ;
76import parseMarkdownMetadata from 'parse-md' ;
7+ import { SitemapStream } from 'sitemap' ;
8+ import type { UserConfig , DefaultTheme } from 'vitepress' ;
9+
10+ import { currentBuildVersion , LATEST } from './vite.config' ;
11+ import { algoliaConfig } from '../../algoliaConfig.js' ;
12+ import { algoliaIndexes } from '../../algoliaIndexes.js' ;
813import iconsList from '../style/icon/icons-list.js' ;
914import illustrationsList from '../style/illustration/illustrations-list.js' ;
1015
1116import 'dotenv/config' ;
12- import { algoliaConfig } from '../../algoliaConfig.js' ;
1317
1418const excludeFromSearch = [ 'a11y-report' ] ;
1519
@@ -31,6 +35,10 @@ if (process.env.CI) {
3135 }
3236}
3337
38+ const BASE_URL = `https://developer.semrush.com/intergalactic/${
39+ currentBuildVersion === LATEST ? '' : `${ currentBuildVersion } /`
40+ } `;
41+
3442const sitemapLinks : { url : string ; lastmod ?: number } [ ] = [ ] ;
3543const searchObjects : {
3644 objectID : number ;
@@ -116,10 +124,7 @@ const transformHtml: UserConfig<DefaultTheme.Config>['transformHtml'] = async (
116124 objectID : objectId ++ ,
117125 title : title ,
118126 type : level ,
119- url :
120- 'https://developer.semrush.com/intergalactic/' +
121- pageData . relativePath . replace ( / ( ( ^ | \/ ) i n d e x ) ? \. m d $ / , '$2' ) +
122- `#${ id } ` ,
127+ url : BASE_URL + pageData . relativePath . replace ( / ( ( ^ | \/ ) i n d e x ) ? \. m d $ / , '$2' ) + `#${ id } ` ,
123128 heading : true ,
124129 hierarchy : { ...hierarchy } ,
125130 changelogPage : pageData . relativePath . includes ( 'changelog' ) ,
@@ -134,9 +139,7 @@ const transformHtml: UserConfig<DefaultTheme.Config>['transformHtml'] = async (
134139 title : metadata ?. title ?? pageData . title ,
135140 content : metadata ?. title ?? pageData . title ,
136141 type : 'content' ,
137- url :
138- 'https://developer.semrush.com/intergalactic/' +
139- pageData . relativePath . replace ( / ( ( ^ | \/ ) i n d e x ) ? \. m d $ / , '$2' ) ,
142+ url : BASE_URL + pageData . relativePath . replace ( / ( ( ^ | \/ ) i n d e x ) ? \. m d $ / , '$2' ) ,
140143 heading : false ,
141144 hierarchy : { lvl0 : hierarchy . lvl0 , lvl1 : hierarchy . lvl1 } ,
142145 changelogPage : pageData . relativePath . includes ( 'changelog' ) ,
@@ -147,7 +150,7 @@ const transformHtml: UserConfig<DefaultTheme.Config>['transformHtml'] = async (
147150} ;
148151const buildEnd : UserConfig < DefaultTheme . Config > [ 'buildEnd' ] = async ( { outDir } ) => {
149152 const sitemap = new SitemapStream ( {
150- hostname : 'https://developer.semrush.com/intergalactic/' ,
153+ hostname : BASE_URL ,
151154 } ) ;
152155 const writeStream = createWriteStream ( resolvePath ( outDir , 'sitemap.xml' ) ) ;
153156 sitemap . pipe ( writeStream ) ;
@@ -158,9 +161,9 @@ const buildEnd: UserConfig<DefaultTheme.Config>['buildEnd'] = async ({ outDir })
158161 if ( process . env . CI ) {
159162 // await fs.writeFile('search-index.json', JSON.stringify(searchObjects, null, 2));
160163 const client = algoliasearch ( algoliaConfig . appName , process . env . ALGOLIA_SECRET_KEY ! ) ;
161- const mainSearchIndex = client . initIndex ( algoliaConfig . mainSearchIndexName ) ;
162- const iconsSearchIndex = client . initIndex ( algoliaConfig . iconsSearchIndexName ) ;
163- const illustrationsSearchIndex = client . initIndex ( algoliaConfig . illustrationsSearchIndexName ! ) ;
164+ const mainSearchIndex = client . initIndex ( algoliaIndexes . mainSearchIndexName ) ;
165+ const iconsSearchIndex = client . initIndex ( algoliaIndexes . iconsSearchIndexName ) ;
166+ const illustrationsSearchIndex = client . initIndex ( algoliaIndexes . illustrationsSearchIndexName ! ) ;
164167
165168 const iconsSearchObjects = iconsList . icons . map ( ( o , i ) => ( { objectID : i , ...o } ) ) ;
166169 const illustrationsSearchObjects = illustrationsList . illustrations . map ( ( o , i ) => ( {
0 commit comments