articleDecorator.js 733 B

1234567891011121314151617181920
  1. module.exports = function articleDecorator(config, item, meta) {
  2. const introStart = item.content.indexOf("<p>") + 3;
  3. const introEnd = item.content.indexOf("</p>");
  4. let cutoff;
  5. if (introEnd - introStart > config.cutoffLength) {
  6. cutoff = item.content.indexOf("p>", introStart + config.cutoffLength) + 1;
  7. } else {
  8. cutoff = introEnd;
  9. }
  10. const blurb = item.content.substring(introStart, cutoff);
  11. const titleStart = item.content.indexOf(">", item.content.indexOf("<h1")) + 1;
  12. const titleEnd = item.content.indexOf("</h1>");
  13. const title = item.content.substring(titleStart, titleEnd) || meta.name;
  14. return {
  15. ...item,
  16. niceName: title,
  17. blurb: blurb,
  18. tags: [].concat(item.tags, ["article"])
  19. };
  20. };