eleventy-plugin-related
Version:
Find related documents in eleventy.
44 lines (32 loc) • 1.21 kB
Markdown
# eleventy-plugin-related
[](https://www.npmjs.com/package/eleventy-plugin-related)


[](https://jpoehnelt.github.io/eleventy-plugin-related/)
## Description
Filter and/or short code to rank text documents by similarity.
## Install
Install using NPM or similar.
```sh
npm i eleventy-plugin-related
```
## Usage
```js
eleventyConfig.addFilter(
"related",
require("eleventy-plugin-related").related({
serializer: (doc) => [doc.title, doc.link ?? "", doc.text ?? ""],
weights: [10, 1, 3],
})
);
```
Usage in a NunJucks template would look similar to the following.
```html
<h3>Related</h3>
<ul>
{% for result in story | related(stories) %}
<li>{{ result.relative }} - {{ result.document.title }}</li>
{% endfor %}
</ul>
```
For more complex options, check out the package [related-documents](https://www.npmjs.com/package/related-documents), on which this package is based.