Skip to content

Conversation

@nozomuikuta
Copy link
Collaborator

@nozomuikuta nozomuikuta commented Oct 26, 2020

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Resolves: #575.

I added an option content.markdown.tocDepth, by which users can define which heading are included in table of contents. For example, if it is set as 3 (default), h2 and h3 are included in table of contents.

There are 3 special cases to handle:

First case is where content.markdown.tocDepth is set as 1. Currently, h1 seems to be treated as the title of the article rather than content. So, I let the module log an info message.

Second case is where content.markdown.tocDepth is set as 0. I handle this case in same way as above.

Third case is where content.markdown.tocDepth is set as more than 6. Since deepest heading tag is h6, I let the module logs an message.

By the way, the reason why I don't design the option as originally described in the issue is that writing every tag names looks redundant to me.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)

Copy link
Collaborator Author

@nozomuikuta nozomuikuta left a comment

Choose a reason for hiding this comment

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

I added some inline comments.


- Type: `Number`
- Default: `3`
- Version: **>= v1.11.0**
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just an placeholder, and supposed to be set correctly later.

- Default: `3`
- Version: **>= v1.11.0**

Define until which heading levels is included in table of contents.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure this sentence is valid in English...

Copy link
Member

Choose a reason for hiding this comment

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

I would say: Maximum heading depth to include in the table of contents (source: https://github.com/remarkjs/remark-toc#optionsmaxdepth)

fullTextSearchFields: ['title', 'description', 'slug', 'text'],
nestedProperties: [],
markdown: {
tocDepth: 3,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For backward compatibility, I set default value of tocDepth as 3, so that h2 and h3 are included in table of contents.

Copy link
Member

@benjamincanac benjamincanac left a comment

Choose a reason for hiding this comment

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

LGTM 🙂

>
<a
:href="`#${link.id}`"
class="block text-sm scrollactive-item transition-padding ease-in-out duration-300 hover:pl-1"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hover:pl-1 might result in "too dynamic" animation for deeper headings.

@nozomuikuta nozomuikuta marked this pull request as ready for review November 3, 2020 19:42
@nozomuikuta
Copy link
Collaborator Author

@benjamincanac

Thank you for reviewing the draft PR!

I modified parts of code and updated the PR message.
Please review it again when you have time.

@nozomuikuta
Copy link
Collaborator Author

nozomuikuta commented Nov 4, 2020

Hmm, it seems tests that I added take too long...they passed in my local, though.
I will divide them into describe() , so that I can set up longer timeout with beforeAll() as like the other tests.
Or, do you have any other ideas?

@nozomuikuta
Copy link
Collaborator Author

OK, now all the tests are passed by splitting tests for the new feature. 🙌

@benjamincanac
Copy link
Member

Great work @nozomuikuta, thank you very much 🙂 I think it's ready to be merged!

@benjamincanac benjamincanac merged commit 5cf18c4 into nuxt:dev Nov 6, 2020
@nozomuikuta nozomuikuta mentioned this pull request Nov 6, 2020
6 tasks
@nozomuikuta nozomuikuta deleted the feat/support-dynamic-toc branch November 16, 2020 16:33
@atinux atinux mentioned this pull request Nov 19, 2020
3 tasks
@nozomuikuta nozomuikuta mentioned this pull request Feb 9, 2021
6 tasks
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.

Make ToC Levels Configurable

2 participants