Tag normalization is now in the model, this is refelcted elsewhere in code usage
This commit is contained in:
parent
d50e902fb9
commit
50cb351167
4 changed files with 36 additions and 12 deletions
|
@ -155,17 +155,9 @@ class NotesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function taggedNotes($tag)
|
public function taggedNotes($tag)
|
||||||
{
|
{
|
||||||
$tag = mb_strtolower(
|
$notes = Note::whereHas('tags', function ($query) use ($tag) {
|
||||||
preg_replace(
|
$query->where('tag', $tag);
|
||||||
'/&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/i',
|
})->get();
|
||||||
'$1',
|
|
||||||
htmlentities($tag)
|
|
||||||
),
|
|
||||||
'UTF-8'
|
|
||||||
);
|
|
||||||
|
|
||||||
$tagId = Tag::where('tag', $tag)->pluck('id');
|
|
||||||
$notes = Tag::find($tagId)->notes()->orderBy('updated_at', 'desc')->get();
|
|
||||||
foreach ($notes as $note) {
|
foreach ($notes as $note) {
|
||||||
$note->iso8601_time = $note->updated_at->toISO8601String();
|
$note->iso8601_time = $note->updated_at->toISO8601String();
|
||||||
$note->human_time = $note->updated_at->diffForHumans();
|
$note->human_time = $note->updated_at->diffForHumans();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
use App\Tag;
|
||||||
use Normalizer;
|
use Normalizer;
|
||||||
use Jonnybarnes\IndieWeb\Numbers;
|
use Jonnybarnes\IndieWeb\Numbers;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
@ -216,7 +217,7 @@ class Note extends Model implements HasMedia
|
||||||
foreach ($matches[0] as $name) {
|
foreach ($matches[0] as $name) {
|
||||||
$name = str_replace('#', '', $name);
|
$name = str_replace('#', '', $name);
|
||||||
$replacements[$name] =
|
$replacements[$name] =
|
||||||
'<a rel="tag" class="p-category" href="/notes/tagged/' . $name . '">#' . $name . '</a>';
|
'<a rel="tag" class="p-category" href="/notes/tagged/' . Tag::normalizeTag($name) . '">#' . $name . '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace #tags with valid microformat-enabled link
|
// Replace #tags with valid microformat-enabled link
|
||||||
|
|
28
app/Tag.php
28
app/Tag.php
|
@ -36,4 +36,32 @@ class Tag extends Model
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize tags so they’re lowercase and fancy diatrics are removed.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
*/
|
||||||
|
public function setTagAttribute($value)
|
||||||
|
{
|
||||||
|
$this->attributes['tag'] = $this->normalizeTag($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method actually normalizes a tag. That means lowercase-ing and
|
||||||
|
* removing fancy diatric characters.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
*/
|
||||||
|
public static function normalizeTag($tag)
|
||||||
|
{
|
||||||
|
return mb_strtolower(
|
||||||
|
preg_replace(
|
||||||
|
'/&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/i',
|
||||||
|
'$1',
|
||||||
|
htmlentities($tag)
|
||||||
|
),
|
||||||
|
'UTF-8'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version {next}
|
||||||
|
- Better tag normalization code organisation
|
||||||
|
|
||||||
## Version 0.0.2 (2016-05-25)
|
## Version 0.0.2 (2016-05-25)
|
||||||
- Fix issue#1: tagged notes page needs the tag from the URL normalizing.
|
- Fix issue#1: tagged notes page needs the tag from the URL normalizing.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue