articleDecorator.js 689 B

123456789101112131415161718192021222324
  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. console.log("tts", titleStart, titleEnd);
  12. const title =
  13. titleEnd > -1
  14. ? item.content.substring(titleStart, titleEnd).trim()
  15. : meta.name;
  16. return {
  17. ...item,
  18. niceName: title,
  19. blurb: blurb,
  20. tags: [].concat(item.tags, ["article"])
  21. };
  22. };