Open wooorm opened 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
.
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
?
Could also find the first image! and populate created/modified times from the vfile? 🤔
/cc @ChristianMurphy
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.
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
Except has also been mentioned/floated as an idea at https://github.com/remarkjs/remark/discussions/794
So how about plugins that add stuff to meta
:
h1, h2
?<!--excerpt-->
comment, or truncating the HTMLrehype-meta
, xast-util-feed
don’t support multiple authors (yet)?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?
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.
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.
file-util-git-history
doesn’t work on node v16 :'(
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)
If
title
is also stored onvfile.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 andfile.meta.description
, would be nice if they both could integraterehype-meta
)