From 5d70fc9fd11b7245efc0aa81c98cd6c3aa6a5322 Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Tue, 15 Mar 2016 21:37:17 -0700 Subject: [PATCH] #27: Improved title tags; added a "meta" service for managing them and meta descriptions. --- resources/assets/scripts/app/app.coffee | 6 ++-- .../scripts/app/controllers/album.coffee | 7 ++-- .../scripts/app/controllers/dashboard.coffee | 1 + .../scripts/app/controllers/home.coffee | 6 ++-- .../scripts/app/controllers/playlist.coffee | 7 ++-- .../scripts/app/controllers/track.coffee | 7 ++-- .../scripts/app/controllers/tracks.coffee | 6 ++-- .../assets/scripts/app/services/meta.coffee | 32 +++++++++++++++++++ resources/views/shared/_layout.blade.php | 2 +- 9 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 resources/assets/scripts/app/services/meta.coffee diff --git a/resources/assets/scripts/app/app.coffee b/resources/assets/scripts/app/app.coffee index dc5beecb..42c4324d 100644 --- a/resources/assets/scripts/app/app.coffee +++ b/resources/assets/scripts/app/app.coffee @@ -70,10 +70,10 @@ if window.pfm.environment == 'production' ] ponyfm.run [ - '$rootScope', - ($rootScope) -> + '$rootScope', 'meta', + ($rootScope, meta) -> $rootScope.$on '$stateChangeStart', (event, toState, toParams, fromState, fromParams) -> - $rootScope.description = '' + meta.reset() ] ponyfm.config [ diff --git a/resources/assets/scripts/app/controllers/album.coffee b/resources/assets/scripts/app/controllers/album.coffee index 122ef367..aaa92235 100644 --- a/resources/assets/scripts/app/controllers/album.coffee +++ b/resources/assets/scripts/app/controllers/album.coffee @@ -21,14 +21,15 @@ window.pfm.preloaders['album'] = [ ] module.exports = angular.module('ponyfm').controller "album", [ - '$scope', '$rootScope', 'albums', '$state', 'playlists', 'auth', '$dialog', 'download-cached', '$window', '$timeout' - ($scope, $rootScope, albums, $state, playlists, auth, $dialog, cachedAlbum, $window, $timeout) -> + '$scope', 'meta', 'albums', '$state', 'playlists', 'auth', '$dialog', 'download-cached', '$window', '$timeout' + ($scope, meta, albums, $state, playlists, auth, $dialog, cachedAlbum, $window, $timeout) -> album = null albums.fetch($state.params.id).done (albumResponse) -> $scope.album = albumResponse.album album = albumResponse.album - $rootScope.description = "Listen to #{album.title}, the album by #{album.user.name}, and more on the largest pony music site." + meta.setTitle("#{album.title} | #{album.user.name}") + meta.setDescription("Listen to #{album.title}, the album by #{album.user.name}, and more on the largest pony music site.") $scope.playlists = [] diff --git a/resources/assets/scripts/app/controllers/dashboard.coffee b/resources/assets/scripts/app/controllers/dashboard.coffee index e4f8246c..2ed5567c 100644 --- a/resources/assets/scripts/app/controllers/dashboard.coffee +++ b/resources/assets/scripts/app/controllers/dashboard.coffee @@ -22,6 +22,7 @@ window.pfm.preloaders['dashboard'] = [ module.exports = angular.module('ponyfm').controller "dashboard", [ '$scope', 'dashboard', 'auth', '$http' ($scope, dashboard, auth, $http) -> + $scope.recentTracks = null $scope.popularTracks = null diff --git a/resources/assets/scripts/app/controllers/home.coffee b/resources/assets/scripts/app/controllers/home.coffee index 31367d43..c375384f 100644 --- a/resources/assets/scripts/app/controllers/home.coffee +++ b/resources/assets/scripts/app/controllers/home.coffee @@ -20,8 +20,10 @@ window.pfm.preloaders['home'] = [ ] module.exports = angular.module('ponyfm').controller "home", [ - '$scope', 'dashboard' - ($scope, dashboard) -> + '$scope', 'meta', 'dashboard' + ($scope, meta, dashboard) -> + meta.reset() + $scope.recentTracks = null $scope.popularTracks = null diff --git a/resources/assets/scripts/app/controllers/playlist.coffee b/resources/assets/scripts/app/controllers/playlist.coffee index d14cc496..1d1c1c0a 100644 --- a/resources/assets/scripts/app/controllers/playlist.coffee +++ b/resources/assets/scripts/app/controllers/playlist.coffee @@ -21,14 +21,15 @@ window.pfm.preloaders['playlist'] = [ ] module.exports = angular.module('ponyfm').controller 'playlist', [ - '$scope', '$rootScope', '$state', 'playlists', '$dialog', 'download-cached', '$window', '$timeout' - ($scope, $rootScope, $state, playlists, $dialog, cachedPlaylist, $window, $timeout) -> + '$scope', 'meta', '$state', 'playlists', '$dialog', 'download-cached', '$window', '$timeout' + ($scope, meta, $state, playlists, $dialog, cachedPlaylist, $window, $timeout) -> playlist = null playlists.fetch($state.params.id).done (playlistResponse) -> $scope.playlist = playlistResponse playlist = playlistResponse - $rootScope.description = "Listen to #{playlist.title} by #{playlist.user.name} on the largest pony music site" + meta.setTitle("#{playlist.title} | #{playlist.user.name}") + meta.setDescription("Listen to \"#{playlist.title}\", a playlist by #{playlist.user.name}, on the largest pony music site.") $scope.share = () -> dialog = $dialog.dialog diff --git a/resources/assets/scripts/app/controllers/track.coffee b/resources/assets/scripts/app/controllers/track.coffee index 8344a6a7..8092a690 100644 --- a/resources/assets/scripts/app/controllers/track.coffee +++ b/resources/assets/scripts/app/controllers/track.coffee @@ -15,15 +15,16 @@ # along with this program. If not, see . module.exports = angular.module('ponyfm').controller "track", [ - '$scope', '$rootScope', 'tracks', '$state', 'playlists', 'auth', 'favourites', '$dialog', 'download-cached', '$window', '$timeout' - ($scope, $rootScope, tracks, $state, playlists, auth, favourites, $dialog, cachedTrack, $window, $timeout) -> + '$scope', 'meta', 'tracks', '$state', 'playlists', 'auth', 'favourites', '$dialog', 'download-cached', '$window', '$timeout' + ($scope, meta, tracks, $state, playlists, auth, favourites, $dialog, cachedTrack, $window, $timeout) -> $scope.track $scope.trackId = parseInt($state.params.id) updateTrackData = (forceUpdate = false) -> tracks.fetch($scope.trackId, forceUpdate).done (trackResponse) -> $scope.track = trackResponse.track - $rootScope.description = "Listen to #{$scope.track.title} by #{$scope.track.user.name} on the largest pony music site" + meta.setTitle("#{$scope.track.title} | #{$scope.track.user.name}") + meta.setDescription("Listen to \"#{$scope.track.title}\" by #{$scope.track.user.name} on the largest pony music site.") updateTrackData() diff --git a/resources/assets/scripts/app/controllers/tracks.coffee b/resources/assets/scripts/app/controllers/tracks.coffee index 3a95bd74..cef0c86e 100644 --- a/resources/assets/scripts/app/controllers/tracks.coffee +++ b/resources/assets/scripts/app/controllers/tracks.coffee @@ -21,8 +21,10 @@ window.pfm.preloaders['tracks'] = [ ] module.exports = angular.module('ponyfm').controller "tracks", [ - '$scope', 'tracks', '$state', 'focus' - ($scope, tracks, $state, focus) -> + '$scope', 'tracks', '$state', 'focus', 'meta' + ($scope, tracks, $state, focus, meta) -> + meta.setTitle('Browse Tracks') + $scope.recentTracks = null $scope.query = tracks.mainQuery $scope.filters = tracks.filters diff --git a/resources/assets/scripts/app/services/meta.coffee b/resources/assets/scripts/app/services/meta.coffee new file mode 100644 index 00000000..4fa5f4f6 --- /dev/null +++ b/resources/assets/scripts/app/services/meta.coffee @@ -0,0 +1,32 @@ +# Pony.fm - A community for pony fan music. +# Copyright (C) 2016 Peter Deltchev +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +module.exports = angular.module('ponyfm').factory('meta', [ + '$rootScope' + ($rootScope) -> + self = + reset: () -> + this.setTitle('Pony.fm - Unlimited Pony Music Hosting', false) + this.setDescription('Pony.fm is the world\'s largest collection of My Little Pony fan music. Enjoy unlimited uploads, streaming, and downloads!') + + setTitle: (title, withSuffix=true) -> + $rootScope.title = title + if withSuffix + $rootScope.title += ' - Pony.fm' + + setDescription: (description) -> + $rootScope.description = description +]) diff --git a/resources/views/shared/_layout.blade.php b/resources/views/shared/_layout.blade.php index 745fa951..5db85b13 100644 --- a/resources/views/shared/_layout.blade.php +++ b/resources/views/shared/_layout.blade.php @@ -19,7 +19,7 @@ - Pony.fm + Pony.fm