mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 06:53:47 +08:00
No slug? Then no '-' separator! (#1351)
* Stop using slug separator when there is no slug * Changing as per upstream requirements
This commit is contained in:
parent
6922c3081e
commit
0fedee8f80
|
@ -34,8 +34,9 @@ export default function(app) {
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
app.route.discussion = (discussion, near) => {
|
app.route.discussion = (discussion, near) => {
|
||||||
|
const slug = discussion.slug();
|
||||||
return app.route(near && near !== 1 ? 'discussion.near' : 'discussion', {
|
return app.route(near && near !== 1 ? 'discussion.near' : 'discussion', {
|
||||||
id: discussion.id() + '-' + discussion.slug(),
|
id: discussion.id() + (slug.trim() ? '-' + slug : ''),
|
||||||
near: near && near !== 1 ? near : undefined
|
near: near && near !== 1 ? near : undefined
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,7 @@ export function slug(string) {
|
||||||
return string.toLowerCase()
|
return string.toLowerCase()
|
||||||
.replace(/[^a-z0-9]/gi, '-')
|
.replace(/[^a-z0-9]/gi, '-')
|
||||||
.replace(/-+/g, '-')
|
.replace(/-+/g, '-')
|
||||||
.replace(/-$|^-/g, '') || '-';
|
.replace(/-$|^-/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,6 +28,6 @@ class Str
|
||||||
$str = preg_replace('/-+/', '-', $str);
|
$str = preg_replace('/-+/', '-', $str);
|
||||||
$str = preg_replace('/-$|^-/', '', $str);
|
$str = preg_replace('/-$|^-/', '', $str);
|
||||||
|
|
||||||
return $str ?: '-';
|
return $str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
@foreach ($document->data as $discussion)
|
@foreach ($document->data as $discussion)
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ $url->to('forum')->route('discussion', [
|
<a href="{{ $url->to('forum')->route('discussion', [
|
||||||
'id' => $discussion->id . '-' . $discussion->attributes->slug
|
'id' => $discussion->id . (trim($discussion->attributes->slug) ? '-' . $discussion->attributes->slug : '')
|
||||||
]) }}">
|
]) }}">
|
||||||
{{ $discussion->attributes->title }}
|
{{ $discussion->attributes->title }}
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user