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

scriptype / writ-cms / 18128625706

30 Sep 2025 11:38AM UTC coverage: 73.078% (-2.4%) from 75.488%
18128625706

push

github

scriptype
Facets wip5

Handle permalinking from entries to collection facets through its faceted fields. Every facet field becomes an object: { value, facetPermalink }. If the field is a link to another entry (already object), then the facetPermalink property is added on top of existing entry object.

490 of 795 branches covered (61.64%)

Branch coverage included in aggregate %.

8 of 25 new or added lines in 4 files covered. (32.0%)

118 existing lines in 9 files now uncovered.

2276 of 2990 relevant lines covered (76.12%)

313.31 hits per line

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

53.66
/src/compiler/contentModel2/models/subpage.js
1
const { join, resolve } = require('path')
9✔
2
const { isTemplateFile, makePermalink } = require('../helpers')
9✔
3
const models = {
9✔
4
  _baseEntry: require('./_baseEntry'),
5
  attachment: require('./attachment'),
6
}
7

8
const defaultSettings = {
9✔
9
  pagesDirectory: 'pages'
10
}
11
module.exports = function Subpage(settings = defaultSettings) {
9!
12
  const indexFileNameOptions = ['page', 'index']
9✔
13
  const pagesDirectoryNameOptions = [settings.pagesDirectory, 'subpages', 'pages']
9✔
14

15
  const isSubpageIndexFile = (node) => {
9✔
16
    return (
36✔
17
      isTemplateFile(node) &&
45✔
18
      node.name.match(
19
        new RegExp(`^(${indexFileNameOptions.join('|')})\\..+$`)
20
      )
21
    )
22
  }
23

24
  const isFolderedSubpage = (node) => {
9✔
25
    return node.children?.find(isSubpageIndexFile)
9✔
26
  }
27

28
  const isPagesDirectory = (node) => {
9✔
29
    return (
9✔
30
      node.children &&
18✔
31
      node.name.match(
32
        new RegExp(`^(${pagesDirectoryNameOptions.join('|')})$`)
33
      )
34
    )
35
  }
36

37
  return {
9✔
38
    match: node => isTemplateFile(node) || isFolderedSubpage(node),
9✔
39
    matchPagesDirectory: node => isPagesDirectory(node),
9✔
40

41
    create: (node, context) => {
42
      const baseEntryProps = models._baseEntry(node, indexFileNameOptions)
×
43

44
      const permalink = makePermalink(
×
45
        context.peek().permalink,
46
        baseEntryProps.slug
47
      ) + (baseEntryProps.hasIndex ? '' : '.html')
×
48

49
      const outputPath = join(
×
50
        context.peek().outputPath,
51
        baseEntryProps.slug
52
      )
53

54
      const pageContext = {
×
55
        title: baseEntryProps.title,
56
        slug: baseEntryProps.slug,
57
        permalink,
58
        outputPath
59
      }
60

61
      return {
×
62
        ...baseEntryProps,
63
        ...pageContext,
64
        context,
65
        attachments: baseEntryProps.attachments.map(
66
          attachment => attachment(context.push({
×
67
            ...pageContext,
68
            key: 'page'
69
          }))
70
        )
71
      }
72
    },
73

74
    afterEffects: (contentModel, subpage) => {
75
      subpage.attachments.forEach(attachment => {
×
76
        models.attachment().afterEffects(contentModel, attachment)
×
77
      })
78
    },
79

80
    render: (renderer, subpage, { contentModel, settings, debug }) => {
UNCOV
81
      const renderSubpage = () => {
×
UNCOV
82
        return renderer.render({
×
83
          templates: [
84
            `pages/${subpage.template}`,
85
            `pages/subpage/${subpage.contentType}`,
86
            `pages/subpage/default`
87
          ],
88
          outputPath: join(...[
89
            subpage.outputPath,
90
            subpage.hasIndex ? 'index' : ''
×
91
          ]) + '.html',
92
          content: subpage.content,
93
          data: {
94
            ...contentModel,
95
            subpage,
96
            settings,
97
            debug
98
          }
99
        })
100
      }
101

UNCOV
102
      const renderAttachments = () => {
×
UNCOV
103
        return Promise.all(
×
104
          subpage.attachments.map(attachment => {
UNCOV
105
            return models.attachment().render(renderer, attachment)
×
106
          })
107
        )
108
      }
109

UNCOV
110
      return Promise.all([
×
111
        renderSubpage(),
112
        renderAttachments()
113
      ])
114
    }
115
  }
116
}
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