@@ -28,6 +28,7 @@ interface IndexedDoc {
28
28
id : number ;
29
29
mdn_url : string ;
30
30
title : string ;
31
+ title_short : string ;
31
32
token_count : number | null ;
32
33
hash : string ;
33
34
text_hash : string ;
@@ -36,6 +37,7 @@ interface IndexedDoc {
36
37
interface Doc {
37
38
mdn_url : string ;
38
39
title : string ;
40
+ title_short : string ;
39
41
hash : string ;
40
42
html : string ;
41
43
markdown : string ;
@@ -108,9 +110,15 @@ export async function updateEmbeddings(
108
110
const updates : Doc [ ] = [ ] ;
109
111
const formattingUpdates : Doc [ ] = [ ] ;
110
112
111
- for await ( const { mdn_url, title, hash, html, markdown, text } of builtDocs (
112
- directory
113
- ) ) {
113
+ for await ( const {
114
+ mdn_url,
115
+ title,
116
+ title_short,
117
+ hash,
118
+ html,
119
+ markdown,
120
+ text,
121
+ } of builtDocs ( directory ) ) {
114
122
seenUrls . add ( mdn_url ) ;
115
123
116
124
// Check for existing document in DB and compare checksums.
@@ -122,6 +130,7 @@ export async function updateEmbeddings(
122
130
updates . push ( {
123
131
mdn_url,
124
132
title,
133
+ title_short,
125
134
hash,
126
135
html,
127
136
markdown,
@@ -132,6 +141,7 @@ export async function updateEmbeddings(
132
141
formattingUpdates . push ( {
133
142
mdn_url,
134
143
title,
144
+ title_short,
135
145
hash,
136
146
html,
137
147
markdown,
@@ -154,6 +164,7 @@ export async function updateEmbeddings(
154
164
for ( const {
155
165
mdn_url,
156
166
title,
167
+ title_short,
157
168
hash,
158
169
html,
159
170
markdown,
@@ -173,27 +184,30 @@ export async function updateEmbeddings(
173
184
INSERT INTO mdn_doc_macro(
174
185
mdn_url,
175
186
title,
187
+ title_short,
176
188
hash,
177
189
html,
178
190
markdown,
179
191
token_count,
180
192
embedding,
181
193
text_hash
182
194
)
183
- VALUES($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (mdn_url) DO
195
+ VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9 ) ON CONFLICT (mdn_url) DO
184
196
UPDATE
185
197
SET mdn_url = $1,
186
198
title = $2,
187
- hash = $3,
188
- html = $4,
189
- markdown = $5,
190
- token_count = $6,
191
- embedding = $7,
192
- text_hash = $8
199
+ title_short = $3,
200
+ hash = $4,
201
+ html = $5,
202
+ markdown = $6,
203
+ token_count = $7,
204
+ embedding = $8,
205
+ text_hash = $9
193
206
` ,
194
207
values : [
195
208
mdn_url ,
196
209
title ,
210
+ title_short ,
197
211
hash ,
198
212
html ,
199
213
markdown ,
@@ -211,7 +225,14 @@ export async function updateEmbeddings(
211
225
console . error ( context ) ;
212
226
}
213
227
}
214
- for ( const { mdn_url, title, hash, html, markdown } of formattingUpdates ) {
228
+ for ( const {
229
+ mdn_url,
230
+ title,
231
+ title_short,
232
+ hash,
233
+ html,
234
+ markdown,
235
+ } of formattingUpdates ) {
215
236
try {
216
237
console . log (
217
238
`-> [${ mdn_url } ] Updating document without generating new embedding...`
@@ -221,16 +242,17 @@ export async function updateEmbeddings(
221
242
const query = {
222
243
name : "upsert-doc" ,
223
244
text : `
224
- INSERT INTO mdn_doc_macro(mdn_url, title, hash, html, markdown)
225
- VALUES($1, $2, $3, $4, $5) ON CONFLICT (mdn_url) DO
245
+ INSERT INTO mdn_doc_macro(mdn_url, title, title_short, hash, html, markdown)
246
+ VALUES($1, $2, $3, $4, $5, $6 ) ON CONFLICT (mdn_url) DO
226
247
UPDATE
227
248
SET mdn_url = $1,
228
249
title = $2,
229
- hash = $3,
230
- html = $4,
231
- markdown = $5
250
+ title_short = $3,
251
+ hash = $4,
252
+ html = $5,
253
+ markdown = $6
232
254
` ,
233
- values : [ mdn_url , title , hash , html , markdown ] ,
255
+ values : [ mdn_url , title , title_short , hash , html , markdown ] ,
234
256
rowMode : "array" ,
235
257
} ;
236
258
@@ -286,7 +308,9 @@ async function* builtDocs(directory: string) {
286
308
for await ( const metadataPath of builtPaths ( directory ) ) {
287
309
try {
288
310
const raw = await readFile ( metadataPath , "utf-8" ) ;
289
- const { title, mdn_url, hash } = JSON . parse ( raw ) as DocMetadata ;
311
+ const { title, short_title, mdn_url, hash } = JSON . parse (
312
+ raw
313
+ ) as DocMetadata ;
290
314
291
315
const plainPath = path . join ( path . dirname ( metadataPath ) , "plain.html" ) ;
292
316
const plainHTML = await readFile ( plainPath , "utf-8" ) ;
@@ -314,6 +338,7 @@ async function* builtDocs(directory: string) {
314
338
yield {
315
339
mdn_url,
316
340
title,
341
+ title_short : short_title || title ,
317
342
hash,
318
343
html,
319
344
markdown,
0 commit comments