@@ -37,85 +37,89 @@ const contentSchema = new mongoose.Schema({
37
37
contentSchema . index ( { title : 'text' , body : 'text' } ) ;
38
38
const Content = mongoose . model ( 'Content' , contentSchema , 'Content' ) ;
39
39
40
- const contents = [ ] ;
40
+ function generateContents ( ) {
41
+ const contents = [ ] ;
42
+
43
+ for ( const [ filename , file ] of Object . entries ( docsFilemap . fileMap ) ) {
44
+ if ( file . api ) {
45
+ for ( const prop of file . props ) {
46
+ const content = new Content ( {
47
+ title : `API: ${ prop . name } ` ,
48
+ body : prop . description ,
49
+ url : `${ filename } #${ prop . anchorId } `
50
+ } ) ;
51
+ const err = content . validateSync ( ) ;
52
+ if ( err != null ) {
53
+ console . error ( content ) ;
54
+ throw err ;
55
+ }
56
+ contents . push ( content ) ;
57
+ }
58
+ } else if ( file . markdown ) {
59
+ let text = fs . readFileSync ( filename , 'utf8' ) ;
60
+ text = markdown . parse ( text ) ;
41
61
42
- for ( const [ filename , file ] of Object . entries ( docsFilemap . fileMap ) ) {
43
- if ( file . api ) {
44
- for ( const prop of file . props ) {
45
62
const content = new Content ( {
46
- title : `API: ${ prop . name } ` ,
47
- body : prop . description ,
48
- url : ` ${ filename } # ${ prop . anchorId } `
63
+ title : file . title ,
64
+ body : text ,
65
+ url : filename . replace ( '.md' , '.html' ) . replace ( / ^ d o c s / , '' )
49
66
} ) ;
50
- const err = content . validateSync ( ) ;
51
- if ( err != null ) {
52
- console . error ( content ) ;
53
- throw err ;
54
- }
55
- contents . push ( content ) ;
56
- }
57
- } else if ( file . markdown ) {
58
- let text = fs . readFileSync ( filename , 'utf8' ) ;
59
- text = markdown . parse ( text ) ;
60
67
61
- const content = new Content ( {
62
- title : file . title ,
63
- body : text ,
64
- url : filename . replace ( '.md' , '.html' ) . replace ( / ^ d o c s / , '' )
65
- } ) ;
68
+ content . validateSync ( ) ;
66
69
67
- content . validateSync ( ) ;
70
+ const $ = cheerio . load ( text ) ;
68
71
69
- const $ = cheerio . load ( text ) ;
72
+ contents . push ( content ) ;
70
73
71
- contents . push ( content ) ;
74
+ // Break up individual h3's into separate content for more fine grained search
75
+ $ ( 'h3' ) . each ( ( index , el ) => {
76
+ el = $ ( el ) ;
77
+ const title = el . text ( ) ;
78
+ const html = el . nextUntil ( 'h3' ) . html ( ) ;
79
+ const content = new Content ( {
80
+ title : `${ file . title } : ${ title } ` ,
81
+ body : html ,
82
+ url : `${ filename . replace ( '.md' , '.html' ) . replace ( / ^ d o c s / , '' ) } #${ el . prop ( 'id' ) } `
83
+ } ) ;
84
+
85
+ content . validateSync ( ) ;
86
+ contents . push ( content ) ;
87
+ } ) ;
88
+ } else if ( file . guide ) {
89
+ let text = fs . readFileSync ( filename , 'utf8' ) ;
90
+ text = text . substring ( text . indexOf ( 'block content' ) + 'block content\n' . length ) ;
91
+ text = pug . render ( `div\n${ text } ` , { filters : { markdown } , filename } ) ;
72
92
73
- // Break up individual h3's into separate content for more fine grained search
74
- $ ( 'h3' ) . each ( ( index , el ) => {
75
- el = $ ( el ) ;
76
- const title = el . text ( ) ;
77
- const html = el . nextUntil ( 'h3' ) . html ( ) ;
78
93
const content = new Content ( {
79
- title : ` ${ file . title } : ${ title } ` ,
80
- body : html ,
81
- url : ` ${ filename . replace ( '.md ' , '.html' ) . replace ( / ^ d o c s / , '' ) } # ${ el . prop ( 'id' ) } `
94
+ title : file . title ,
95
+ body : text ,
96
+ url : filename . replace ( '.pug ' , '.html' ) . replace ( / ^ d o c s / , '' )
82
97
} ) ;
83
98
84
99
content . validateSync ( ) ;
85
- contents . push ( content ) ;
86
- } ) ;
87
- } else if ( file . guide ) {
88
- let text = fs . readFileSync ( filename , 'utf8' ) ;
89
- text = text . substring ( text . indexOf ( 'block content' ) + 'block content\n' . length ) ;
90
- text = pug . render ( `div\n${ text } ` , { filters : { markdown } , filename } ) ;
91
-
92
- const content = new Content ( {
93
- title : file . title ,
94
- body : text ,
95
- url : filename . replace ( '.pug' , '.html' ) . replace ( / ^ d o c s / , '' )
96
- } ) ;
97
-
98
- content . validateSync ( ) ;
99
100
100
- const $ = cheerio . load ( text ) ;
101
+ const $ = cheerio . load ( text ) ;
101
102
102
- contents . push ( content ) ;
103
+ contents . push ( content ) ;
103
104
104
- // Break up individual h3's into separate content for more fine grained search
105
- $ ( 'h3' ) . each ( ( index , el ) => {
106
- el = $ ( el ) ;
107
- const title = el . text ( ) ;
108
- const html = el . nextUntil ( 'h3' ) . html ( ) ;
109
- const content = new Content ( {
110
- title : `${ file . title } : ${ title } ` ,
111
- body : html ,
112
- url : `${ filename . replace ( '.pug' , '.html' ) . replace ( / ^ d o c s / , '' ) } #${ el . prop ( 'id' ) } `
105
+ // Break up individual h3's into separate content for more fine grained search
106
+ $ ( 'h3' ) . each ( ( index , el ) => {
107
+ el = $ ( el ) ;
108
+ const title = el . text ( ) ;
109
+ const html = el . nextUntil ( 'h3' ) . html ( ) ;
110
+ const content = new Content ( {
111
+ title : `${ file . title } : ${ title } ` ,
112
+ body : html ,
113
+ url : `${ filename . replace ( '.pug' , '.html' ) . replace ( / ^ d o c s / , '' ) } #${ el . prop ( 'id' ) } `
114
+ } ) ;
115
+
116
+ content . validateSync ( ) ;
117
+ contents . push ( content ) ;
113
118
} ) ;
114
-
115
- content . validateSync ( ) ;
116
- contents . push ( content ) ;
117
- } ) ;
119
+ }
118
120
}
121
+
122
+ return contents ;
119
123
}
120
124
121
125
run ( ) . catch ( async error => {
@@ -132,6 +136,9 @@ async function run() {
132
136
await Content . init ( ) ;
133
137
134
138
await Content . deleteMany ( { version } ) ;
139
+
140
+ const contents = generateContents ( ) ;
141
+
135
142
let count = 0 ;
136
143
for ( const content of contents ) {
137
144
if ( version === '8.x' ) {
0 commit comments