-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56c52c6
commit 22f4989
Showing
6 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
vendor | ||
composer.lock | ||
js/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# ID Slug by Pipecraft | ||
|
||
这是一个使discussion的URL只包含`id`的[Flarum](http://flarum.org)插件。 | ||
|
||
- AS-IS: | ||
- http://exmaple.com/d/123-hello-world | ||
- http://exmaple.com/d/123-hello-world/3 | ||
- TO-BE: | ||
- http://exmaple.com/d/123 | ||
- http://exmaple.com/d/123/3 | ||
|
||
### Installation | ||
|
||
```sh | ||
composer require pipecraft/flarum-ext-id-slug | ||
``` | ||
|
||
### Updating | ||
|
||
```sh | ||
composer update pipecraft/flarum-ext-id-slug | ||
``` | ||
|
||
### 如何更新已有数据 | ||
|
||
你可以执行一个SQL,类似 | ||
|
||
```sql | ||
UPDATE `flarum_discussions` SET `slug`='' WHERE <condition>; | ||
``` | ||
|
||
或在Flarum页面修改标题,更新slug。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# flarum-ext-id-slug | ||
A Flarum extension. Use id as slug in discussion URL. | ||
# ID Slug by Pipecraft | ||
|
||
A [Flarum](http://flarum.org) extension. Use `id` as the `slug` in the discussion URL. | ||
|
||
- AS-IS: | ||
- http://exmaple.com/d/123-hello-world | ||
- http://exmaple.com/d/123-hello-world/3 | ||
- TO-BE: | ||
- http://exmaple.com/d/123 | ||
- http://exmaple.com/d/123/3 | ||
|
||
### Installation | ||
|
||
```sh | ||
composer require pipecraft/flarum-ext-id-slug | ||
``` | ||
|
||
### Updating | ||
|
||
```sh | ||
composer update pipecraft/flarum-ext-id-slug | ||
``` | ||
|
||
### How to Update the Slug of Existing Discussions | ||
|
||
You can run this SQL to clear all slugs. | ||
|
||
```sql | ||
UPDATE `flarum_discussions` SET `slug`='' WHERE <condition>; | ||
``` | ||
|
||
Or you can rename the title of the discussion to update the slug. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "pipecraft/flarum-ext-id-slug", | ||
"description": "A Flarum extension. Use id as slug in discussion URL.", | ||
"keywords": [ | ||
"flarum", | ||
"slug" | ||
], | ||
"type": "flarum-extension", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Pipecraft", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/PipecraftNet/flarum-ext-id-slug/issues", | ||
"source": "https://github.com/PipecraftNet/flarum-ext-id-slug" | ||
}, | ||
"homepage": "https://github.com/PipecraftNet", | ||
"require": { | ||
"flarum/core": "^1.0.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Pipecraft\\IdSlug\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"flarum-extension": { | ||
"title": "ID Slug", | ||
"category": "feature", | ||
"icon": { | ||
"name": "fas fa-info", | ||
"backgroundColor": "#000", | ||
"color": "#fff" | ||
} | ||
}, | ||
"flagrow": { | ||
"discuss": "https://discuss.flarum.org/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of PipecraftNet/flarum-ext-id-slug | ||
* | ||
* Copyright (c) Pipecraft. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pipecraft\IdSlug; | ||
|
||
use Flarum\Discussion\Event\Saving; | ||
use Flarum\Extend; | ||
|
||
return [ | ||
(new Extend\Event()) | ||
->listen(Saving::class, Listeners\SlugOverwriter::class), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of PipecraftNet/flarum-ext-id-slug | ||
* | ||
* Copyright (c) Pipecraft. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pipecraft\IdSlug\Listeners; | ||
|
||
use Flarum\Discussion\Event\Saving; | ||
use Illuminate\Support\Arr; | ||
|
||
class SlugOverwriter | ||
{ | ||
public function handle(Saving $event) | ||
{ | ||
if (Arr::has($event->data, 'attributes.title')) { | ||
$event->discussion->slug = ''; | ||
} | ||
} | ||
} |