{"id":25597965,"url":"https://github.com/reod/koa-head","last_synced_at":"2025-07-14T03:08:48.221Z","repository":{"id":33682605,"uuid":"160518939","full_name":"reod/koa-head","owner":"reod","description":"A document head manager middleware for koa.","archived":false,"fork":false,"pushed_at":"2023-10-26T23:39:39.000Z","size":757,"stargazers_count":4,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-06-15T16:11:54.976Z","etag":null,"topics":["document","head","koa","koa-head","middleware"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2018-12-05T13:01:33.000Z","updated_at":"2024-09-17T19:56:21.000Z","dependencies_parsed_at":"2025-04-13T03:41:39.603Z","dependency_job_id":"9e868174-a8be-44b2-a72e-1c92edb23e0c","html_url":"https://github.com/reod/koa-head","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/reod/koa-head","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reod%2Fkoa-head","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reod%2Fkoa-head/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reod%2Fkoa-head/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reod%2Fkoa-head/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reod","download_url":"https://codeload.github.com/reod/koa-head/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reod%2Fkoa-head/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265236918,"owners_count":23732504,"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":["document","head","koa","koa-head","middleware"],"created_at":"2025-02-21T13:19:59.769Z","updated_at":"2025-07-14T03:08:48.187Z","avatar_url":"https://github.com/reod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Known Vulnerabilities](https://snyk.io/test/github/reod/koa-head/badge.svg?targetFile=package.json)](https://snyk.io/test/github/reod/koa-head?targetFile=package.json)\n\n# koa-head\n\nA document head manager middleware for koa.\n\n## Installation\n\n`npm i koa-head`\n\n## TL;DR example\n\n**note:** this package can be used as native ES6 module but has fallback to CommonJS `require`.\n\n```js\nimport Koa from \"koa\";\nimport koaHead from \"koa-head\";\n\nconst app = new Koa();\n\napp\n  .use(koaHead())\n  .use(async (ctx, next) =\u003e {\n    ctx.documentHead.setTitle(\"Title for my webpage\");\n    ctx.documentHead.addMetaTag({\n      name: \"twitter:card\",\n      content: \"summary_large_image\"\n    });\n    ctx.documentHead.addLink({ rel: \"canonical\", href: \"index.html\" });\n    ctx.documentHead.addStyle(\"body { background: aliceblue; }\");\n    ctx.documentHead.addScript(\"{ fixture: 'test fixture' }\");\n\n    await next();\n  })\n  .use(ctx =\u003e {\n    const documentHead = ctx.documentHead.toHTML();\n    const userData = { name: \"John Doe\" };\n\n    await ctx.myAwesomeLayoutEngine(\"user-view\", {\n      documentHead,\n      userData\n    });\n  });\n\napp.listen(3333);\n```\n\nwill make `documentHead` variable to contain:\n\n```html\n\u003ctitle\u003eTitle for my webpage\u003c/title\u003e\n\u003cmeta name=\"twitter:card\" content=\"summary_large_image\" /\u003e\n\u003clink rel=\"canonical\" href=\"index.html\" /\u003e\n\u003cstyle type=\"text/css\"\u003e\n  body {\n    background: aliceblue;\n  }\n\u003c/style\u003e\n\u003cscript type=\"text/javascript\"\u003e\n  {\n    fixture: \"test fixture\";\n  }\n\u003c/script\u003e\n```\n\nso you can use it in a place in your layout.\n\n## Available methods\n\n### `.setTitle( string | object )`\n\nSet document title.\n\n### `.addMetaTag( object )`\n\nAdd `\u003cmeta /\u003e` tag.\n\n### `.addLink( object )`\n\nAdd `\u003clink /\u003e` tag.\n\n### `.addStyle( string | object )`\n\nAdd `\u003cstyle /\u003e` tag.\n\n### `.addScript( string | object )`\n\nAdd `\u003cscript /\u003e` tag.\n\n### `.toHtml()`\n\nRender all set content to coresponding HTML tags.\n\n## Middleware factory function config\n\n| Option                   | Description                                                                                                                        | Default value          |\n| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |\n| `ctxNamespace`           | Name under which middleware is exposed in `cxt` object and is used by other middlewares i.e. `ctx.documentHead.setTitle('Hello')`. | `'documentHead'`       |\n| `stateNamespace`         | Name under which middleware stores values in `ctx.state`                                                                           | `'documentHead'`       |\n| `documentTitleFormatter` | If set, all values passed to `.setTitle()` function will pe parsed by this formatter.                                              | `title =\u003e title`       |\n| `toHtml`                 | Config for toHtml function.                                                                                                        | `{ [default_values] }` |\n| `toHtml.tagSeparator`    | Separator between tags inside one group.                                                                                           | `\\n`                   |\n| `toHtml.groupSeparator`  | Separator between group of tags.                                                                                                   | `\\n\\n`                 |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freod%2Fkoa-head","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freod%2Fkoa-head","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freod%2Fkoa-head/lists"}