% if (get_config('toc') === true && (post.layout === 'page' || post.layout === 'post')) {
function buildToc(toc) {
let result = '';
if (toc.hasOwnProperty('id') && toc.hasOwnProperty('index') && toc.hasOwnProperty('text')) {
result += `
${toc.index}
${toc.text}
`;
}
let keys = Object.keys(toc);
keys.indexOf('id') > -1 && keys.splice(keys.indexOf('id'), 1);
keys.indexOf('text') > -1 && keys.splice(keys.indexOf('text'), 1);
keys.indexOf('index') > -1 && keys.splice(keys.indexOf('index'), 1);
keys = keys.map(k => parseInt(k)).sort((a, b) => a - b);
if (keys.length > 0) {
result += '';
}
if (toc.hasOwnProperty('id') && toc.hasOwnProperty('index') && toc.hasOwnProperty('text')) {
result += '';
}
return result;
}
%>
<% } %>