corowne / lorekeeper

A dA ARPG masterlist framework
MIT License
109 stars 122 forks source link

Make hash come AFTER image ID for correct sorting #1083

Open ScuffedNewt opened 4 days ago

ScuffedNewt commented 4 days ago

Currently, image hashes are in the form {hash}-{id}-image.png (with some minor variations)

my proposal, inspired by @preimpression, is to change this convention to {id}-{hash}-image.png

Why?

Steps to do this:

I'm happy enough to do this when the opportunity next arises, unless there's some major objections

itinerare commented 4 days ago

Is this regarding item, etc. images?

ScuffedNewt commented 4 days ago

yep!

itinerare commented 4 days ago

Gotcha. Makes sense to me, then.

SpeedyD commented 4 days ago

..and on that note, I think I'll be making helpers to call on specific items/traits/etc..

So that an admin can just put [item-img-345] in their news post and guess what: get item no.345's image, linking to the item.

...especially since this'll mean I need to change some newsposts AGAIN XD

itinerare commented 4 days ago

Oh, I did that for our purposes and I guess never PRed it in? so I could probably do that as well.

preimpression commented 4 days ago

This is what I ended up doing for the helper for items. Just using the same syntax that previously existed for something (I've added a bunch of these so I don't recall which were the originals,)


 * Parses a piece of user-entered text to match item mentions
 * and replace with a thumbnail link.
 *
 * @param string $text
 * @param mixed  $items
 *
 * @return string
 */
function parseItems($text, &$items) {
    $matches = null;
    $items = [];
    $count = preg_match_all('/\[item=([^\[\]&<>?"\']+)\]/', $text, $matches);
    if ($count) {
        $matches = array_unique($matches[1]);
        foreach ($matches as $match) {
            $item = App\Models\Item\Item::where('id', $match)->first();
            if ($item) {
                $items[] = $item;
                $text = preg_replace('/\[item='.$match.'\]/', '<a href="'.$item->idUrl.'"><img src="'.$item->imageUrl.'" class="mw-100" alt="'.$item->name.'"></a>', $text);
            }
        }
    }

    return $text;
}
SpeedyD commented 2 days ago

I mean, I've done this for user avatars and such before, so I know how to do this. :P But if Merc has a quick PR they want to do, I'm not stopping them. 🤷

Either way: I think nobody had any objections? I'd like to suggest to @ScuffedNewt to go for it. :)