简体   繁体   English

Strapi slug 希伯来语字符支持

[英]strapi slug Hebrew character support

I am having an issue finding any documentation regarding allowing the strapi slug filter manipulation I would like to allow it to whitelist Hebrew characters.我在查找有关允许strapi slug 过滤器操作的任何文档时遇到问题,我想允许它将希伯来语字符列入白名单。

at current state when trying to change the characters to Hebrew i get the error "This does not match the format"在当前状态下尝试将字符更改为希伯来语时出现错误“这与格式不匹配”

For this, you will want to create a specific slug behavior on your model.为此,您需要在模型上创建特定的 slug 行为。 The specifics are on "How to create a Slug" documentation.详细信息在“如何创建 Slug”文档中。 This uses slugify dependency on your endpoint.这使用slugify对您的端点的依赖。

Please check the documentation there, you can configure it appropriately to allow a specific locale and or special characters.请检查那里的文档,您可以适当地配置它以允许特定的语言环境和/或特殊字符。

Slugify example options: Slugify 示例选项:

slugify('some string', {
  replacement: '-',  // replace spaces with replacement character, defaults to `-`
  remove: undefined, // remove characters that match regex, defaults to `undefined`
  lower: false,      // convert to lower case, defaults to `false`
  strict: false,     // strip special characters except replacement, defaults to `false`
  locale: 'vi',       // language code of the locale to use
  trim: true         // trim leading and trailing replacement chars, defaults to `true`
})

And now on your model JavaScript file:现在在您的模型 JavaScript 文件上:

const slugify = require('slugify');

module.exports = {
  /**
   * Triggered before user creation.
   */
  lifecycles: {
    async beforeCreate(data) {
      if (data.title) {
        data.slug = slugify(data.title, {HERE_YOUR_OPTIONS});
      }
    },
    async beforeUpdate(params, data) {
      if (data.title) {
        data.slug = slugify(data.title, {HERE_YOUR_OPTIONS});
      }
    },
  },
};

Ref:参考:
https://strapi.io/documentation/developer-docs/latest/guides/slug.html#create-attributes https://github.com/simov/slugify https://strapi.io/documentation/developer-docs/latest/guides/slug.html#create-attributes https://github.com/simov/slugify

在 Strapi 的第 4 版中,这成为一个无问题,它现在支持所有语言

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM