Skip to content

fix: complete a parent's count when it covers only its own posts - #199

Merged
isaacslee merged 2 commits into
mainfrom
fix/category-parent-count
Nov 23, 2026
Merged

isaacslee merged 2 commits into
mainfrom
fix/category-parent-count

Conversation

@isaacslee

Copy link
Copy Markdown
Member

Summary

A parent category whose count covers only its own posts is completed with the posts under its sub-categories, so the number matches the page it opens. Parents Tistory already totals are left as written.

Why

Closes #198

Engineering read 9 in the sidebar and /category/Engineering lists 368. Tistory had written the category's direct count (9), the page lists the category and everything beneath it, and with the rail folded, which is how it starts, that 9 was the only number on screen.

My first hypothesis was wrong, and it is the reason this is not a one-line sum. I read it as "Tistory counts a parent's own posts only" and added the two together for every parent. That is wrong for the blog it was meant for: Projects reads 10 over 0+5+5 and has no posts of its own, so the sum made it 20. Four of the five parents on this blog read exactly the sum of their children. Surveying other blogs, Tistory usually does roll a parent up:

parent vs the sum of its children count (64 parents, 12 blogs)
equal 40
above 21
below 3

Below is impossible for a total, so those three are direct counts: this blog's Engineering (9 vs 359) and two others. The rule that fits all 64 is the one implemented: complete a parent only when it is below the sum of its children.

How it was verified

  • node scripts/check.mjs — 27 checks, passed.

  • Against the sidebar markup fetched from the live blog (isaac-christian.tistory.com/category/Engineering, the five parents and their rows) in jsdom, once from source and once from the built dist/images/app.js:

    row before after
    All posts 512 512
    Engineering 9 368
    Projects 10 10
    Career 7 7
    Life 19 19
    Archive 108 108

    Constructed cases on top of that: a three-level branch (1 over 2 over 4 became 7 over 6 over 4), and a branch with one row that has no count, which was left as written all the way up.

  • 368 is checked against the site, not only against the arithmetic. /category/Engineering paged through to its 46th page lists 368 posts: 9 filed in Engineering itself, and 93, 120, 118, 8 and 20 under it. /category/Projects lists 10 and /category/Life 19, both with none of their own.

  • The rule checked on a second blog, one not used to derive it: moonsiri.tistory.com, infra, reads 1 over sub-categories holding 11, and its listing holds 12.

Not run: a real browser, because none is installed on this machine. jsdom needed matchMedia and requestAnimationFrame supplied, which are the harness's gaps and not the skin's. Nothing was uploaded to a Tistory blog.

Limitations

  • A direct count that reaches the sum of its children cannot be told from a total and is left alone. A parent with 400 posts of its own over children holding 359 would still read 400. Nothing in the markup distinguishes the two.
  • The figure is rewritten by the bundle after the first paint, so on a load the old number is on screen for a frame. The number's width changes and nothing else moves, and hiding it would trade a changed digit for a gap, which states.css already argues is the worse of the two.
  • The live blog's counter looks out of step with its own tree (Tistory writes 9 where the rest of its parents write a total). That is Tistory's, and if it is ever recomputed the figure becomes 368 on its own and this code stops doing anything for it.
  • No setting, index.xml field or template changed; the release that carries this is a separate PR.

- a parent category read 9 over sub-categories holding 359 and opened a
  page of 368: Tistory had written its direct count, and with the rail
  folded that was the only number on screen
- add `rollUpCount` to category.ts, which compares each parent with the
  sum of the rows beneath it, bottom-up
- complete a parent only when it is below that sum, since a total cannot
  be smaller than its parts; at or above it, leave it as Tistory wrote it
- adding the two for every parent was the first attempt and is wrong:
  Projects, 10 over 0+5+5, came out as 20
- leave the "all posts" row alone and skip any branch with an unreadable
  count rather than print a sum with a hole in it
- a direct count that reaches its children's sum is still indistinguishable
  from a total and is not corrected
- no setting, template or stylesheet changes
Copilot AI balanced review requested due to automatic review settings November 23, 2026 00:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@isaacslee
isaacslee merged commit 7cc1131 into main Nov 23, 2026
1 check passed
@isaacslee
isaacslee deleted the fix/category-parent-count branch November 23, 2026 00:11
@isaacslee isaacslee mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A parent category's count leaves out its sub-categories

2 participants