astro-relatinator 2.0.0 → 2.0.1
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/integration.ts +31 -10
- package/package.json +3 -3
package/integration.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { TfIdfUtils, BM25Utils } from "relatinator";
|
|
4
4
|
import { glob } from "glob";
|
|
5
5
|
import matter from "gray-matter";
|
|
6
6
|
import fs from "node:fs/promises";
|
|
@@ -11,7 +11,12 @@ async function writeDebug(message: string) {
|
|
|
11
11
|
console.log("[astro-relatinator]", message);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
async function trainModel(
|
|
14
|
+
async function trainModel(
|
|
15
|
+
similarityMethod: "tfidf" | "bm25",
|
|
16
|
+
paths: string[],
|
|
17
|
+
schema: string[],
|
|
18
|
+
debug = false
|
|
19
|
+
) {
|
|
15
20
|
const documents: RelatinatorDocument[] = [];
|
|
16
21
|
|
|
17
22
|
if (debug) {
|
|
@@ -62,7 +67,11 @@ async function trainModel(paths: string[], schema: string[], debug = false) {
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
// Train the existing instance
|
|
65
|
-
|
|
70
|
+
if (similarityMethod === "tfidf") {
|
|
71
|
+
TfIdfUtils.train(documents, debug);
|
|
72
|
+
} else {
|
|
73
|
+
BM25Utils.train(documents, debug);
|
|
74
|
+
}
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
const stringifyData = (data: any): string => {
|
|
@@ -97,8 +106,12 @@ const relatinatorIntegration = ({
|
|
|
97
106
|
logger.info(
|
|
98
107
|
`Training Relatinator using ${similarityMethod} on existing data...`
|
|
99
108
|
);
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
if (similarityMethod === "tfidf") {
|
|
110
|
+
await TfIdfUtils.getInstance();
|
|
111
|
+
} else {
|
|
112
|
+
await BM25Utils.getInstance();
|
|
113
|
+
}
|
|
114
|
+
await trainModel(similarityMethod, paths, schema, debug);
|
|
102
115
|
logger.info("Initial training done.");
|
|
103
116
|
|
|
104
117
|
server.watcher.on("all", async (eventName, filePath) => {
|
|
@@ -110,8 +123,12 @@ const relatinatorIntegration = ({
|
|
|
110
123
|
logger.info(
|
|
111
124
|
`Markdown file changed: ${filePath}; Re-training ${similarityMethod}...`
|
|
112
125
|
);
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
if (similarityMethod === "tfidf") {
|
|
127
|
+
await TfIdfUtils.getInstance();
|
|
128
|
+
} else {
|
|
129
|
+
await BM25Utils.getInstance();
|
|
130
|
+
}
|
|
131
|
+
await trainModel(similarityMethod, paths, schema, debug);
|
|
115
132
|
} else {
|
|
116
133
|
return;
|
|
117
134
|
}
|
|
@@ -123,13 +140,17 @@ const relatinatorIntegration = ({
|
|
|
123
140
|
logger.info(
|
|
124
141
|
`Training Relatinator using ${similarityMethod} on existing data...`
|
|
125
142
|
);
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
if (similarityMethod === "tfidf") {
|
|
144
|
+
await TfIdfUtils.getInstance();
|
|
145
|
+
} else {
|
|
146
|
+
await BM25Utils.getInstance();
|
|
147
|
+
}
|
|
148
|
+
await trainModel(similarityMethod, paths, schema, debug);
|
|
128
149
|
logger.info(`Training done.`);
|
|
129
150
|
},
|
|
130
151
|
},
|
|
131
152
|
};
|
|
132
153
|
};
|
|
133
154
|
|
|
134
|
-
export {
|
|
155
|
+
export { TfIdfUtils, BM25Utils };
|
|
135
156
|
export default relatinatorIntegration;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-relatinator",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Find related content in your Astro website or app",
|
|
5
5
|
"author": "Darko Bozhinovski <dbozhinovski@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"@types/node": "^22.13.4",
|
|
32
32
|
"astro": ">=5",
|
|
33
33
|
"husky": "^9.1.7",
|
|
34
|
-
"vite": "^6.1.
|
|
34
|
+
"vite": "^6.1.1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"glob": "^11.0.1",
|
|
38
38
|
"gray-matter": "^4.0.3",
|
|
39
|
-
"relatinator": "2.0.
|
|
39
|
+
"relatinator": "2.0.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"astro": ">=5"
|