• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

scriptype / writ-cms / 14131789549

28 Mar 2025 02:58PM UTC coverage: 77.366% (-0.07%) from 77.435%
14131789549

push

github

scriptype
[CM2] Parse markdown content of models

Copy-paste the parse function from _baseEntry to category and collection. Maybe a base model class with this parse functionality?

431 of 657 branches covered (65.6%)

Branch coverage included in aggregate %.

23 of 28 new or added lines in 4 files covered. (82.14%)

2201 of 2745 relevant lines covered (80.18%)

339.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.08
/src/compiler/contentModel2/models/_baseEntry.js
1
const _ = require('lodash')
9✔
2
const frontMatter = require('front-matter')
9✔
3
const slug = require('slug')
9✔
4
const { templateExtensions, removeExtension, Markdown } = require('../helpers')
9✔
5

6
const models = {
9✔
7
  attachment: require('./attachment')
8
}
9

10
const isIndexFile = (node, nameOptions) => {
9✔
11
  if (node.children) {
54!
NEW
12
    return false
×
13
  }
14
  const names = nameOptions.join('|')
54✔
15
  const extensions = templateExtensions.join('|')
54✔
16
  const namePattern = new RegExp(`^(${names})(${extensions})$`, 'i')
54✔
17
  return node.name.match(namePattern)
54✔
18
}
19

20
function parseFolderedEntry(node, indexFileNameOptions) {
21
  const tree = {
18✔
22
    indexFile: null,
23
    attachments: []
24
  }
25
  node.children.forEach(childNode => {
18✔
26
    if (isIndexFile(childNode, indexFileNameOptions)) {
54✔
27
      tree.indexFile = childNode
18✔
28
      return
18✔
29
    }
30
    tree.attachments.push(models.attachment.bind(null, childNode))
36✔
31
  })
32

33
  return {
18✔
34
    ...tree,
35
    name: node.name
36
  }
37
}
38

39
function parseContent(node, content) {
40
  if (node.extension.match(/(html|htm|hbs|handlebars)/i)) {
72✔
41
    return content
36✔
42
  }
43
  return Markdown.parse(content)
36✔
44
}
45

46
function _baseEntry(node, indexFileNameOptions) {
47
  const folderedEntry = node.children ?
72✔
48
    parseFolderedEntry(node, indexFileNameOptions) :
49
    undefined
50
  const entryFile = folderedEntry?.indexFile || node
72✔
51
  const { attributes, body } = frontMatter(entryFile.content)
72✔
52
  const entryName = removeExtension(
72✔
53
    folderedEntry?.name || entryFile.name
126✔
54
  )
55
  const attachments = folderedEntry?.attachments || []
72✔
56
  const contentRaw = body || ''
72✔
57
  const content = parseContent(entryFile, contentRaw)
72✔
58

59
  return {
72✔
60
    ..._.omit(node, 'children'),
61
    ...attributes,
62
    title: attributes.title || entryName,
135✔
63
    slug: attributes.slug || slug(entryName),
144✔
64
    contentRaw,
65
    content,
66
    attachments
67
  }
68
}
69

70
module.exports = _baseEntry
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc