Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration w/ rehype-meta #3

Open
wooorm opened this issue Aug 29, 2021 · 12 comments
Open

Add integration w/ rehype-meta #3

wooorm opened this issue Aug 29, 2021 · 12 comments

Comments

@wooorm
Copy link

wooorm commented Aug 29, 2021

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
Copy link
Owner

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
Copy link
Author

wooorm commented Aug 29, 2021

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
Copy link
Author

wooorm commented Aug 29, 2021

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

@wooorm
Copy link
Author

wooorm commented Aug 29, 2021

/cc @ChristianMurphy

@remcohaszing
Copy link
Owner

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
Copy link
Author

wooorm commented Aug 29, 2021

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
Copy link

Except has also been mentioned/floated as an idea at remarkjs/remark#794

@wooorm
Copy link
Author

wooorm commented Aug 30, 2021

So how about plugins that add stuff to meta:

  • rehype-infer-meta-title: find the main title
    • first of a selector, defaulting to h1, h2?
  • rehype-infer-meta-image: find the main image
    • probably find the biggest, otherwise the first, image? If a selector is given, could use the one matching it?
  • rehype-infer-meta-description: find an excerpt
    • either by selector, <!--excerpt--> comment, or truncating the HTML
  • unified-infer-meta-git-info
    • published, modified from Git?
    • Also authors?
      • How to add Twitter (maybe even Facebook / GitHub / website / email)
      • rehype-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?

@remcohaszing
Copy link
Owner

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
Copy link

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
Copy link
Author

wooorm commented Aug 30, 2021

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

@ChristianMurphy
Copy link

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 nodegit/nodegit#1840 (support is currently in alpha)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants