{"size": 651, "ext": "js", "max_stars_repo_path": "build/plugins/permalinks.js", "max_stars_repo_name": "akiraei/nativescript-vue.org", "max_stars_repo_stars_event_min_datetime": "2018-01-28T19:19:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-25T16:58:53.000Z", "max_issues_repo_path": "build/plugins/permalinks.js", "max_issues_repo_name": "akiraei/nativescript-vue.org", "max_issues_repo_issues_event_min_datetime": "2018-01-24T16:55:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-19T10:28:58.000Z", "max_forks_repo_path": "build/plugins/permalinks.js", "max_forks_repo_name": "akiraei/nativescript-vue.org", "max_forks_repo_forks_event_min_datetime": "2018-02-01T12:08:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-26T17:25:15.000Z"}
{"max_stars_count": 106, "max_issues_count": 340, "max_forks_count": 233, "avg_line_length": 25.0384615385, "max_line_length": 79, "alphanum_fraction": 0.5637480799}
const Permalinks = require('permalinks');

module.exports = function permalinks(options = {}) {
  const opts = Object.assign({}, {
    format: ':name/index.html',
    sets: []
  }, options);

  const pl = new Permalinks();

  return (files, metalsmith, done) => {
    Object.keys(files).forEach((file) => {
      const set = opts.sets.find(set => metalsmith.matches(file, set.pattern));
      let format = (set && set.format) || opts.format;

      try {
        const l = pl.format(format, file, files[file]);
        files[file].path = l;
        metalsmith.rename(file, l)
      } catch (err) {
        done(err);
      }
    });
    done();
  }
};