Skip to content

Commit

Permalink
feat(content-docs): sidebar category linking to document or auto-gene…
Browse files Browse the repository at this point in the history
…rated index page (#5830)

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Armano <[email protected]>
Co-authored-by: Alexey Pyltsyn <[email protected]>
  • Loading branch information
4 people authored Dec 3, 2021
1 parent 95f911e commit cfae5d0
Show file tree
Hide file tree
Showing 105 changed files with 3,900 additions and 812 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ module.exports = {
'head',
'tail',
'initial',
'last',
],
message: 'These APIs have their ES counterparts.',
},
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-mdx-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"escape-html": "^1.0.3",
"file-loader": "^6.2.0",
"fs-extra": "^10.0.0",
"github-slugger": "^1.4.0",
"gray-matter": "^4.0.3",
"mdast-util-to-string": "^2.0.0",
"remark-emoji": "^2.1.0",
Expand All @@ -40,7 +39,6 @@
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.9",
"@types/escape-html": "^1.0.1",
"@types/github-slugger": "^1.3.0",
"@types/mdast": "^3.0.7",
"@types/stringify-object": "^3.3.1",
"@types/unist": "^2.0.6",
Expand Down
9 changes: 3 additions & 6 deletions packages/docusaurus-mdx-loader/src/remark/headings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

/* Based on remark-slug (https://github.com/remarkjs/remark-slug) and gatsby-remark-autolink-headers (https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-autolink-headers) */

import {parseMarkdownHeadingId} from '@docusaurus/utils';
import {parseMarkdownHeadingId, createSlugger} from '@docusaurus/utils';
import visit, {Visitor} from 'unist-util-visit';
import toString from 'mdast-util-to-string';
import Slugger from 'github-slugger';
import type {Transformer} from 'unified';
import type {Parent} from 'unist';
import type {Heading, Text} from 'mdast';

const slugs = new Slugger();

function headings(): Transformer {
const transformer: Transformer = (ast) => {
slugs.reset();
const slugs = createSlugger();

const visitor: Visitor<Heading> = (headingNode) => {
const data = headingNode.data || (headingNode.data = {});
Expand All @@ -29,7 +26,7 @@ function headings(): Transformer {
let {id} = properties;

if (id) {
id = slugs.slug(id, true);
id = slugs.slug(id, {maintainCase: true});
} else {
const headingTextNodes = headingNode.children.filter(
({type}) => !['html', 'jsx'].includes(type),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version-1.0.1/docs": {
"VersionedSideBarNameDoesNotMatter/docs": {
"Test": [
"version-1.0.1/foo/bar"
"foo/bar"
],
"Guides": [
"version-1.0.1/hello"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,122 +2,64 @@

exports[`docsVersion first time versioning 1`] = `
Object {
"version-1.0.0/docs": Array [
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-1.0.0/foo/bar",
"type": "doc",
},
Object {
"id": "version-1.0.0/foo/baz",
"type": "doc",
},
],
"label": "foo",
"type": "category",
},
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-1.0.0/rootAbsoluteSlug",
"type": "doc",
},
Object {
"id": "version-1.0.0/rootRelativeSlug",
"type": "doc",
},
Object {
"id": "version-1.0.0/rootResolvedSlug",
"type": "doc",
},
Object {
"id": "version-1.0.0/rootTryToEscapeSlug",
"type": "doc",
},
],
"label": "Slugs",
"type": "category",
},
Object {
"id": "version-1.0.0/headingAsTitle",
"type": "doc",
},
Object {
"href": "https://github.com",
"label": "Github",
"type": "link",
},
Object {
"id": "version-1.0.0/hello",
"type": "ref",
},
],
"label": "Test",
"type": "category",
},
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-1.0.0/hello",
"type": "doc",
},
],
"label": "Guides",
"type": "category",
},
],
"docs": Object {
"Guides": Array [
"hello",
],
"Test": Array [
Object {
"items": Array [
"foo/bar",
"foo/baz",
],
"label": "foo",
"type": "category",
},
Object {
"items": Array [
"rootAbsoluteSlug",
"rootRelativeSlug",
"rootResolvedSlug",
"rootTryToEscapeSlug",
],
"label": "Slugs",
"type": "category",
},
Object {
"id": "headingAsTitle",
"type": "doc",
},
Object {
"href": "https://github.com",
"label": "Github",
"type": "link",
},
Object {
"id": "hello",
"type": "ref",
},
],
},
}
`;

exports[`docsVersion not the first time versioning 1`] = `
Object {
"version-2.0.0/docs": Array [
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-2.0.0/foo/bar",
"type": "doc",
},
],
"label": "Test",
"type": "category",
},
Object {
"collapsed": true,
"collapsible": true,
"items": Array [
Object {
"id": "version-2.0.0/hello",
"type": "doc",
},
],
"label": "Guides",
"type": "category",
},
],
"docs": Object {
"Guides": Array [
"hello",
],
"Test": Array [
"foo/bar",
],
},
}
`;

exports[`docsVersion second docs instance versioning 1`] = `
Object {
"version-2.0.0/community": Array [
Object {
"id": "version-2.0.0/team",
"type": "doc",
},
"community": Array [
"team",
],
}
`;
Loading

0 comments on commit cfae5d0

Please sign in to comment.