Dan Brown

Added custom meta titles to many pages. Closes #30.

...@@ -97,19 +97,30 @@ abstract class Entity extends Model ...@@ -97,19 +97,30 @@ abstract class Entity extends Model
97 */ 97 */
98 public static function isA($type) 98 public static function isA($type)
99 { 99 {
100 - return static::getName() === strtolower($type); 100 + return static::getClassName() === strtolower($type);
101 } 101 }
102 102
103 /** 103 /**
104 * Gets the class name. 104 * Gets the class name.
105 * @return string 105 * @return string
106 */ 106 */
107 - public static function getName() 107 + public static function getClassName()
108 { 108 {
109 return strtolower(array_slice(explode('\\', static::class), -1, 1)[0]); 109 return strtolower(array_slice(explode('\\', static::class), -1, 1)[0]);
110 } 110 }
111 111
112 /** 112 /**
113 + *Gets a limited-length version of the entities name.
114 + * @param int $length
115 + * @return string
116 + */
117 + public function getShortName($length = 25)
118 + {
119 + if(strlen($this->name) <= $length) return $this->name;
120 + return substr($this->name, 0, $length-3) . '...';
121 + }
122 +
123 + /**
113 * Perform a full-text search on this entity. 124 * Perform a full-text search on this entity.
114 * @param string[] $fieldsToSearch 125 * @param string[] $fieldsToSearch
115 * @param string[] $terms 126 * @param string[] $terms
......
...@@ -44,6 +44,7 @@ class BookController extends Controller ...@@ -44,6 +44,7 @@ class BookController extends Controller
44 $books = $this->bookRepo->getAllPaginated(10); 44 $books = $this->bookRepo->getAllPaginated(10);
45 $recents = $this->signedIn ? $this->bookRepo->getRecentlyViewed(4, 0) : false; 45 $recents = $this->signedIn ? $this->bookRepo->getRecentlyViewed(4, 0) : false;
46 $popular = $this->bookRepo->getPopular(4, 0); 46 $popular = $this->bookRepo->getPopular(4, 0);
47 + $this->setPageTitle('Books');
47 return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular]); 48 return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular]);
48 } 49 }
49 50
...@@ -55,6 +56,7 @@ class BookController extends Controller ...@@ -55,6 +56,7 @@ class BookController extends Controller
55 public function create() 56 public function create()
56 { 57 {
57 $this->checkPermission('book-create'); 58 $this->checkPermission('book-create');
59 + $this->setPageTitle('Create New Book');
58 return view('books/create'); 60 return view('books/create');
59 } 61 }
60 62
...@@ -89,8 +91,9 @@ class BookController extends Controller ...@@ -89,8 +91,9 @@ class BookController extends Controller
89 public function show($slug) 91 public function show($slug)
90 { 92 {
91 $book = $this->bookRepo->getBySlug($slug); 93 $book = $this->bookRepo->getBySlug($slug);
92 - Views::add($book);
93 $bookChildren = $this->bookRepo->getChildren($book); 94 $bookChildren = $this->bookRepo->getChildren($book);
95 + Views::add($book);
96 + $this->setPageTitle($book->getShortName());
94 return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]); 97 return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]);
95 } 98 }
96 99
...@@ -104,6 +107,7 @@ class BookController extends Controller ...@@ -104,6 +107,7 @@ class BookController extends Controller
104 { 107 {
105 $this->checkPermission('book-update'); 108 $this->checkPermission('book-update');
106 $book = $this->bookRepo->getBySlug($slug); 109 $book = $this->bookRepo->getBySlug($slug);
110 + $this->setPageTitle('Edit Book ' . $book->getShortName());
107 return view('books/edit', ['book' => $book, 'current' => $book]); 111 return view('books/edit', ['book' => $book, 'current' => $book]);
108 } 112 }
109 113
...@@ -139,6 +143,7 @@ class BookController extends Controller ...@@ -139,6 +143,7 @@ class BookController extends Controller
139 { 143 {
140 $this->checkPermission('book-delete'); 144 $this->checkPermission('book-delete');
141 $book = $this->bookRepo->getBySlug($bookSlug); 145 $book = $this->bookRepo->getBySlug($bookSlug);
146 + $this->setPageTitle('Delete Book ' . $book->getShortName());
142 return view('books/delete', ['book' => $book, 'current' => $book]); 147 return view('books/delete', ['book' => $book, 'current' => $book]);
143 } 148 }
144 149
...@@ -153,9 +158,16 @@ class BookController extends Controller ...@@ -153,9 +158,16 @@ class BookController extends Controller
153 $book = $this->bookRepo->getBySlug($bookSlug); 158 $book = $this->bookRepo->getBySlug($bookSlug);
154 $bookChildren = $this->bookRepo->getChildren($book); 159 $bookChildren = $this->bookRepo->getChildren($book);
155 $books = $this->bookRepo->getAll(); 160 $books = $this->bookRepo->getAll();
161 + $this->setPageTitle('Sort Book ' . $book->getShortName());
156 return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]); 162 return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]);
157 } 163 }
158 164
165 + /**
166 + * Shows the sort box for a single book.
167 + * Used via AJAX when loading in extra books to a sort.
168 + * @param $bookSlug
169 + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
170 + */
159 public function getSortItem($bookSlug) 171 public function getSortItem($bookSlug)
160 { 172 {
161 $book = $this->bookRepo->getBySlug($bookSlug); 173 $book = $this->bookRepo->getBySlug($bookSlug);
......
...@@ -40,6 +40,7 @@ class ChapterController extends Controller ...@@ -40,6 +40,7 @@ class ChapterController extends Controller
40 { 40 {
41 $this->checkPermission('chapter-create'); 41 $this->checkPermission('chapter-create');
42 $book = $this->bookRepo->getBySlug($bookSlug); 42 $book = $this->bookRepo->getBySlug($bookSlug);
43 + $this->setPageTitle('Create New Chapter');
43 return view('chapters/create', ['book' => $book, 'current' => $book]); 44 return view('chapters/create', ['book' => $book, 'current' => $book]);
44 } 45 }
45 46
...@@ -79,6 +80,7 @@ class ChapterController extends Controller ...@@ -79,6 +80,7 @@ class ChapterController extends Controller
79 $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id); 80 $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
80 $sidebarTree = $this->bookRepo->getChildren($book); 81 $sidebarTree = $this->bookRepo->getChildren($book);
81 Views::add($chapter); 82 Views::add($chapter);
83 + $this->setPageTitle($chapter->getShortName());
82 return view('chapters/show', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter, 'sidebarTree' => $sidebarTree]); 84 return view('chapters/show', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter, 'sidebarTree' => $sidebarTree]);
83 } 85 }
84 86
...@@ -93,6 +95,7 @@ class ChapterController extends Controller ...@@ -93,6 +95,7 @@ class ChapterController extends Controller
93 $this->checkPermission('chapter-update'); 95 $this->checkPermission('chapter-update');
94 $book = $this->bookRepo->getBySlug($bookSlug); 96 $book = $this->bookRepo->getBySlug($bookSlug);
95 $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id); 97 $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
98 + $this->setPageTitle('Edit Chapter' . $chapter->getShortName());
96 return view('chapters/edit', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]); 99 return view('chapters/edit', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]);
97 } 100 }
98 101
...@@ -127,6 +130,7 @@ class ChapterController extends Controller ...@@ -127,6 +130,7 @@ class ChapterController extends Controller
127 $this->checkPermission('chapter-delete'); 130 $this->checkPermission('chapter-delete');
128 $book = $this->bookRepo->getBySlug($bookSlug); 131 $book = $this->bookRepo->getBySlug($bookSlug);
129 $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id); 132 $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
133 + $this->setPageTitle('Delete Chapter' . $chapter->getShortName());
130 return view('chapters/delete', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]); 134 return view('chapters/delete', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]);
131 } 135 }
132 136
......
...@@ -43,6 +43,15 @@ abstract class Controller extends BaseController ...@@ -43,6 +43,15 @@ abstract class Controller extends BaseController
43 } 43 }
44 44
45 /** 45 /**
46 + * Adds the page title into the view.
47 + * @param $title
48 + */
49 + public function setPageTitle($title)
50 + {
51 + view()->share('pageTitle', $title);
52 + }
53 +
54 + /**
46 * Checks for a permission. 55 * Checks for a permission.
47 * 56 *
48 * @param $permissionName 57 * @param $permissionName
......
...@@ -46,6 +46,7 @@ class PageController extends Controller ...@@ -46,6 +46,7 @@ class PageController extends Controller
46 $this->checkPermission('page-create'); 46 $this->checkPermission('page-create');
47 $book = $this->bookRepo->getBySlug($bookSlug); 47 $book = $this->bookRepo->getBySlug($bookSlug);
48 $chapter = $chapterSlug ? $this->chapterRepo->getBySlug($chapterSlug, $book->id) : false; 48 $chapter = $chapterSlug ? $this->chapterRepo->getBySlug($chapterSlug, $book->id) : false;
49 + $this->setPageTitle('Create New Page');
49 return view('pages/create', ['book' => $book, 'chapter' => $chapter]); 50 return view('pages/create', ['book' => $book, 'chapter' => $chapter]);
50 } 51 }
51 52
...@@ -89,6 +90,7 @@ class PageController extends Controller ...@@ -89,6 +90,7 @@ class PageController extends Controller
89 $page = $this->pageRepo->getBySlug($pageSlug, $book->id); 90 $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
90 $sidebarTree = $this->bookRepo->getChildren($book); 91 $sidebarTree = $this->bookRepo->getChildren($book);
91 Views::add($page); 92 Views::add($page);
93 + $this->setPageTitle($page->getShortName());
92 return view('pages/show', ['page' => $page, 'book' => $book, 'current' => $page, 'sidebarTree' => $sidebarTree]); 94 return view('pages/show', ['page' => $page, 'book' => $book, 'current' => $page, 'sidebarTree' => $sidebarTree]);
93 } 95 }
94 96
...@@ -104,6 +106,7 @@ class PageController extends Controller ...@@ -104,6 +106,7 @@ class PageController extends Controller
104 $this->checkPermission('page-update'); 106 $this->checkPermission('page-update');
105 $book = $this->bookRepo->getBySlug($bookSlug); 107 $book = $this->bookRepo->getBySlug($bookSlug);
106 $page = $this->pageRepo->getBySlug($pageSlug, $book->id); 108 $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
109 + $this->setPageTitle('Editing Page ' . $page->getShortName());
107 return view('pages/edit', ['page' => $page, 'book' => $book, 'current' => $page]); 110 return view('pages/edit', ['page' => $page, 'book' => $book, 'current' => $page]);
108 } 111 }
109 112
...@@ -148,6 +151,7 @@ class PageController extends Controller ...@@ -148,6 +151,7 @@ class PageController extends Controller
148 $this->checkPermission('page-delete'); 151 $this->checkPermission('page-delete');
149 $book = $this->bookRepo->getBySlug($bookSlug); 152 $book = $this->bookRepo->getBySlug($bookSlug);
150 $page = $this->pageRepo->getBySlug($pageSlug, $book->id); 153 $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
154 + $this->setPageTitle('Delete Page ' . $page->getShortName());
151 return view('pages/delete', ['book' => $book, 'page' => $page, 'current' => $page]); 155 return view('pages/delete', ['book' => $book, 'page' => $page, 'current' => $page]);
152 } 156 }
153 157
...@@ -179,6 +183,7 @@ class PageController extends Controller ...@@ -179,6 +183,7 @@ class PageController extends Controller
179 { 183 {
180 $book = $this->bookRepo->getBySlug($bookSlug); 184 $book = $this->bookRepo->getBySlug($bookSlug);
181 $page = $this->pageRepo->getBySlug($pageSlug, $book->id); 185 $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
186 + $this->setPageTitle('Revisions For ' . $page->getShortName());
182 return view('pages/revisions', ['page' => $page, 'book' => $book, 'current' => $page]); 187 return view('pages/revisions', ['page' => $page, 'book' => $book, 'current' => $page]);
183 } 188 }
184 189
...@@ -195,6 +200,7 @@ class PageController extends Controller ...@@ -195,6 +200,7 @@ class PageController extends Controller
195 $page = $this->pageRepo->getBySlug($pageSlug, $book->id); 200 $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
196 $revision = $this->pageRepo->getRevisionById($revisionId); 201 $revision = $this->pageRepo->getRevisionById($revisionId);
197 $page->fill($revision->toArray()); 202 $page->fill($revision->toArray());
203 + $this->setPageTitle('Page Revision For ' . $page->getShortName());
198 return view('pages/revision', ['page' => $page, 'book' => $book]); 204 return view('pages/revision', ['page' => $page, 'book' => $book]);
199 } 205 }
200 206
......
...@@ -45,6 +45,7 @@ class SearchController extends Controller ...@@ -45,6 +45,7 @@ class SearchController extends Controller
45 $pages = $this->pageRepo->getBySearch($searchTerm); 45 $pages = $this->pageRepo->getBySearch($searchTerm);
46 $books = $this->bookRepo->getBySearch($searchTerm); 46 $books = $this->bookRepo->getBySearch($searchTerm);
47 $chapters = $this->chapterRepo->getBySearch($searchTerm); 47 $chapters = $this->chapterRepo->getBySearch($searchTerm);
48 + $this->setPageTitle('Search For ' . $searchTerm);
48 return view('search/all', ['pages' => $pages, 'books' => $books, 'chapters' => $chapters, 'searchTerm' => $searchTerm]); 49 return view('search/all', ['pages' => $pages, 'books' => $books, 'chapters' => $chapters, 'searchTerm' => $searchTerm]);
49 } 50 }
50 51
......
...@@ -18,6 +18,7 @@ class SettingController extends Controller ...@@ -18,6 +18,7 @@ class SettingController extends Controller
18 public function index() 18 public function index()
19 { 19 {
20 $this->checkPermission('settings-update'); 20 $this->checkPermission('settings-update');
21 + $this->setPageTitle('Settings');
21 return view('settings/index'); 22 return view('settings/index');
22 } 23 }
23 24
......
...@@ -35,6 +35,7 @@ class UserController extends Controller ...@@ -35,6 +35,7 @@ class UserController extends Controller
35 public function index() 35 public function index()
36 { 36 {
37 $users = $this->user->all(); 37 $users = $this->user->all();
38 + $this->setPageTitle('Users');
38 return view('users/index', ['users' => $users]); 39 return view('users/index', ['users' => $users]);
39 } 40 }
40 41
...@@ -90,6 +91,7 @@ class UserController extends Controller ...@@ -90,6 +91,7 @@ class UserController extends Controller
90 91
91 $user = $this->user->findOrFail($id); 92 $user = $this->user->findOrFail($id);
92 $activeSocialDrivers = $socialAuthService->getActiveDrivers(); 93 $activeSocialDrivers = $socialAuthService->getActiveDrivers();
94 + $this->setPageTitle('User Profile');
93 return view('users/edit', ['user' => $user, 'activeSocialDrivers' => $activeSocialDrivers]); 95 return view('users/edit', ['user' => $user, 'activeSocialDrivers' => $activeSocialDrivers]);
94 } 96 }
95 97
...@@ -139,6 +141,7 @@ class UserController extends Controller ...@@ -139,6 +141,7 @@ class UserController extends Controller
139 return $this->currentUser->id == $id; 141 return $this->currentUser->id == $id;
140 }); 142 });
141 $user = $this->user->findOrFail($id); 143 $user = $this->user->findOrFail($id);
144 + $this->setPageTitle('Delete User ' . $user->name);
142 return view('users/delete', ['user' => $user]); 145 return view('users/delete', ['user' => $user]);
143 } 146 }
144 147
......
...@@ -32,7 +32,6 @@ class Page extends Entity ...@@ -32,7 +32,6 @@ class Page extends Entity
32 return $this->chapter()->count() > 0; 32 return $this->chapter()->count() > 0;
33 } 33 }
34 34
35 -
36 public function revisions() 35 public function revisions()
37 { 36 {
38 return $this->hasMany('BookStack\PageRevision')->orderBy('created_at', 'desc'); 37 return $this->hasMany('BookStack\PageRevision')->orderBy('created_at', 'desc');
...@@ -40,7 +39,6 @@ class Page extends Entity ...@@ -40,7 +39,6 @@ class Page extends Entity
40 39
41 public function getUrl() 40 public function getUrl()
42 { 41 {
43 - // TODO - Extract this and share with chapters
44 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug; 42 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
45 return '/books/' . $bookSlug . '/page/' . $this->slug; 43 return '/books/' . $bookSlug . '/page/' . $this->slug;
46 } 44 }
......
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 - <title>BookStack</title> 4 + <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ Setting::get('app-name', 'BookStack') }}</title>
5 5
6 <!-- Meta --> 6 <!-- Meta -->
7 <meta name="viewport" content="width=device-width"> 7 <meta name="viewport" content="width=device-width">
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 <h3 class="text-book"><i class="zmdi zmdi-book"></i>{{ $book->name }}</h3> 2 <h3 class="text-book"><i class="zmdi zmdi-book"></i>{{ $book->name }}</h3>
3 <ul class="sortable-page-list sort-list"> 3 <ul class="sortable-page-list sort-list">
4 @foreach($bookChildren as $bookChild) 4 @foreach($bookChildren as $bookChild)
5 - <li data-id="{{$bookChild->id}}" data-type="{{ $bookChild->getName() }}" class="text-{{ $bookChild->getName() }}"> 5 + <li data-id="{{$bookChild->id}}" data-type="{{ $bookChild->getClassName() }}" class="text-{{ $bookChild->getClassName() }}">
6 <i class="zmdi {{ $bookChild->isA('chapter') ? 'zmdi-collection-bookmark':'zmdi-file-text'}}"></i>{{ $bookChild->name }} 6 <i class="zmdi {{ $bookChild->isA('chapter') ? 'zmdi-collection-bookmark':'zmdi-file-text'}}"></i>{{ $bookChild->name }}
7 @if($bookChild->isA('chapter')) 7 @if($bookChild->isA('chapter'))
8 <ul> 8 <ul>
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
7 <div class="row"> 7 <div class="row">
8 <div class="col-sm-6 faded"> 8 <div class="col-sm-6 faded">
9 <div class="breadcrumbs"> 9 <div class="breadcrumbs">
10 - <a href="{{$book->getUrl()}}" class="text-book text-button"><i class="zmdi zmdi-book"></i>{{ $book->name }}</a> 10 + <a href="{{$book->getUrl()}}" class="text-book text-button"><i class="zmdi zmdi-book"></i>{{ $book->getShortName() }}</a>
11 @if($page->hasChapter()) 11 @if($page->hasChapter())
12 <span class="sep">&raquo;</span> 12 <span class="sep">&raquo;</span>
13 <a href="{{ $page->chapter->getUrl() }}" class="text-chapter text-button"> 13 <a href="{{ $page->chapter->getUrl() }}" class="text-chapter text-button">
14 <i class="zmdi zmdi-collection-bookmark"></i> 14 <i class="zmdi zmdi-collection-bookmark"></i>
15 - {{$page->chapter->name}} 15 + {{$page->chapter->getShortName()}}
16 </a> 16 </a>
17 @endif 17 @endif
18 </div> 18 </div>
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
6 6
7 7
8 @foreach($sidebarTree as $bookChild) 8 @foreach($sidebarTree as $bookChild)
9 - <li class="list-item-{{ $bookChild->getName() }} {{ $bookChild->getName() }}"> 9 + <li class="list-item-{{ $bookChild->getClassName() }} {{ $bookChild->getClassName() }}">
10 - <a href="{{$bookChild->getUrl()}}" class="{{ $bookChild->getName() }} {{ $current->matches($bookChild)? 'selected' : '' }}"> 10 + <a href="{{$bookChild->getUrl()}}" class="{{ $bookChild->getClassName() }} {{ $current->matches($bookChild)? 'selected' : '' }}">
11 @if($bookChild->isA('chapter'))<i class="zmdi zmdi-collection-bookmark"></i>@else <i class="zmdi zmdi-file-text"></i>@endif{{ $bookChild->name }} 11 @if($bookChild->isA('chapter'))<i class="zmdi zmdi-collection-bookmark"></i>@else <i class="zmdi zmdi-file-text"></i>@endif{{ $bookChild->name }}
12 </a> 12 </a>
13 13
......