twozeroone / post-type-discovery

Implementation of post type discovery W3C spec
https://post-type-discovery.js.org/
BSD 3-Clause "New" or "Revised" License
5 stars 1 forks source link

Type Error when mf2 content property only contains html value #4

Open paulrobertlloyd opened 5 years ago

paulrobertlloyd commented 5 years ago

It would seem the mf2 objects created by Quill contain only a html value for the content property, i.e.:

{
  "type": ["h-entry"],
  "properties": {
    "name": ["Article name"],
    "content": [{
        "html": "<p>This is some HTML.</p>"
    }]
  }
} 

As this package assumes a content property will also contain a value key, such an mf2 object throws the following error:

TypeError: content.replace is not a function
  at contentIncludesName (/app/node_modules/post-type-discovery/index.js:26:32)
  at getType (/app/node_modules/post-type-discovery/index.js:80:6)
  at Object.module.exports [as createPost] (/app/app/lib/micropub/create-post.js:33:12)
  at getResult (/app/app/routes/micropub.js:88:23)
  at processTicksAndRejections (internal/process/next_tick.js:81:5)
paulrobertlloyd commented 5 years ago

I have fixed this by extracting a plain text value by using the html-to-text package, as can be seen in this commit. Not sure if this is the right approach, or reflects the intention behind the post type discovery heuristics however.

prtksxna commented 5 years ago

Thanks, I created a PR from your branch and merged it. Pushed to npm too.

Do you have an example (probably real world) of when this happens, I'd like to add it to the test suite so that there aren't any regressions in the future.