{"id":14967605,"url":"https://github.com/joyqi/koa-pug-middleware","last_synced_at":"2026-01-25T03:01:49.206Z","repository":{"id":63750851,"uuid":"570369311","full_name":"joyqi/koa-pug-middleware","owner":"joyqi","description":"A Koa Pug view render middleware.","archived":false,"fork":false,"pushed_at":"2025-09-25T09:24:45.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-30T07:25:46.799Z","etag":null,"topics":["koa","koa-pug","pug","pugjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/koa-pug-middleware","language":"TypeScript","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/joyqi.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}},"created_at":"2022-11-25T02:36:36.000Z","updated_at":"2025-09-25T09:24:21.000Z","dependencies_parsed_at":"2023-01-28T21:01:07.020Z","dependency_job_id":null,"html_url":"https://github.com/joyqi/koa-pug-middleware","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":"joyqi/typescript-module-template","purl":"pkg:github/joyqi/koa-pug-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joyqi%2Fkoa-pug-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joyqi%2Fkoa-pug-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joyqi%2Fkoa-pug-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joyqi%2Fkoa-pug-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joyqi","download_url":"https://codeload.github.com/joyqi/koa-pug-middleware/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joyqi%2Fkoa-pug-middleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28742973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T02:46:29.005Z","status":"ssl_error","status_checked_at":"2026-01-25T02:44:29.968Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["koa","koa-pug","pug","pugjs"],"created_at":"2024-09-24T13:38:20.814Z","updated_at":"2026-01-25T03:01:49.185Z","avatar_url":"https://github.com/joyqi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-pug-middleware\n\nThis is a Koa middleware wrapper for [Pug](https://pugjs.org/) template engine.\n\nCompare to [koa-pug](https://www.npmjs.com/package/koa-pug), this middleware has the following features:\n\n1. More elegant API, no need to pass `app` to `Pug` constructor.\n2. Follows KISS principle, keep more things to Pug.\n3. Support `koa@2` only.\n4. Support `pug@3` only.\n5. Add `context.setLocal` method, so you can set locals in middleware.\n\n## Installation\n\n```bash\nnpm install -s koa-pug-middleware\n```\n\n## Usage\n\n### Mount the middleware\n\nUse [Pug](https://pugjs.org/api/reference.html) options to initialize the middleware:\n\n```typescript\nimport * as Koa from 'koa';\nimport * as pug from 'koa-pug-middleware';\n\nconst app = new Koa();\n\napp.use(pug({\n  debug: false,\n  cache: true,        // NOTE: set to false in development\n  pretty: false,\n  compileDebug: false,\n  locals: {\n    globalFoo: 'bar'  // You can set global locals here\n  },\n  basedir: './views'\n}));\n```\n\n### `context.setLocal(key, value)`\n\nParameters:\n\n- `key` - The key of the local variable.\n- `value` - The value of the local variable.\n\n```typescript\napp.use(async (ctx) =\u003e {\n  ctx.setLocal('foo', 'bar');  // You can set locals here\n});\n```\n\n### `context.render(view, locals, options?)`\n\nParameters:\n\n- `view` - The path of the view file. Relative to the `basedir` option. You can omit the extension name.\n- `locals` - The locals for the view.\n- `options` - The options for the view. See [Pug options](https://pugjs.org/api/reference.html#options). Will override the options in the middleware.\n\n```typescript\napp.use(async (ctx) =\u003e {\n  await ctx.render('index', {\n    foo: 'bar'  // You can set locals here\n  });\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoyqi%2Fkoa-pug-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoyqi%2Fkoa-pug-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoyqi%2Fkoa-pug-middleware/lists"}