-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
executable file
·41 lines (37 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require('dotenv').config();
const algoliaSitemap = require('algolia-sitemap');
const { mkdirSync, copyFileSync } = require('fs');
const algoliaConfig = {
appId: 'OFCNCOG2CU',
apiKey: process.env.ALGOLIA_BROWSE_KEY,
indexName: 'npm-search',
};
function hitToParams(hit) {
const url = ({ lang, name }) => `https://yarnpkg.com/${lang}/package/${name}`;
const loc = url({ lang: 'en', name: hit.name });
const lastmod = new Date(hit.modified).toISOString();
const priority = hit.downloadsRatio || 0.5;
return {
loc,
lastmod,
priority,
alternates: {
languages: ['fr', 'pt-BR', 'zh-Hans'],
hitToURL: lang => url({ lang, name: hit.name }),
},
};
}
mkdirSync('build', { recursive: true });
algoliaSitemap({
algoliaConfig,
sitemapLoc: 'https://sitemap.yarnpkg.com',
outputFolder: 'build',
hitToParams,
})
.then(() => console.log('Sitemap generated successfully'))
.then(() => copyFileSync('index.html', 'build/index.html'))
.then(() => console.log('Copied index'))
.catch(e => {
console.log(e);
process.exit(1);
});