LycheeOrg / Lychee

A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.
https://lycheeorg.github.io/
MIT License
3.42k stars 302 forks source link

Friendly URLs instead of IDs #330

Open garster opened 5 years ago

garster commented 5 years ago

My feature request is similar to or would compliment #308

Previous photo galleries I have used create slugified friendly urls.

For example:

Some Album => www.example.com/some-album Some Album / Sub Album 1 => www.example.com/some-album/sub-album-1 Some Album / I like Cats & Cocktails => www.example.com/some-album/i-like-cats-and-cocktails

This would make sharing and viewing links much more user friendly. I do see now that the album Id is passes in which is very efficient, but with some slight work this would work too. When and album is created or renamed the parent albums could be looked up and the names slugified, path generated, and stored in the DB. Then the lookup could be on that url-slug field instead of the id.

Laravel has a slug helper, but it may not be advanced enough to handle multiple spaces, and special characters. https://laravel.com/docs/5.8/helpers#method-str-slug

There are others on Packagist. I have seen ones that will do stuff like turn & in and and " - " into "-" instead of "---" (like in "Landmark - 25"=> "landmark-25") https://packagist.org/?query=slug

Thanks for hearing my suggestion.

ildyria commented 5 years ago

What happens in case of name collision?

kamil4 commented 5 years ago

Exactly. Albums and photos in Lychee don't need to have unique titles. We could, of course, add code to enforce that they be unique, but still...

I think the easiest way for us to implement something like this would be to add an alias column to the albums table, and allow the use of that alias in addition to the numeric album IDs that we already have. The alias would be provided by the user (same way as title or description; pretty much every character should be fine, including /) and would obviously have to be unique.

ildyria commented 5 years ago

I would like to also bring up the attention with a possible collision with the (not released yet) page module. :)

kamil4 commented 5 years ago

Erm, what is the page module? :smiley:

ildyria commented 5 years ago

Well I guess you were not aware that you could add pages & menu to the landing. 😆 I made it a long time ago to be able to add things like : about, contact, portfolio, or even worse, blog posts...

Route::get('/{page}', 'PageController@page');

https://github.com/LycheeOrg/Lychee-Laravel/blob/master/app/Http/Controllers/PageController.php#L40

public function page(Request $request, $page)
    {
        $page = Page::enabled()->where('link', '/' . $page)->first();
        if ($page == null) {
            abort(404);
        }
        $lang = Lang::get_lang(Configs::get_value('lang'));
        $lang['language'] = Configs::get_value('lang');
        $infos = $this->configFunctions->get_pages_infos();
        $title = Configs::get_value('site_title', Config::get('defines.defaults.SITE_TITLE'));
        $menus = Page::menu()->get();
        $contents = $page->content;
        $page_config = array();
        $page_config['show_hosted_by'] = false;
        $page_config['display_socials'] = false;
        return view('page', ['locale' => $lang, 'title' => $title, 'infos' => $infos, 'menus' => $menus, 'contents' => $contents, 'page_config' => $page_config]);
    }

https://github.com/LycheeOrg/Lychee-Laravel/blob/master/app/Page.php https://github.com/LycheeOrg/Lychee-Laravel/blob/master/app/PageContent.php

quentinsf commented 2 years ago

Picking up an old thread... here's another vote for the idea of an alias that could be used to give a friendly URL to an album.

I'm really liking the look of Lychee and would like to migrate to it from other systems where I have shared URLs like '/Architecture' and '/Haddenham-Steam-Rally' with many others, so I want to keep legacy links working as much as I can, without writing lots and lots of nginx redirects :-)