remcohaszing / rehype-mdx-title

A rehype MDX plugin for exposing the page title
MIT License
14 stars 1 forks source link

Add integration w/ `rehype-meta` #3

Open wooorm opened 3 years ago

wooorm commented 3 years ago

If title is also stored on vfile.data.meta, rehype-meta could use it to populate <title> in <head> (https://github.com/rehypejs/rehype-meta#config).

(I’m thinking of perhaps writing rehype-mdx-description (or named -summary, -excerpt?) to also expose the first few words as an export and file.meta.description, would be nice if they both could integrate rehype-meta)

remcohaszing commented 3 years ago

I like the idea, but wouldn’t it be a better idea to make this a separate plugin? I think extracting the document title isn’t related to mdx. In fact, maybe this plugin should be using vfile.data.meta.title instead of extracting it. The same property could also be used by rehype-document.

wooorm commented 3 years ago

Oh hmm, that’s a great idea. And indeed, was thinking of rehype-document supporting vfile.data.meta.title too.

So then it’s more a rehype-extract-meta-from-file (better named 😅) that does both title and description?

wooorm commented 3 years ago

Could also find the first image! and populate created/modified times from the vfile? 🤔

wooorm commented 3 years ago

/cc @ChristianMurphy

remcohaszing commented 3 years ago

I wonder how far meta data extraction should go.

I think extracting the title is obvious, since a document should have one <h1> element.

Extracting the description isn’t as obvious. What should be used? The first <blockquote> or <p> element? This tends to be obvious for markdown documents, but not as much for HTML.

wooorm commented 3 years ago

Could be either done on character/word count, or with a <!--summary:stop--> or so comment. rehype-infer-meta could also allow selectors to find the body that is to be extracted (defaulting to the root)

For images, classes could also be used to prefer a specific image. I think FB itself finds the biggest image on a page, but that requires file access

ChristianMurphy commented 3 years ago

Except has also been mentioned/floated as an idea at https://github.com/remarkjs/remark/discussions/794

wooorm commented 3 years ago

So how about plugins that add stuff to meta:

And then plugins like this one would instead take file.data.meta and export it? Or this one could be deprecated, and another one (recma-expose-meta) created?

remcohaszing commented 3 years ago

Or this one could be deprecated, and another one (recma-expose-meta) created?

That’s interesting. If we do this, then indeed this plugin has nothing to do with rehype anymore.

recma-expose-meta should probably take an array of meta names to expose as an option.

ChristianMurphy commented 3 years ago

unified-infer-meta-git-info

published, modified from Git? Also authors?

I've worked on a similar pull of author info in the past. https://github.com/ChristianMurphy/file-util-git-history is what I created to simplify extracting history metadata. https://github.com/askgitdev/askgit is another useful library for pulling information.

wooorm commented 3 years ago

file-util-git-history doesn’t work on node v16 :'(

ChristianMurphy commented 3 years ago

file-util-git-history doesn’t work on node v16 :'(

Not yet, it relies on LibGit2 wrapped with NodeGit, NodeGit is working on Node 16 support https://github.com/nodegit/nodegit/issues/1840 (support is currently in alpha)