astro-relatinator 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,13 +28,16 @@ export default defineConfig({
|
|
|
28
28
|
integrations: [
|
|
29
29
|
// ...
|
|
30
30
|
relatinatorIntegration({
|
|
31
|
-
paths: ["./src/content/posts"],
|
|
31
|
+
paths: ["./src/content/posts"], // path yo your content files
|
|
32
|
+
schema: ["title", "descriptions", "tags"], // frontmatter fields to use for training
|
|
32
33
|
}),
|
|
33
34
|
// ...
|
|
34
35
|
],
|
|
35
36
|
});
|
|
36
37
|
```
|
|
37
38
|
|
|
39
|
+
__Note:__ the fields you specify in the `schema` array must be present in the frontmatter of the files you're training on. If they're not, the integration will throw an error or lead to unexpected results.
|
|
40
|
+
|
|
38
41
|
## Usage
|
|
39
42
|
|
|
40
43
|
The integration hooks into the Astro build (or dev) process, and will traing the tf-idf model based on the files you've provided. You can then use the `find` function from the package to find related content.
|
|
@@ -43,12 +46,29 @@ The integration hooks into the Astro build (or dev) process, and will traing the
|
|
|
43
46
|
|
|
44
47
|
```astro
|
|
45
48
|
---
|
|
49
|
+
import { getCollection } from "astro:content";
|
|
46
50
|
import { find } from "astro-relatinator";
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
const blogEntries = await getCollection("posts"); // assuming your collection is called posts
|
|
53
|
+
// let's say we want to compare against the first blog entry
|
|
54
|
+
const first = blogEntries[0];
|
|
49
55
|
|
|
50
|
-
|
|
56
|
+
// Concatenate the same fields we used for training and declare how many related posts we want to find
|
|
57
|
+
const related = find(`${first.frontmatter.title} ${first.frontmatter.description} ${first.frontmatter.tags.join(' ')} ${first.body}`, 3)
|
|
51
58
|
|
|
52
59
|
---
|
|
53
60
|
|
|
61
|
+
<div>
|
|
62
|
+
<!-- render your related posts here -->
|
|
63
|
+
{ related.map((id) => {
|
|
64
|
+
const post = posts.find((post) => post.id === id);
|
|
65
|
+
return (
|
|
66
|
+
<a href={post.slug}>
|
|
67
|
+
<h2>{post.frontmatter.title}</h2>
|
|
68
|
+
<p>{post.frontmatter.description}</p>
|
|
69
|
+
</a>
|
|
70
|
+
);
|
|
71
|
+
}) }
|
|
72
|
+
</div>
|
|
73
|
+
|
|
54
74
|
```
|