{"id":28487186,"url":"https://github.com/rehypejs/rehype-infer-title-meta","last_synced_at":"2025-07-01T17:30:33.574Z","repository":{"id":44807229,"uuid":"404745076","full_name":"rehypejs/rehype-infer-title-meta","owner":"rehypejs","description":"plugin to infer file metadata from the main title of a document","archived":false,"fork":false,"pushed_at":"2023-09-02T07:55:06.000Z","size":47,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-07T07:03:23.328Z","etag":null,"topics":["file","hast","meta","rehype","rehype-plugin","title"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rehypejs.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-09T14:04:27.000Z","updated_at":"2023-07-10T16:00:34.000Z","dependencies_parsed_at":"2024-06-20T00:09:38.223Z","dependency_job_id":"54c5a85a-bbff-42fb-a36d-93b60eb9136e","html_url":"https://github.com/rehypejs/rehype-infer-title-meta","commit_stats":{"total_commits":25,"total_committers":1,"mean_commits":25.0,"dds":0.0,"last_synced_commit":"16824192f3c2e8be69addfde1b8cbb251ad67e07"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/rehypejs/rehype-infer-title-meta","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-infer-title-meta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-infer-title-meta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-infer-title-meta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-infer-title-meta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rehypejs","download_url":"https://codeload.github.com/rehypejs/rehype-infer-title-meta/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-infer-title-meta/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263006990,"owners_count":23398740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file","hast","meta","rehype","rehype-plugin","title"],"created_at":"2025-06-08T04:12:09.508Z","updated_at":"2025-07-01T17:30:33.551Z","avatar_url":"https://github.com/rehypejs.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"readme":"# rehype-infer-title-meta\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n**[rehype][]** plugin to infer the title of a document.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`unified().use(rehypeInferTitleMeta, options?)`](#unifieduserehypeinfertitlemeta-options)\n    *   [`Options`](#options)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a [unified][] ([rehype][]) plugin to infer the title of a\ndocument.\n\n**unified** is a project that transforms content with abstract syntax trees\n(ASTs).\n**rehype** adds support for HTML to unified.\n**vfile** is the virtual file interface used in unified.\n**hast** is the HTML AST that rehype uses.\nThis is a rehype plugin that inspects hast and adds metadata to vfiles.\n\n## When should I use this?\n\nThis plugin is particularly useful in combination with\n[`rehype-document`][rehype-document] or [`rehype-meta`][rehype-meta].\nWhen both are used together, the `\u003ctitle\u003e` is populated with the document’s\ntitle.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install rehype-infer-title-meta\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport rehypeInferTitleMeta from 'https://esm.sh/rehype-infer-title-meta@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import rehypeInferTitleMeta from 'https://esm.sh/rehype-infer-title-meta@2?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay our module `example.js` looks as follows:\n\n```js\nimport rehypeDocument from 'rehype-document'\nimport rehypeFormat from 'rehype-format'\nimport rehypeInferTitleMeta from 'rehype-infer-title-meta'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport {unified} from 'unified'\n\nconst file = await unified()\n  .use(remarkParse)\n  .use(remarkRehype)\n  .use(rehypeInferTitleMeta)\n  .use(rehypeDocument)\n  .use(rehypeFormat)\n  .use(rehypeStringify)\n  .process('# Hello, world!')\n\nconsole.log(file.data)\nconsole.log(String(file))\n```\n\n…now running `node example.js` yields:\n\n```js\n{meta: {title: 'Hello, world!'}}\n```\n\n```html\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003eHello, world!\u003c/title\u003e\n    \u003cmeta content=\"width=device-width, initial-scale=1\" name=\"viewport\"\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eHello, world!\u003c/h1\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## API\n\nThis package exports no identifiers.\nThe default export is [`rehypeInferTitleMeta`][api-rehype-infer-title-meta].\n\n### `unified().use(rehypeInferTitleMeta, options?)`\n\nInfer file metadata from the main title of a document.\n\nThe result is stored on `file.data.meta.title`.\n\n###### Parameters\n\n*   `options` ([`Options`][api-options], optional)\n    — configuration\n\n###### Returns\n\nTransform ([`Transformer`][unified-transformer]).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n*   `selector` (`string`, default: `'h1'`)\n    — CSS selector to the title; can be a selector list (such as `'title, h1,\n    .main-heading'`), in which case the first element in the tree that matches\n    is used\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`Options`][api-options].\n\nIt also registers `file.data.meta` with `vfile`.\nIf you’re working with the file, make sure to import this plugin somewhere in\nyour types, as that registers the new fields on the file.\n\n```js\n/**\n * @typedef {import('rehype-infer-title-meta')}\n */\n\nimport {VFile} from 'vfile'\n\nconst file = new VFile()\n\nconsole.log(file.data.meta.title) //=\u003e TS now knows that this is a `string?`.\n```\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line,\n`rehype-infer-title-meta@^2`, compatible with Node.js 16.\n\nThis plugin works with `rehype-parse` version 3+, `rehype-stringify` version 3+,\n`rehype` version 4+, and `unified` version 6+.\n\n## Security\n\nUse of `rehype-infer-title-meta` is safe.\n\n## Related\n\n*   [`rehype-document`][rehype-document]\n    — wrap a fragment in a document\n*   [`rehype-meta`][rehype-meta]\n    — add metadata to the head of a document\n*   [`unified-infer-git-meta`](https://github.com/unifiedjs/unified-infer-git-meta)\n    — infer file metadata from Git\n*   [`rehype-infer-description-meta`](https://github.com/rehypejs/rehype-infer-description-meta)\n    — infer file metadata from the description of a document\n*   [`rehype-infer-reading-time-meta`](https://github.com/rehypejs/rehype-infer-reading-time-meta)\n    — infer file metadata from the reading time of a document\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`rehypejs/.github`][health] for ways\nto get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/rehypejs/rehype-infer-title-meta/workflows/main/badge.svg\n\n[build]: https://github.com/rehypejs/rehype-infer-title-meta/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-infer-title-meta.svg\n\n[coverage]: https://codecov.io/github/rehypejs/rehype-infer-title-meta\n\n[downloads-badge]: https://img.shields.io/npm/dm/rehype-infer-title-meta.svg\n\n[downloads]: https://www.npmjs.com/package/rehype-infer-title-meta\n\n[size-badge]: https://img.shields.io/bundlejs/size/rehype-infer-title-meta\n\n[size]: https://bundlejs.com/?q=rehype-infer-title-meta\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/rehypejs/rehype/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[health]: https://github.com/rehypejs/.github\n\n[contributing]: https://github.com/rehypejs/.github/blob/main/contributing.md\n\n[support]: https://github.com/rehypejs/.github/blob/main/support.md\n\n[coc]: https://github.com/rehypejs/.github/blob/main/code-of-conduct.md\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[rehype]: https://github.com/rehypejs/rehype\n\n[rehype-meta]: https://github.com/rehypejs/rehype-meta\n\n[rehype-document]: https://github.com/rehypejs/rehype-document\n\n[typescript]: https://www.typescriptlang.org\n\n[unified]: https://github.com/unifiedjs/unified\n\n[unified-transformer]: https://github.com/unifiedjs/unified#transformer\n\n[api-options]: #options\n\n[api-rehype-infer-title-meta]: #unifieduserehypeinfertitlemeta-options\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehypejs%2Frehype-infer-title-meta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frehypejs%2Frehype-infer-title-meta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehypejs%2Frehype-infer-title-meta/lists"}