| 
									
										
										
										
											2017-04-16 22:13:09 +01:00
										 |  |  | module.exports = function convertToJsonProcessor(log, createDocMessage) { | 
					
						
							| 
									
										
										
										
											2017-02-21 16:57:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     $runAfter: ['checkUnbalancedBackTicks'], | 
					
						
							|  |  |  |     $runBefore: ['writeFilesProcessor'], | 
					
						
							|  |  |  |     docTypes: [], | 
					
						
							|  |  |  |     $process: function(docs) { | 
					
						
							| 
									
										
										
										
											2017-04-01 21:34:10 +03:00
										 |  |  |       const docTypes = this.docTypes; | 
					
						
							| 
									
										
										
										
											2017-02-21 16:57:19 +00:00
										 |  |  |       docs.forEach((doc) => { | 
					
						
							|  |  |  |         if (docTypes.indexOf(doc.docType) !== -1) { | 
					
						
							| 
									
										
										
										
											2017-04-16 22:13:09 +01:00
										 |  |  |           let contents = doc.renderedContent || ''; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-19 09:56:39 +01:00
										 |  |  |           let title = doc.title; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-30 22:24:44 +03:00
										 |  |  |           // We do allow an empty `title` but if it is `undefined` we resort to `vFile.title` and then `name`
 | 
					
						
							| 
									
										
										
										
											2017-04-19 09:56:39 +01:00
										 |  |  |           if (title === undefined) { | 
					
						
							| 
									
										
										
										
											2017-05-30 22:24:44 +03:00
										 |  |  |             title = (doc.vFile && doc.vFile.title); | 
					
						
							| 
									
										
										
										
											2017-04-19 09:56:39 +01:00
										 |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-16 22:13:09 +01:00
										 |  |  |           if (title === undefined) { | 
					
						
							| 
									
										
										
										
											2017-05-30 22:24:44 +03:00
										 |  |  |             title = doc.name; | 
					
						
							| 
									
										
										
										
											2017-04-16 22:13:09 +01:00
										 |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // If there is still no title then log a warning
 | 
					
						
							|  |  |  |           if (title === undefined) { | 
					
						
							|  |  |  |             title = ''; | 
					
						
							|  |  |  |             log.warn(createDocMessage('Title property expected', doc)); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-20 12:55:34 +01:00
										 |  |  |           doc.renderedContent = JSON.stringify({ id: doc.path, title, contents }, null, 2); | 
					
						
							| 
									
										
										
										
											2017-02-21 16:57:19 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2017-04-16 22:13:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-01 21:34:10 +03:00
										 |  |  | }; |