Skip to content

Commit

Permalink
feat: 🎸 major rework of table of contents generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Reese committed Nov 13, 2020
1 parent 1e9c5d4 commit 49d898b
Show file tree
Hide file tree
Showing 17 changed files with 8,918 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
root: true,
env: {
node: true,
commonjs: false,
commonjs: true,
es2020: true,
browser: true,
'jest/globals': true,
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/'],
};
2 changes: 1 addition & 1 deletion packages/markdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ plugins: {
// theme is the only option available - for now.
},
useElderJsPluginImages: true, // if you are using the @elderjs/plugin-images the plugin replace all markdown images with the {{picture src="" alt="" /}} shortcode.
useTableOfContents: false, // adds tocTree and tocHtml to each route's data object.
useTableOfContents: false, // adds tocTree to each route's data object.
},

}
Expand Down
4,848 changes: 4,848 additions & 0 deletions packages/markdown/package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
},
"dependencies": {
"glob": "^7.1.6",
"hast-util-to-string": "^1.0.4",
"jest": "^26.6.3",
"rehype": "^11.0.0",
"rehype-slug": "^4.0.1",
"remark": "^13.0.0",
"remark-extract-frontmatter": "^3.0.0",
"remark-frontmatter": "^3.0.0",
Expand Down
79 changes: 79 additions & 0 deletions packages/markdown/test/createTree.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const createTree = require('../utils/createTree');

describe('createTree', () => {
it('Make a tree from an easy array of h2s', () => {
const h2s = require('./fixtures/h2s.json');
expect(createTree(h2s)).toEqual([
{
children: [],
depth: 2,
i: 0,
id: 'determining-the-right-type-of-senior-living-facility',
text: 'Determining The Right Type of Senior Living Facility',
},
{ children: [], depth: 2, i: 1, id: 'independent-living', text: 'Independent Living' },
{ children: [], depth: 2, i: 2, id: 'assisted-living', text: 'Assisted Living' },
{
children: [],
depth: 2,
i: 3,
id: 'home-healthcare-services-assisted-living-alternative',
text: 'Home Healthcare Services: Assisted Living Alternative',
},
{ children: [], depth: 2, i: 4, id: 'nursing-homes', text: 'Nursing Homes' },
{ children: [], depth: 2, i: 5, id: 'memory-care-units', text: 'Memory Care Units' },
{
children: [],
depth: 2,
i: 6,
id: 'continuing-care-retirement-communities',
text: 'Continuing Care Retirement Communities',
},
{ children: [], depth: 2, i: 7, id: 'hospice-care', text: 'Hospice Care' },
{ children: [], depth: 2, i: 8, id: 'putting-it-all-together', text: 'Putting It All Together' },
]);
});

it('Mixed Page with out of order headers', () => {
const mixed = require('./fixtures/mixedhs.json');
expect(createTree(mixed)).toEqual([
{
depth: 2,
i: 0,
id: 'services-offered-by-assisted-living',
text: 'Services Offered By ',
children: [
{ children: [], depth: 4, i: 1, id: 'test-orphan', text: 'test orphan' },
{
children: [{ children: [], depth: 4, i: 3, id: 'testing-more', parent: true, text: 'Testing more' }],
depth: 3,
i: 2,
id: 'testing',
parent: true,
text: 'Testing',
},
],
},
{
children: [],
depth: 2,
i: 4,
id: 'costs-and-paying-for-assisted-living',
text: 'Costs and Paying for Assisted Living',
},
{
children: [],
depth: 2,
i: 5,
id: 'pros-and-cons-of-assisted-living',
text: 'Pros and Cons of Assisted Living',
},
]);
});

it('It parses Elder.js', () => {
const json = require('./fixtures/elderjs-headers.json');
const parsed = require('./fixtures/elderjs-parsed.json');
expect(createTree(json)).toEqual(parsed);
});
});
Loading

0 comments on commit 49d898b

Please sign in to comment.