onecrayon / gridsome-plugin-feed

Generate an RSS, Atom, and/or JSON feed for your Gridsome site
13 stars 15 forks source link

Feed Output is Markdown, not HTML #6

Open RehanSaeed opened 4 years ago

RehanSaeed commented 4 years ago

The feed output is coming out as markdown and not HTML. There is a workaround in https://github.com/gridsome/gridsome/issues/514#issuecomment-510481670l to use marked but that does not include any custom remark plugins you may have added.

BobWalsh commented 4 years ago

Having the same issue.

scottsweb commented 4 years ago

I was just searching for a solution to this problem myself. I am working on a markdown powered site with a number of remark plugins and the feeds (atom, xml, json) contain raw markdown at the moment.

BobWalsh commented 4 years ago

@scottsweb - I fixed it with the workaround mentioned by @RehanSaeed, but still.

freaktechnik commented 3 years ago

The workaround has one big downside: any images in content will not work, due to whatever markdown transformer you'd end up using not knowing about the transforms gridsome does to the image paths. Same applies to links to other resources/attachments in content that rely on gridsome packing them up while importing the markdown files.

jacurtis commented 3 years ago

Yes, tonight I discovered the same problem that @freaktechnik mentioned. If you manually render your HTML from the markdown node.content then you end up with incorrect image URLs because of how Gridsome processes them, packs them, and organizes images for you in the dist/ folder. This means that this workaround simply will NOT work with images (or at least locally hosted ones).

According to https://github.com/gridsome/gridsome/issues/514#issuecomment-510481670 it appears that the Remark Transformer only runs when a GraphQL query is made for each post. This is a strange architectural decision for Gridsome since you would ideally run this during the build process for each post and not have to do it again. Then any plugins that run on api.afterBuild() would have access to the processed content. But unfortunately, I imagine that making a change as extreme as this would probably require a breaking change in Gridsome to fix (having the transformer run on build instead of on query).

So... the "solution" is to have a GraphQL query in the Feed Plugin. I'm going to look into this tomorrow to see if I can engineer a PR for this plugin that would use a GraphQL query to get the posts for your feed.

Advantages of this method:

  1. This would (theoretically) automatically use the settings and plugins you have configured in your Remark Transformer
  2. It would solve the Image problem (since this would generate the HTML after images have been processed).
  3. You could potentially query for the feed differently than you query for your website (if you wanted the RSS feed to be slightly different than your website content for some reason)

Disadvantages of this method:

  1. It is not D.R.Y - (you would need to replicate your contentType GraphQL query)
  2. Not very elegant to put a GraphQL query in your settings
  3. Potentially confusing for newbies who just want an RSS feed and don't understand GraphQL

I've spent two nights just figuring out the problem (that the transformer only runs when you query GraphQL ). So I'm going to pick this project up tomorrow or the next day. But I don't think it will be too hard to implement using the GraphQL query, and it will largely solve everyone's issues.