This is how you handle the google bot and facebook bot.
Inside of where you load middleware
1 | var useragent = require('express-useragent'); |
Inside your main.js
1 | ; |
botservice.js
1 | var page = require('webpage').create(), |
In angular, this is how you can reset the metadata
entry.js1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70angular.module('app').service('PageTitle', function() {
var title,
defaultTitle;
title = defaultTitle = 'Some title';
return {
title: function() {return title; },
setTitle: function(newTitle) { title = newTitle + " - " + defaultTitle }
};
})
.service('MetaInformation', [function() {
var metaDescription,
ogDescription,
defaultMetaDescription,
metaKeywords,
ogImage,
defaultImage,
ogTitle,
defaultTitle;
metaDescription = ogDescription = defaultMetaDescription = 'default meta data description.';
metaKeywords = ' education, information';
ogImage = defaultImage = 'http://company.com/logo.png';
ogTitle = defaultTitle = 'network of tomorrow';
return {
metaDescription: function() { return metaDescription; },
metaKeywords: function() { return metaKeywords; },
ogImage: function() {return ogImage; },
ogTitle: function() {return ogTitle; },
ogDescription: function() {return ogDescription; },
url: function() {return document.location.href},
reset: function() {
metaDescription = defaultMetaDescription;
ogImage = defaultImage;
ogTitle = defaultTitle;
ogDescription = defaultMetaDescription;
},
setMetaDescription: function(newMetaDescription) {
metaDescription = newMetaDescription;
},
setOgImage: function(newOgImage) {
ogImage = newOgImage;
},
setOgTitle: function(newOgTitle) {
ogTitle = newOgTitle + " - " + defaultTitle;
},
setOgDescription: function(newOgDescription) {
ogDescription = newOgDescription;
metaDescription = newOgDescription;
},
appendMetaKeywords: function(newKeywords) {
for (var key in newKeywords) {
if (metaKeywords === '') {
metaKeywords += newKeywords[key].name;
} else {
metaKeywords += ', ' + newKeywords[key].name;
}
}
}
};
}]);
angular.module('app').run(function ($rootScope, $location, Auth, PageTitle, MetaInformation) {
$rootScope.PageTitle = PageTitle;
$rootScope.MetaInformation = MetaInformation;
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
$rootScope.MetaInformation.reset();
});
});
inside of a controller, you do the following
1 | $rootScope.PageTitle.setTitle('Something'); |