@@ -6,6 +6,7 @@ const filemap = require('./source');
6
6
const fs = require ( 'fs' ) ;
7
7
const pug = require ( 'pug' ) ;
8
8
const mongoose = require ( '../' ) ;
9
+ let { version } = require ( '../package.json' ) ;
9
10
10
11
const markdown = require ( 'marked' ) ;
11
12
const highlight = require ( 'highlight.js' ) ;
@@ -15,12 +16,14 @@ markdown.setOptions({
15
16
}
16
17
} ) ;
17
18
18
- mongoose . set ( 'useCreateIndex' , true ) ;
19
+ // 5.13.5 -> 5.x, 6.8.2 -> 6.x, etc.
20
+ version = version . slice ( 0 , version . indexOf ( '.' ) ) + '.x' ;
19
21
20
22
const contentSchema = new mongoose . Schema ( {
21
23
title : { type : String , required : true } ,
22
24
body : { type : String , required : true } ,
23
- url : { type : String , required : true }
25
+ url : { type : String , required : true } ,
26
+ version : { type : String , required : true , default : version }
24
27
} ) ;
25
28
contentSchema . index ( { title : 'text' , body : 'text' } ) ;
26
29
const Content = mongoose . model ( 'Content' , contentSchema , 'Content' ) ;
@@ -30,7 +33,6 @@ const files = Object.keys(filemap);
30
33
31
34
for ( const filename of files ) {
32
35
const file = filemap [ filename ] ;
33
- console . log ( file )
34
36
if ( file . api ) {
35
37
// API docs are special, raw content is in the `docs` property
36
38
for ( const _class of file . docs ) {
@@ -42,14 +44,15 @@ for (const filename of files) {
42
44
} ) ;
43
45
const err = content . validateSync ( ) ;
44
46
if ( err != null ) {
47
+ console . log ( content ) ;
45
48
throw err ;
46
49
}
47
50
contents . push ( content ) ;
48
51
}
49
52
}
50
53
} else if ( file . markdown ) {
51
54
let text = fs . readFileSync ( filename , 'utf8' ) ;
52
- text = markdown ( text ) ;
55
+ text = markdown . parse ( text ) ;
53
56
54
57
const content = new Content ( {
55
58
title : file . title ,
@@ -114,15 +117,18 @@ for (const filename of files) {
114
117
run ( ) . catch ( error => console . error ( error . stack ) ) ;
115
118
116
119
async function run ( ) {
117
- await mongoose . connect ( config . uri , { useNewUrlParser : true , dbName : 'mongoose' } ) ;
120
+ await mongoose . connect ( config . uri , { dbName : 'mongoose' } ) ;
118
121
119
- await Content . deleteMany ( { } ) ;
122
+ await Content . deleteMany ( { version } ) ;
120
123
for ( const content of contents ) {
124
+ if ( version !== '6.x' ) {
125
+ content . url = `/docs/${ version } /docs${ content . url } ` ;
126
+ }
121
127
await content . save ( ) ;
122
128
}
123
129
124
130
const results = await Content .
125
- find ( { $text : { $search : 'validate' } } , { score : { $meta : 'textScore' } } ) .
131
+ find ( { $text : { $search : 'validate' } , version } , { score : { $meta : 'textScore' } } ) .
126
132
sort ( { score : { $meta : 'textScore' } } ) .
127
133
limit ( 10 ) ;
128
134
0 commit comments