Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
[sections] missing types of nested elements #136
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe committed Dec 13, 2018
1 parent 6f6b086 commit 3912d09
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/html/get-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,23 @@ function image(section) {
*/
function sectiontype(section) {
const children = section.children || [];
const typecounter = children.reduce((counter, { type }) => {

function reducer(counter, { type, children: pChildren }) {
if (type === 'yaml') {
return counter;
}
const mycounter = {};

let mycounter = {};
if (pChildren && pChildren.length > 0) {
mycounter = Object.assign(counter, pChildren.reduce(reducer, {}));
}

const mycount = counter[type] || 0;
mycounter[type] = mycount + 1;
return Object.assign(counter, mycounter);
}, {});
}

const typecounter = children.reduce(reducer, {});

const types = Object.keys(typecounter).map(type => `has-${type}`);
if (Object.keys(typecounter).length === 1) {
Expand Down

0 comments on commit 3912d09

Please sign in to comment.