You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sitemaps.js 1.2 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env node
  2. if (
  3. process.env.CONTEXT === 'production' &&
  4. process.env.BUILD_SITEMAP !== 'false'
  5. ) {
  6. const algoliaSitemap = require('algolia-sitemap');
  7. const { mkdirSync, existsSync } = require('fs');
  8. const algoliaConfig = {
  9. appId: 'OFCNCOG2CU',
  10. apiKey: process.env.ALGOLIA_BROWSE_KEY,
  11. indexName: 'npm-search',
  12. };
  13. function hitToParams(hit) {
  14. const url = ({ lang, name }) =>
  15. `https://yarnpkg.com/${lang}/package/${name}`;
  16. const loc = url({ lang: 'en', name: hit.name });
  17. const lastmod = new Date(hit.modified).toISOString();
  18. const priority = hit.downloadsRatio || 0.5;
  19. return {
  20. loc,
  21. lastmod,
  22. priority,
  23. alternates: {
  24. languages: ['fr', 'pt-BR', 'zh-Hans'],
  25. hitToURL: lang => url({ lang, name: hit.name }),
  26. },
  27. };
  28. }
  29. const path = `${__dirname}/../sitemaps`;
  30. if (!existsSync(path)) {
  31. mkdirSync(path);
  32. }
  33. algoliaSitemap({
  34. algoliaConfig,
  35. sitemapLoc: 'https://yarnpkg.com/sitemaps',
  36. outputFolder: path,
  37. hitToParams,
  38. })
  39. .then(() => console.log('Sitemap generated successfully'))
  40. .catch(e => {
  41. console.log(e);
  42. process.exit(1);
  43. });
  44. } else {
  45. console.log('sitemap generation skipped');
  46. }

js yarn包管理组件依赖分析

Contributors (1)