{"id":21558809,"url":"https://github.com/jledentu/sails-hook-slugs","last_synced_at":"2025-04-10T10:43:07.305Z","repository":{"id":84558631,"uuid":"46822108","full_name":"jledentu/sails-hook-slugs","owner":"jledentu","description":"A Sails.js hook to add URL-friendly slugs in your models.","archived":false,"fork":false,"pushed_at":"2020-12-20T23:01:48.000Z","size":41,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T09:38:23.697Z","etag":null,"topics":["rest-api","sails","sails-hook"],"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/jledentu.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}},"created_at":"2015-11-24T22:16:14.000Z","updated_at":"2021-01-18T17:36:15.000Z","dependencies_parsed_at":"2023-03-12T23:37:42.686Z","dependency_job_id":null,"html_url":"https://github.com/jledentu/sails-hook-slugs","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jledentu%2Fsails-hook-slugs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jledentu%2Fsails-hook-slugs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jledentu%2Fsails-hook-slugs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jledentu%2Fsails-hook-slugs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jledentu","download_url":"https://codeload.github.com/jledentu/sails-hook-slugs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248200023,"owners_count":21063803,"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":["rest-api","sails","sails-hook"],"created_at":"2024-11-24T08:15:52.260Z","updated_at":"2025-04-10T10:43:07.298Z","avatar_url":"https://github.com/jledentu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sails-hook-slugs\n\n[![Build Status](https://travis-ci.org/jledentu/sails-hook-slugs.svg)](https://travis-ci.org/jledentu/sails-hook-slugs) [![Coverage Status](https://coveralls.io/repos/github/jledentu/sails-hook-slugs/badge.svg)](https://coveralls.io/github/jledentu/sails-hook-slugs) [![dependencies Status](https://david-dm.org/jledentu/sails-hook-slugs/status.svg)](https://david-dm.org/jledentu/sails-hook-slugs) [![npm](https://img.shields.io/npm/v/sails-hook-slugs.svg)](https://www.npmjs.com/package/sails-hook-slugs)\n\nThis [Sails.js](https://github.com/balderdashy/sails) hook generates URL-friendly slugs in your models.\n\n```\nhttp://www.myblog.com/post/233987\n-\u003e http://www.myblog.com/post/title-of-my-blog-post\n```\n\n## Installation\n\nAdd this hook to your Sails app:\n\n```shell\n$ npm install sails-hook-slugs\n```\n\nThat's all!\n\n## Usage\n\nAdd an attribute of type `slug` in a model:\n\n```js\nmodule.exports = {\n\n  attributes: {\n    title: {\n      type: 'string',\n      required: true,\n      unique: true\n    },\n    content: {\n      type: 'text'\n    },\n    slug: {\n      type: 'slug',\n      from: 'title',\n      blacklist: ['search']\n    }\n  }\n};\n```\n\nConfigure your slug attribute:\n\n* `from`: name of the attribute from which the slug will be defined (required)\n* `blacklist`: A list of reserved words to not use as this slug (optional)\n\n\nA `slug` attribute is automatically set when you create a record:\n\n```js\nPost.create({\n  title: 'This is a new post!!!',\n  content: 'Post content'\n})\n.then(function(post) {\n  console.log(post.slug); // 'this-is-a-new-post'\n});\n```\n\nIf a record of the same model has the same slug, a UUID is added at the end of the new slug:\n\n```js\nPost.create({\n  title: 'This is a new post!!!!',\n  content: 'A new post again'\n})\n.then(function(post) {\n  console.log(post.slug); // 'this-is-a-new-post-a50ec97e-9ae1-44a5-8fb2-81c665b61538'\n});\n```\n\nLike any other attribute, you can use it as criteria to find a given resource:\n\n```js\nPost.findOne({ slug: 'this-is-a-new-post' })\n.then(function(post) {\n  // Use the post\n})\n.catch(function(err) {\n  // ...\n});\n```\n\n## Configuration\n\nThese parameters can be changed in `sails.config.slugs`:\n\nParameter      | Type                | Details\n-------------- | ------------------- |:---------------------------------\nlowercase | `boolean` | Whether or not the generated slugs are lowercased. Defaults to `true`.\nblacklist | `Array\u003cstring\u003e` | A list of reserved words to not use as slugs in your application. Defaults to `[]`.\nseparator | `string` | Separator to use in slugs. Defaults to `-`.\n\n## License\n\nMIT © 2019 Jérémie Ledentu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjledentu%2Fsails-hook-slugs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjledentu%2Fsails-hook-slugs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjledentu%2Fsails-hook-slugs/lists"}