Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PipecraftNet committed Sep 4, 2021
1 parent 56c52c6 commit 22f4989
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
vendor
composer.lock
js/dist
32 changes: 32 additions & 0 deletions README-cn.md
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。
34 changes: 32 additions & 2 deletions README.md
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.
43 changes: 43 additions & 0 deletions composer.json
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/"
}
}
}
20 changes: 20 additions & 0 deletions extend.php
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),
];
25 changes: 25 additions & 0 deletions src/Listeners/SlugOverwriter.php
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 = '';
}
}
}

0 comments on commit 22f4989

Please sign in to comment.