
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
algolia-sitemap
Advanced tools
This is a node library allowing you to generate sitemaps from an Algolia index.
This is a node library allowing you to generate sitemaps from an Algolia index.
Requires node v6+ (make an issue if this is a problem for you).
It will create sitemaps, and a sitemap index in a folder of your choosing (for example /sitemaps
). Then you can upload /sitemaps/sitemap-index.xml
to Google for good indexing of your pages!
This process is a script that should be ran periodically to keep the sitemaps up to date, no "watch" feature has been put in place (yet?)
First install the module from npm
(or with yarn
):
$ npm install algolia-sitemap --save[-dev]
$ yarn add algolia-sitemap [--dev]
// import the dependency
const algoliaSitemap = require('algolia-sitemap');
algoliaSitemap({
algoliaConfig,
sitemapLoc: 'https://yoursite.com/sitemaps',
outputFolder: 'sitemaps',
hitToParams,
});
Where algoliaConfig
holds the setup for your index. Make sure that the API key you use has the "browse" capability
// set up your API keys
const algoliaConfig = {
appId: 'XXXXX',
apiKey: 'xxxxxx', // make sure the key has "browse" capability
indexName: 'xxxxxx',
};
And hitToParams is a function that transforms a hit into a parameters object. This function can return an object of type Param
, an array of Param
s or false.
function hitToParams({ objectID, modified, downloadsRatio }) {
const url = ({ lang, objectID }) =>
`https://${lang}.yoursite.com/${lang}/detail/${objectID}`;
const loc = url({ lang: 'en', objectID });
const lastmod = new Date().toISOString();
const priority = Math.random();
return {
loc,
lastmod,
priority,
alternates: {
languages: ['fr', 'pt-BR', 'zh-Hans'],
hitToURL: lang => url({ lang, objectID }),
},
};
}
These parameters mean:
/**
* @typedef {Object} Params
* @property {string} loc the link of this hit
* @property {string} [lastmod] the last time this link was modified (ISO8601)
* @property {number} [priority] the priority you give to this link (between 0 and 1)
* @property {Object} [alternates] alternative versions of this link (useful for multi-language)
* @property {Array} [alternates.languages] list of languages that are enabled
* @property {Array} [images] list of images links related to the hit
* @property {function} [alternates.hitToURL] function to transform a language into a url of this object
*/
If you want your sitemap to include Google image extensions, return an array for each hit containing objects with the following keys:
/**
* @typedef {Object} Image
* @property {string} loc the link of this image
* @property {string} [title] image title
* @property {string} [caption] image caption
* @property {string} [geo_location] geographic location (e.g. 'Limerick, Ireland')
* @property {string} [license] the link to the image's license
*/
For example:
function hitToParams({
objectID,
modified,
downloadsRatio,
profilePic,
coverPhoto,
name,
}) {
const url = ({ lang, objectID }) =>
`https://${lang}.yoursite.com/${lang}/detail/${objectID}`;
const loc = url({ lang: 'en', objectID });
const lastmod = new Date().toISOString();
const priority = Math.random();
return {
loc,
lastmod,
priority,
images: [
{
loc: `https://media.yoursite.com/images/${profilePic}`,
title: name,
},
{
loc: `https://media.yoursite.com/images/${coverPhoto}`,
title: name,
},
],
alternates: {
languages: ['fr', 'pt-BR', 'zh-Hans'],
hitToURL: lang => url({ lang, objectID }),
},
};
}
For more information, see https://support.google.com/webmasters/answer/178636?hl=en
You can pass a params
parameter to algoliaSitemap
. This allows you to narrow down the returned results. For instance, in order to have hitToParams
called for every products in the phone
category, we could do:
algoliaSitemap({
algoliaConfig,
sitemapLoc: 'https://yoursite.com/sitemaps',
outputFolder: 'sitemaps',
params: {
filters: 'category: phone',
},
hitToParams,
});
Note that a query can also be passed to params
.
You can also take a look at examples
folder for how it works.
MIT
2.2.2
FAQs
This is a node library allowing you to generate sitemaps from an Algolia index.
The npm package algolia-sitemap receives a total of 2,494 weekly downloads. As such, algolia-sitemap popularity was classified as popular.
We found that algolia-sitemap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.