{"id":18926776,"url":"https://github.com/ladjs/koa-meta","last_synced_at":"2025-04-15T13:33:20.583Z","repository":{"id":25021422,"uuid":"102979829","full_name":"ladjs/koa-meta","owner":"ladjs","description":"SEO \u003ctitle\u003e and \u003cmeta name=\"description\"\u003e middleware for Koa and Lad","archived":false,"fork":false,"pushed_at":"2023-06-09T01:22:39.000Z","size":698,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-01T16:40:13.340Z","etag":null,"topics":["children","description","dictionary","koa","lookup","meta","metadata","node","path","recursive","seo","title"],"latest_commit_sha":null,"homepage":"https://lad.js.org","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/ladjs.png","metadata":{"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":"2017-09-09T19:28:28.000Z","updated_at":"2022-01-13T21:18:31.000Z","dependencies_parsed_at":"2024-06-19T19:04:32.987Z","dependency_job_id":"aeb634b8-8c1d-4fb9-8466-27217ccfaf8a","html_url":"https://github.com/ladjs/koa-meta","commit_stats":{"total_commits":61,"total_committers":4,"mean_commits":15.25,"dds":0.3770491803278688,"last_synced_commit":"2901216c4d768eaca0064169457b210695b4e0ea"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-meta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-meta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-meta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-meta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/koa-meta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223672916,"owners_count":17183618,"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":["children","description","dictionary","koa","lookup","meta","metadata","node","path","recursive","seo","title"],"created_at":"2024-11-08T11:17:09.105Z","updated_at":"2024-11-08T11:17:09.591Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-meta\n\n[![build status](https://github.com/ladjs/koa-meta/actions/workflows/ci.yml/badge.svg)](https://github.com/ladjs/koa-meta/actions/workflows/ci.yml)\n[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)\n[![license](https://img.shields.io/github/license/ladjs/koa-meta.svg)]()\n\n\u003e Meta `\u003ctitle\u003e` and `\u003cmeta name=\"description\"\u003e` middleware for Koa and Lad\n\n\n## Table of Contents\n\n* [Install](#install)\n* [Usage](#usage)\n* [Translation Support](#translation-support)\n* [Child Path Support](#child-path-support)\n* [Error Catching](#error-catching)\n* [Contributors](#contributors)\n* [License](#license)\n\n\n## Install\n\n[npm][]:\n\n```sh\nnpm install koa-meta\n```\n\n\n## Usage\n\n\u003e Use middleware:\n\n```js\nconst path = require('path');\n\nconst views = require('@ladjs/koa-views');\nconst Meta = require('koa-meta');\n\n/// ...\n\n// set template rendering engine (see @ladjs/web for inspiration)\napp.use(views(path.join(__dirname, 'views')));\n\nconst meta = new Meta({\n  '/': [ 'Home', 'Our home page description' ],\n  '/contact', [ 'Contact', 'Contact us with questions' ]\n});\n\n// note: you can also pass a second argument of a custom `logger`\n// the default logger is `console` and must have a `.error` method\n// `const meta = new Meta({}, console);`\n\napp.use(meta.middleware);\n\napp.use((ctx, next) =\u003e {\n  // since the previous middleware was defined before this\n  // the `ctx.state` object has been populated with metadata\n  // when the render call occurs (it will not override any existing set values)\n  // for a request with `ctx.path` of `/` it will output:\n  // { title: 'Home', description: 'Our home page description' }\n  ctx.render('home');\n});\n```\n\nTherefore in your views you can render the meta data easily:\n\n```pug\ndoctype html\nhtml\n  head\n    title= meta.title\n    meta(name=\"description\", content=meta.description)\n```\n\n\u003e Programmatically get a meta object/translated version of `title` and `description`:\n\n```js\nconst Meta = require('koa-meta');\n\nconst meta = new Meta({\n  '/': [ 'Home', 'Our home page description' ],\n  '/posts': [ 'Posts', 'Posts by our team' ]\n});\n\nconsole.log(meta.getByPath('/posts/123456'));\n// `{ title: 'Posts', description: 'Posts by our team' }`\n```\n\n\n## Translation Support\n\nThis package supports translation out of the box.\n\nIt checks for a function set on `ctx.request.t` and utilizes that function to translate based off the request's locale.\n\n\n## Child Path Support\n\nThis package supports parent meta data lookup for children of paths.\n\nThis means if you define in your configuration a path of `/posts` and a request is made to `/posts/123456` (with this path not being defined in your configuration), then it will use `/posts` definition for `/posts/123456`.\n\n\n## Error Catching\n\nBy default this package will throw an error if a child path was found that does not have a parent defined.\n\nThis is extremely useful for retaining quality control with your configuration.\n\nHowever this is configurable based off the third argument passed to `new Meta()`, e.g. `new Meta(config, logger, levelForMissing`.\n\nThe value of `levelForMissing` defaults to `error` for when `process.env.NODE_ENV` is equal to `development`, otherwise it defaults to `debug`.\n\nThis is configurable, therefore you can simply pass `new Meta(config, logger, 'warn')` if you want `warn` to be the log level for missing meta configurations.\n\n\n## Contributors\n\n| Name           | Website                    |\n| -------------- | -------------------------- |\n| **Nick Baugh** | \u003chttp://niftylettuce.com/\u003e |\n\n\n## License\n\n[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)\n\n\n##\n\n[npm]: https://www.npmjs.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fkoa-meta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fkoa-meta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fkoa-meta/lists"}