feat(v2): support external links & linking to docs from other sidebars#1052
Conversation
|
Deploy preview for docusaurus-preview ready! Built with commit 4f0b188 |
There was a problem hiding this comment.
Looks great. Kinda happy also by the fact that you are able to implement it in v2 easily @SleepWalker
We need to document this in the future since there is a lot of things now, including 'ref' means including it in sidebar but not including it at next/prev.
The change to ids to items seems to make sense since we allow href linking other than id
|
@yangshun I have more questions:
|
|
@SleepWalker I'll get back to you on this soon. We're currently getting ready for a demo and will be holding off on merging v2 PRs these few days. |
|
Let's leave v1 implementation in another PR. Small changes is easier to review. @SleepWalker can you resolve the conflicts ? |
0966b72 to
9ed899c
Compare
|
@endiliey yep, they are resolved |
|
Shall let @yangshun press the merge button |
This PR implements #827, #868 (v1 PR pending)
Motivation
This PR will improve sidebar to support:
idstoitems)Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
I have added some examples in
sidebar.json. It looks like this:{ "docs": { "Category 1": [ { "type": "link", "label": "Github", "href": "http://github.com" }, { "type": "category", "label": "Subcategory 1", "items": [ "foo/bar", "foo/baz" ] }, { "type": "category", "label": "Subcategory 2", "items": [ { "type": "ref", "id": "intro" }, "hello", { "type": "link", "label": "Google", "href": "http://google.com" } ] } ], "Category 2": ["code"] }, "test": { "Test Ref links": [ { "type": "doc", "id": "intro" }, { "type": "ref", "id": "code" } ] } }The
typefield can be one of the following:doc— low level name for simple link to doc. Should containidfieldref— link to some docId, but without binding this doc to current sidebar. Should containidfieldlink— the type used to render any link in sidebar (doc and ref are converted to this type too). Should containhrefandlabelfieldscategory— category :) should containlabelanditemsfields (I think this should be a better name, because we will handle not only ids in this array)I'm normalizing sidebars to this low-level format immediately after reading them (including versioned sidebars) in
v2/lib/load/docs/sidebars.js. During normalization I'm checking, that all the items contain only allowed fields and that we won't have sub-sub-categories.Normalized structure is much more predictable and reliable, which allow us to simplify logic (it won't be needed to test for each type of possible sidebar syntaxes in each function) during docs ordering and during sidebar rendering on client side. In future we can even more simplify this by implementing visitor pattern, like in e.g. babel.
Docs Paginator behavior
I've decided to ignore
refandlinkitems, when building data for docs paginator. If you send user torefdoc, the sidebar will be changed. If you send user tolinkit may even leave our site. I think that's not expected behavior for the user.Unit tests
I've added one new test to test for
refandlinkprocessing in order.js. All other cases seems to be covered with older tests after I've fixed them