{"size": 980, "ext": "js", "max_stars_repo_path": "lib/html.js", "max_stars_repo_name": "firstandthird/hapi-generate-sitemap", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/html.js", "max_issues_repo_name": "firstandthird/hapi-generate-sitemap", "max_issues_repo_issues_event_min_datetime": "2018-06-06T23:08:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-06T23:54:15.000Z", "max_forks_repo_path": "lib/html.js", "max_forks_repo_name": "firstandthird/hapi-generate-sitemap", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 12, "max_forks_count": null, "avg_line_length": 33.7931034483, "max_line_length": 109, "alphanum_fraction": 0.5846938776}
const groupBy = require('lodash.groupby');
const sortBy = require('lodash.sortby');

module.exports = (pages, h, pluginOptions) => {
  pages = sortBy(pages, ['section', 'path']);
  // if we're using a view just render and return that:;
  if (pluginOptions.htmlView !== '') {
    return h.view(pluginOptions.htmlView, { sitemap: pages });
  }
  // group the list by sections:
  const sections = groupBy(pages, (page) => page.section);
  // first list all the routes that have no section:
  let html = `
    <ul>
      ${sections.none.map((page) => `<li><a href="${page.url}">${page.title || page.url}</a></li>`).join('')}
    </ul>`;
  Object.keys(sections).sort().forEach(sectionName => {
    if (sectionName === 'none') {
      return;
    }
    html = `${html} <h2>${sectionName}</h2><ul>`;
    sections[sectionName].forEach(page => {
      html = `${html}<li><a href="${page.url}">${page.title || page.url}</a></li>`;
    });
    html = `${html}</ul>`;
  });
  return html;
};
