pretty_urls.js 423 B

123456789101112131415161718
  1. 'use strict';
  2. function prettyUrls(url, options = {}) {
  3. options = Object.assign({
  4. trailing_index: true,
  5. trailing_html: true
  6. }, options);
  7. const indexPattern = /index\.html$/;
  8. if (options.trailing_index === false) url = url.replace(indexPattern, '');
  9. if (options.trailing_html === false && !indexPattern.test(url)) {
  10. url = url.replace(/\.html$/, '');
  11. }
  12. return url;
  13. }
  14. module.exports = prettyUrls;