-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Include chapter name with URL path for pages #497
Comments
Hi @levest28, Thanks for opening this issue/feature request. Reasons For
Reasons Against
|
Good discussion regarding URLs. From UX perspective, URLs should be as short as possible. Therefore having books/mybook/chapter/new/page/three just adds lots of clutter to URLs. I think having URL as simple as: Anyway, this might be another config option to have URL slugs for books, chapters and pages (or not to have them defined at all). |
@ssddanbrown, I know this is a bit of an old thread, but I'd like to +1 @nekromoff's suggestion for pretty, or clean URLs. For example;
As an addition, I think user definable Slugs would be a welcome addition to page options (similar to Page Tags), and maybe even carried over to chapters and shelves, i.e.; Example uses the same 'Current URL' from above...
|
I'd like to add my vote to implementing slugs. It's difficult to link to pages because a page title can change at any time (thus changing the page URL), and also pages with accented characters end up with very ugly URL-s (an issue also mentioned in issue #1765 ). If one could manually set the page slug, this wouldn't be a problem. |
@ssddanbrown Sorry to dig up this old issue, but I have encounter a need for URLs with chapter slugs:
Would it be possible to have the best of both worlds, such as:
|
Hi @rclement, If you needed this ability right now you could use the below using the logical theme system (Video Guide): <?php
use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;
use BookStack\Entities\Repos\ChapterRepo;
use BookStack\Exceptions\NotFoundException;
use Illuminate\Support\Facades\Route;
Theme::listen(ThemeEvents::APP_BOOT, function() {
Route::middleware(['web', 'auth'])->group(function() {
Route::get('/books/{bookSlug}/chapter/{chapterSlug}/page/{pageSlug}', function(ChapterRepo $chapterRepo, string $bookSlug, string $chapterSlug, string $pageSlug) {
$chapter = $chapterRepo->getBySlug($bookSlug, $chapterSlug);
$page = $chapter->pages()->scopes('visible')->where('slug', 'like', $pageSlug . '%')->first();
if (!$page) {
throw new NotFoundException(trans('errors.page_not_found'));
}
return redirect($page->getUrl());
});
});
}); This adds the desired URL endpoint for page-showing, with chapter held within, for example:
This will then run a prefix-match using the url page slug, against the pages within that chapter, then redirect to it's standard URL if such a page is found. Note, since this uses custom internal logic within the logical theme system much of that is technically deemed unstable/not-supported so it's advised to check such customizations upon upgrades. |
Thanks @ssddanbrown for your workaround! After trying your theme customization snippet, I found an issue with the order of middleware execution:
So here is a working snippet in case anyone needs it: <?php
use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;
use BookStack\Entities\Repos\ChapterRepo;
use BookStack\Exceptions\NotFoundException;
use Illuminate\Support\Facades\Route;
Theme::listen(ThemeEvents::APP_BOOT, function() {
Route::middleware(['web', 'auth'])->group(function() {
Route::get('/books/{bookSlug}/chapter/{chapterSlug}/page/{pageSlug}', function(ChapterRepo $chapterRepo, string $bookSlug, string $chapterSlug, string $pageSlug) {
$chapter = $chapterRepo->getBySlug($bookSlug, $chapterSlug);
$page = $chapter->pages()->scopes('visible')->where('slug', 'like', $pageSlug . '%')->first();
if (!$page) {
throw new NotFoundException(trans('errors.page_not_found'));
}
return redirect($page->getUrl());
});
});
}); @ssddanbrown Can you confirm my updated snippet? |
@rclement Yep! Can confirm your updated snippet. Sorry, was testing on a public dev instance when writing out my version, will update my copy to prevent copying of wrong order. |
Any updates on this? We also have a lot of repetition in page names. I think having the option to include the chapter in the URL might be beneficial. |
@martialblog No |
For Feature Requests
Desired Feature: Option to include chapter in URL
For example:
Current URL for Chapter:
https://domain.ca/books/{bookname}/chapter/{chaptername}
Current URL for Page:
https://domain.ca/books/{bookname}/page/{pagename}
Desired URL for Page:
https://domain.ca/books/{bookname}/chapter/{chaptername}/page/{pagename}
Issue:
In current setup, if I have Chapter 1 with a page "About", Chapter 2 also with "About" page is named differently.
It would be better if both chapter can refer to the page name as "About", but include the chapter name in the URL.
For documentation purpose, if we have 100+ chapters, each with an "About" page, it looks pretty messy.
The text was updated successfully, but these errors were encountered: