From 1405ad7d317f59478fa84437329c0203911581ab Mon Sep 17 00:00:00 2001 From: Adam Lavin Date: Thu, 17 Dec 2015 00:14:46 +0000 Subject: [PATCH] Proof-of-concept for SEO meta updates in angular #27 --- resources/assets/scripts/app/app.coffee | 8 ++++++++ resources/assets/scripts/app/controllers/album.coffee | 5 +++-- resources/assets/scripts/app/controllers/playlist.coffee | 5 +++-- resources/assets/scripts/app/controllers/track.coffee | 5 +++-- resources/views/shared/_layout.blade.php | 6 +++--- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/resources/assets/scripts/app/app.coffee b/resources/assets/scripts/app/app.coffee index f9c891ea..15de84a4 100644 --- a/resources/assets/scripts/app/app.coffee +++ b/resources/assets/scripts/app/app.coffee @@ -25,6 +25,13 @@ if window.pfm.environment == 'production' analytics.init() ] +module.run [ + '$rootScope', + ($rootScope) -> + $rootScope.$on '$stateChangeStart', (event, toState, toParams, fromState, fromParams) -> + $rootScope.description = '' +] + module.config [ '$locationProvider', '$stateProvider', '$dialogProvider', 'AngularyticsProvider', '$httpProvider', '$sceDelegateProvider' (location, state, $dialogProvider, analytics, $httpProvider, $sceDelegateProvider) -> @@ -283,4 +290,5 @@ module.config [ $dialogProvider.options dialogFade: true backdropClick: false + ] diff --git a/resources/assets/scripts/app/controllers/album.coffee b/resources/assets/scripts/app/controllers/album.coffee index 8c816d91..387a2bd9 100644 --- a/resources/assets/scripts/app/controllers/album.coffee +++ b/resources/assets/scripts/app/controllers/album.coffee @@ -21,13 +21,14 @@ window.pfm.preloaders['album'] = [ ] angular.module('ponyfm').controller "album", [ - '$scope', 'albums', '$state', 'playlists', 'auth', '$dialog', 'download-cached', '$window', '$timeout' - ($scope, albums, $state, playlists, auth, $dialog, cachedAlbum, $window, $timeout) -> + '$scope', '$rootScope', 'albums', '$state', 'playlists', 'auth', '$dialog', 'download-cached', '$window', '$timeout' + ($scope, $rootScope, 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." $scope.playlists = [] diff --git a/resources/assets/scripts/app/controllers/playlist.coffee b/resources/assets/scripts/app/controllers/playlist.coffee index c2ab3e2b..c2b252c6 100644 --- a/resources/assets/scripts/app/controllers/playlist.coffee +++ b/resources/assets/scripts/app/controllers/playlist.coffee @@ -21,13 +21,14 @@ window.pfm.preloaders['playlist'] = [ ] angular.module('ponyfm').controller 'playlist', [ - '$scope', '$state', 'playlists', '$dialog', 'download-cached', '$window', '$timeout' - ($scope, $state, playlists, $dialog, cachedPlaylist, $window, $timeout) -> + '$scope', '$rootScope', '$state', 'playlists', '$dialog', 'download-cached', '$window', '$timeout' + ($scope, $rootScope, $state, playlists, $dialog, cachedPlaylist, $window, $timeout) -> playlist = null playlists.fetch($state.params.id).done (playlistResponse) -> $scope.playlist = playlistResponse playlist = playlistResponse + #$rootScope.description = "Listen to #{track.title} by #{track.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 b6112214..9393df1f 100644 --- a/resources/assets/scripts/app/controllers/track.coffee +++ b/resources/assets/scripts/app/controllers/track.coffee @@ -21,13 +21,14 @@ window.pfm.preloaders['track'] = [ ] angular.module('ponyfm').controller "track", [ - '$scope', 'tracks', '$state', 'playlists', 'auth', 'favourites', '$dialog', 'download-cached', '$window', '$timeout' - ($scope, tracks, $state, playlists, auth, favourites, $dialog, cachedTrack, $window, $timeout) -> + '$scope', '$rootScope', 'tracks', '$state', 'playlists', 'auth', 'favourites', '$dialog', 'download-cached', '$window', '$timeout' + ($scope, $rootScope, tracks, $state, playlists, auth, favourites, $dialog, cachedTrack, $window, $timeout) -> track = null tracks.fetch($state.params.id).done (trackResponse) -> $scope.track = trackResponse.track track = trackResponse.track + $rootScope.description = "Listen to #{track.title} by #{track.user.name} on the largest pony music site" $scope.playlists = [] diff --git a/resources/views/shared/_layout.blade.php b/resources/views/shared/_layout.blade.php index f69e5ef3..745fa951 100644 --- a/resources/views/shared/_layout.blade.php +++ b/resources/views/shared/_layout.blade.php @@ -15,18 +15,18 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . --}} - + Pony.fm - + @yield('styles') - + @yield('content') @yield('scripts')