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

scriptype / writ-cms / 14434359401

13 Apr 2025 11:25PM UTC coverage: 75.454%. Remained the same
14434359401

push

github

scriptype
[CM2] Introduce deep categorization

This is a combination of 3 commits. Brace yourself.

For now the taxonomy depth is max 3. Because why not.

This required looking up to parent context for content modelling
information, instead of reaching out to the collection. So, throughout
the depth of the taxonomy, content modelling can manipulate the cascade.

To achieve that, the context object is converted into a stack. An
ImmutableStack class is used to pop() it without worrying. It has a
throwUntil() to dig the stack until reaching a point of interest (for
example digging the context to find a collection). That was needed to
avoid passing post and category contexts to tags, as tags don't carry a
hierarchial-relationship in respect to them.

Now, each subCategory can define content-modelling attributes in its
index file. Therefore, each subCategory can have a custom indexFileName
and custom names for its subCategories and posts. For example:

Demos (collection contentType: DemoPortfolio)
  - CSS (category contentType: Technology)
    + CSS-Only (category contentType: Technique)
    + Sliding Doors (category contentType: Technique)
  - Three.js
  - Whatever

The easiest way to deal with rendering subCategories was to merge
the rendering counterpart of models into the models themselves. So,
now, in addition to match() and create(), there's a render(). The render()
is pretty scrappy for now and probably needs more thinking. One of the
main ideas in this implementation is to nest the rendering of the
model's child entities (e.g. for a category, rendering of subCategories,
posts, attachments) into the models' render(). When root render()s,
render flows downstream from there. So, CM2's rendering counterpart is
now only the renderer itself, there's no more views.

Invent something called 'levelPosts' in Category. It contains only the
posts belonging to the category's specific depth. The regular 'posts'
field contains all posts downstream. This was particularly ne... (continued)

483 of 756 branches covered (63.89%)

Branch coverage included in aggregate %.

60 of 161 new or added lines in 13 files covered. (37.27%)

49 existing lines in 7 files now uncovered.

2259 of 2878 relevant lines covered (78.49%)

327.66 hits per line

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

66.67
/src/lib/ImmutableStack.js
1
module.exports = class ImmutableStack {
9✔
2
  constructor(items = [])  {
×
3
    this.items = items
477✔
4
    return this
477✔
5
  }
6

7
  push(item) {
8
    return new ImmutableStack([...this.items, item])
153✔
9
  }
10

11
  pop() {
NEW
12
    const newItems = [...this.items].slice(0, -1)
×
NEW
13
    return new ImmutableStack(newItems)
×
14
  }
15

16
  throwUntil(searchFn) {
17
    const lastItemIndex = this.items.findLastIndex(searchFn)
315✔
18
    const newItems = [...this.items].slice(0, lastItemIndex + 1)
315✔
19
    return new ImmutableStack(newItems)
315✔
20
  }
21

22
  peek() {
23
    return this.items[this.items.length - 1]
1,377✔
24
  }
25

26
  serialize(key) {
NEW
27
    return this.items.reduce((acc, item, depth) => ({
×
28
      ...acc,
29
      [item[key]]: {
30
        ...item,
31
        depth
32
      }
33
    }), {})
34
  }
35
}
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