mirror of
https://github.com/flarum/framework.git
synced 2025-02-06 06:56:14 +08:00
Merge pull request #1975 from flarum/fl/194-better-slugs
Use Laravel's slugger for basic transliteration
This commit is contained in:
commit
c26c06faf6
|
@ -16,6 +16,10 @@ export function truncate(string, length, start = 0) {
|
||||||
* Create a slug out of the given string. Non-alphanumeric characters are
|
* Create a slug out of the given string. Non-alphanumeric characters are
|
||||||
* converted to hyphens.
|
* converted to hyphens.
|
||||||
*
|
*
|
||||||
|
* NOTE: This method does not use the comparably sophisticated transliteration
|
||||||
|
* mechanism that is employed in the backend. Therefore, it should only be used
|
||||||
|
* to *suggest* slugs that can be overridden by the user.
|
||||||
|
*
|
||||||
* @param {String} string
|
* @param {String} string
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
* LICENSE file that was distributed with this source code.
|
* LICENSE file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Flarum\Util\Str;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Database\Schema\Builder;
|
use Illuminate\Database\Schema\Builder;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'up' => function (Builder $schema) {
|
'up' => function (Builder $schema) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ use Flarum\Notification\Notification;
|
||||||
use Flarum\Post\MergeableInterface;
|
use Flarum\Post\MergeableInterface;
|
||||||
use Flarum\Post\Post;
|
use Flarum\Post\Post;
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
use Flarum\Util\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* For detailed copyright and license information, please view the
|
|
||||||
* LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Util;
|
|
||||||
|
|
||||||
class Str
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create a slug out of the given string.
|
|
||||||
*
|
|
||||||
* Non-alphanumeric characters are converted to hyphens.
|
|
||||||
*
|
|
||||||
* @param string $str
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function slug($str)
|
|
||||||
{
|
|
||||||
$str = strtolower($str);
|
|
||||||
$str = preg_replace('/[^a-z0-9]/i', '-', $str);
|
|
||||||
$str = preg_replace('/-+/', '-', $str);
|
|
||||||
$str = preg_replace('/-$|^-/', '', $str);
|
|
||||||
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user