fix: handle page metadata parse failure
This commit is contained in:
		@@ -192,35 +192,39 @@ module.exports = class Page extends Model {
 | 
				
			|||||||
   */
 | 
					   */
 | 
				
			||||||
  static parseMetadata (raw, contentType) {
 | 
					  static parseMetadata (raw, contentType) {
 | 
				
			||||||
    let result
 | 
					    let result
 | 
				
			||||||
    switch (contentType) {
 | 
					    try {
 | 
				
			||||||
      case 'markdown':
 | 
					      switch (contentType) {
 | 
				
			||||||
        result = frontmatterRegex.markdown.exec(raw)
 | 
					        case 'markdown':
 | 
				
			||||||
        if (result[2]) {
 | 
					          result = frontmatterRegex.markdown.exec(raw)
 | 
				
			||||||
          return {
 | 
					 | 
				
			||||||
            ...yaml.safeLoad(result[2]),
 | 
					 | 
				
			||||||
            content: result[3]
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
          // Attempt legacy v1 format
 | 
					 | 
				
			||||||
          result = frontmatterRegex.legacy.exec(raw)
 | 
					 | 
				
			||||||
          if (result[2]) {
 | 
					          if (result[2]) {
 | 
				
			||||||
            return {
 | 
					            return {
 | 
				
			||||||
              title: result[2],
 | 
					              ...yaml.safeLoad(result[2]),
 | 
				
			||||||
              description: result[4],
 | 
					              content: result[3]
 | 
				
			||||||
              content: result[5]
 | 
					            }
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            // Attempt legacy v1 format
 | 
				
			||||||
 | 
					            result = frontmatterRegex.legacy.exec(raw)
 | 
				
			||||||
 | 
					            if (result[2]) {
 | 
				
			||||||
 | 
					              return {
 | 
				
			||||||
 | 
					                title: result[2],
 | 
				
			||||||
 | 
					                description: result[4],
 | 
				
			||||||
 | 
					                content: result[5]
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					          break
 | 
				
			||||||
        break
 | 
					        case 'html':
 | 
				
			||||||
      case 'html':
 | 
					          result = frontmatterRegex.html.exec(raw)
 | 
				
			||||||
        result = frontmatterRegex.html.exec(raw)
 | 
					          if (result[2]) {
 | 
				
			||||||
        if (result[2]) {
 | 
					            return {
 | 
				
			||||||
          return {
 | 
					              ...yaml.safeLoad(result[2]),
 | 
				
			||||||
            ...yaml.safeLoad(result[2]),
 | 
					              content: result[3]
 | 
				
			||||||
            content: result[3]
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					          break
 | 
				
			||||||
        break
 | 
					      }
 | 
				
			||||||
 | 
					    } catch (err) {
 | 
				
			||||||
 | 
					      WIKI.logger.warn('Failed to parse page metadata. Invalid syntax.')
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      content: raw
 | 
					      content: raw
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user