An open API service indexing awesome lists of open source software.

https://github.com/jpoehnelt/eleventy-plugin-related

Plugin for related posts in Eleventy.
https://github.com/jpoehnelt/eleventy-plugin-related

eleventy eleventy-plugin natural nlp tf-idf

Last synced: 8 months ago
JSON representation

Plugin for related posts in Eleventy.

Awesome Lists containing this project

README

          

# eleventy-plugin-related

[![npm](https://img.shields.io/npm/v/eleventy-plugin-related)](https://www.npmjs.com/package/eleventy-plugin-related)
![Build](https://github.com/jpoehnelt/eleventy-plugin-related/workflows/Build/badge.svg)
![Release](https://github.com/jpoehnelt/eleventy-plugin-related/workflows/Release/badge.svg)
[![Docs](https://img.shields.io/badge/documentation-api-brightgreen)](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

Related



    {% for result in story | related(stories) %}
  • {{ result.relative }} - {{ result.document.title }}

  • {% endfor %}

```

For more complex options, check out the package [related-documents](https://www.npmjs.com/package/related-documents), on which this package is based.