articleDecorator.js 670 B

12345678910111213141516171819202122
  1. module.exports = function articleDecorator(config, item, meta) {
  2. let blurb = "No description.";
  3. const introMatches = item.content.match(
  4. new RegExp("<p>(?<introText>[a-zA-Z0-9 :,.-]+)</p>", "m")
  5. );
  6. if (introMatches) {
  7. blurb = introMatches.groups.introText.trim();
  8. }
  9. const titleStart = item.content.indexOf(">", item.content.indexOf("<h1")) + 1;
  10. const titleEnd = item.content.indexOf("</h1>");
  11. const title =
  12. titleEnd > -1
  13. ? item.content.substring(titleStart, titleEnd).trim()
  14. : meta.name;
  15. return {
  16. ...item,
  17. niceName: title.replace(/<[^>]*>?/gm, ""),
  18. blurb: blurb,
  19. tags: [].concat(item.tags, ["article"])
  20. };
  21. };