Open KentarouTakeda opened 1 month ago
git clone -b max-items-of-toc https://github.com/KentarouTakeda/hexojs-hexo.git
cd hexo
npm install
npm test
This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
lib/box/index.ts | 4 | 96.07% | ||
lib/plugins/processor/post.ts | 7 | 97.78% | ||
<!-- | Total: | 11 | --> |
Totals | |
---|---|
Change from base Build 8875175928: | 0.002% |
Covered Lines: | 9368 |
Relevant Lines: | 9417 |
It seems that the test is failing at some points unrelated to this pull request. Other pull requests have also failed, so I'll leave it as is.
What does it do?
Added the ability to set an upper limit on the number of items in the table of contents output by the
toc()
helper.If no value is specified, the default is
Infinity
. This is no different from previous behavior. If we specify a number greater than or equal to 1, the elements will be truncated in the following order.<h6>
to<h1>
) to fit within the specified number.For example, if we have a heading like this:
If
5
is specified formax_items
, all items will be output. On the other hand, if we specify4
or3
,All
<h3>
are removed, resulting in two items being output. This is the same result as specifying2
formax_items
. This is because this outline requires five elements to display up to<h3>
.Only the highest heading that appears on the page behaves differently. For example, if we specify
1
formax_items
,Instead of all
<h2>
being deleted at once as before, they will be deleted sequentially from the bottom. This is to avoid unintentionally not outputting anything.In addition to the code, I welcome any feedback regarding the specifications described here. I believe this specification is the best, but if you have any other good ideas, I would definitely consider them.
Screenshots
Pull request tasks