corowne / lorekeeper

A dA ARPG masterlist framework
MIT License
113 stars 125 forks source link

Make hash come AFTER image ID for correct sorting #1083

Open ScuffedNewt opened 1 month ago

ScuffedNewt commented 1 month 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 1 month ago

Is this regarding item, etc. images?

ScuffedNewt commented 1 month ago

yep!

itinerare commented 1 month ago

Gotcha. Makes sense to me, then.

SpeedyD commented 1 month 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 1 month 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 1 month 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 1 month 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. :)