gatsby-theme-brain icon indicating copy to clipboard operation
gatsby-theme-brain copied to clipboard

What's in previewHtml?

Open JuanCaicedo opened this issue 4 years ago • 2 comments

Hi Aengus! 😀

I'm going through and setting up this plugin and am a little confused about the shape of the inboundReferencePreviews on each note.

Looking at your example for how to render references, I see a property coming in that's previewHtml.

What ends up being included in previewHtml? In some of your pages, I see that it can carry quite a lot of content, like in https://aengusmcmillin.com/brain/books.

What content ends up being included in a preview?

I can draft up something to add to the docs about it 👍

JuanCaicedo avatar Jun 06 '20 23:06 JuanCaicedo

Hi Juan.

The previewHtml is a little bit nebulous at the moment, and I haven't spent tons of time pinning it down exactly. What I'm doing in the code is applying a heuristic to try and extract a subtree of the markdown AST containing just the relevant section containing the inbound link. The problem is the heuristic isn't great yet, so although it works well in some cases (mainly in a normal paragraph based page), in others it pulls in way too much content.

You could try and write something up in the readme (it would be appreciated!) but it will likely change whenever I get around to improving this. And if you want to see the code that generates this, checkout https://github.com/aengusmcmillin/gatsby-theme-brain/blob/master/src/source-nodes.js#L562

aengusmcmillin avatar Jun 08 '20 14:06 aengusmcmillin

Cool, thanks for sharing! It looks like right now what is does is pull in the whole parent node of the reference, so I'm assuming the whole node that contains the [[link]]

Yeah, I could see how it's tricky to figure out what to share in a preview 😅 It might even be that it's something that someone wants to decide on a note-by-note basis.

I'm thinking that maybe the right way to document it would be to document the props passed to BrainNote.

For now, those look like this to me:

  • childMdx
  • inboundReferencePreviews
  • inboundReferences
  • slug
  • title

JuanCaicedo avatar Jun 09 '20 03:06 JuanCaicedo