Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 46 additions & 54 deletions public/app.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,47 @@
var app = angular.module('prerender-tutorial', ['ngRoute'])
.config(function($routeProvider, $locationProvider){
$routeProvider.when('/', {
templateUrl : 'views/homeView.html',
controller: 'homeController'
})

$routeProvider.when('/about', {
templateUrl : '/views/aboutView.html',
controller: 'aboutController'
})

$routeProvider.when('/features', {
templateUrl : '/views/featuresView.html',
controller : 'featuresController'
})

$routeProvider.otherwise({
redirectTo : '/'
});

$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
angular
.module('prerender-tutorial', ['ngRoute'])
.config(function($routeProvider, $locationProvider){
$routeProvider
.when('/', {
name: 'base',
templateUrl: 'views/homeView.html'
})
.when('/about', {
name: 'about',
templateUrl: '/views/aboutView.html'
})
.when('/features', {
name: 'features',
templateUrl: '/views/featuresView.html'
})
.otherwise({
redirectTo: '/'
});

$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
})
.run(function($rootScope){
const pageMeta = {
base: {
pageTitle : 'AngularJS SEO Tutorial',
pageDescripton: 'Welcome to our tutorial on getting your AngularJS websites and apps indexed by Google.'
},
about: {
pageTitle : 'About',
pageDescripton: 'We are a content heavy website so we need to be indexed.'
},
features: {
pageTitle : 'Features',
pageDescripton: 'Check out some of our awesome features!'
}
};

$rootScope.$on('$routeChangeSuccess', function(event, current, previous){
const route = current.$$route.name;
const pageInfo = pageMeta[route] || pageMeta.base;

$rootScope.pageTitle = pageInfo.pageTitle;
$rootScope.pageDescription = pageInfo.pageDescription;
});
});

function mainController($scope) {
// We will create an seo variable on the scope and decide which fields we want to populate
$scope.seo = {
pageTitle : '',
pageDescription : ''
};
}

function homeController($scope) {
// For this tutorial, we will simply access the $scope.seo variable from the main controller and fill it with content.
// Additionally you can create a service to update the SEO variables - but that's for another tutorial.
$scope.$parent.seo = {
pageTitle : 'AngularJS SEO Tutorial',
pageDescripton: 'Welcome to our tutorial on getting your AngularJS websites and apps indexed by Google.'
};
}

function aboutController($scope) {
$scope.$parent.seo = {
pageTitle : 'About',
pageDescripton: 'We are a content heavy website so we need to be indexed.'
};
}

function featuresController($scope) {
$scope.$parent.seo = {
pageTitle : 'Features',
pageDescripton: 'Check out some of our awesome features!'
};
}
73 changes: 35 additions & 38 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
<!doctype html>
<!DOCTYPE html>
<!-- We will create a mainController and bind it to HTML which will give us access to the entire DOM -->
<html ng-app="prerender-tutorial" ng-controller="mainController">
<head>
<html ng-app="prerender-tutorial">
<head>

<!-- We define the SEO variables we want to dynamically update -->
<title>Scotch Tutorial | {{ seo.pageTitle }}</title>
<meta name="description" content="{{ seo.metaDescription }}">
<!-- We define the SEO variables we want to dynamically update -->
<title>Scotch Tutorial | {{ $root.pageTitle }}</title>
<meta name="description" content="{{ $root.metaDescription }}">

<!-- CSS-->
<link rel="stylesheet" type="text/css" href="/assets/bootstrap.min.css">
<style>
body { margin-top:60px; }
</style>
<!-- CSS-->
<link rel="stylesheet" type="text/css" href="/assets/bootstrap.min.css">
<style>body { margin-top:60px; }</style>

<!-- JS -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.10/angular-route.min.js"></script>
<script src="/app.js"></script>
<script>
// Including this code will ensure that the page is not rendered until all JavaScript has finished executing
window.prerenderReady = false;
</script>
<!-- JS -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.10/angular-route.min.js"></script>
<script src="/app.js"></script>
<script>
// Including this code will ensure that the page is not rendered until all JavaScript has finished executing
window.prerenderReady = false;
</script>
</head>
<body>
<div class="container">
<div class="container">

<!-- NAVIGATION BAR -->
<div class="bs-example bs-navbar-top-example">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<a class="navbar-brand" href="/">Angular SEO Prerender Tutorial</a>
</div>
<!-- NAVIGATION BAR -->
<div class="bs-example bs-navbar-top-example">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<a class="navbar-brand" href="/">Angular SEO Prerender Tutorial</a>
</div>

<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/features">Features</a></li>
</ul>
</nav>
</div>
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/features">Features</a></li>
</ul>
</nav>
</div>

<h1 class="text-center">Welcome to the Angular SEO Prerender Tutorial</h1>
<!-- where we will inject our template data -->
<div ng-view></div>

</div>
<h1 class="text-center">Welcome to the Angular SEO Prerender Tutorial</h1>
<!-- where we will inject our template data -->
<div ng-view></div>
</div>
</body>
</html>