Skip to content

Commit 9de54aa

Browse files
committed
Create seo service
1 parent 2bedb10 commit 9de54aa

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
2.68 KB
Loading
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import '@images/cep-promise-288x288.png';
2+
import ENV from '@environment';
3+
4+
const _public = {};
5+
const DEFAULT_IMAGE_FILENAME = 'cep-promise-288x288.png';
6+
7+
_public.buildHead = ({ title, description, keywords, imageFilename }) => {
8+
return {
9+
title: {
10+
inner: title
11+
},
12+
meta: [
13+
{ name: 'application-name', content: '' },
14+
{ name: 'description', content: description, id: 'desc' },
15+
{ name: 'keywords', content: keywords },
16+
// Twitter
17+
{ name: 'twitter:card', content: 'summary' },
18+
{ name: 'twitter:title', content: title },
19+
{ name: 'twitter:description', content: description },
20+
{ name: 'twitter:site', content: '@ceppromise' },
21+
{ name: 'twitter:creator', content: '@ceppromise' },
22+
// Google+ / Schema.org
23+
{ itemprop: 'name', content: title },
24+
{ itemprop: 'desc', content: description },
25+
// Facebook / Open Graph
26+
{ property: 'og:title', content: title },
27+
{ property: 'og:image', content: buildImageUrl(imageFilename) }
28+
]
29+
};
30+
};
31+
32+
function buildImageUrl(filename = DEFAULT_IMAGE_FILENAME){
33+
return `${ENV.APP.BASE_URL}/images/${filename}`;
34+
}
35+
36+
export default _public;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import seoService from './seo';
2+
3+
describe('SEO Service', () => {
4+
function buildViewData(){
5+
return {
6+
title: 'Title',
7+
description: 'Description',
8+
keywords: 'Keywords',
9+
imageFilename: 'test.png'
10+
};
11+
}
12+
13+
it('should build seo items', () => {
14+
expect(seoService.buildHead(buildViewData())).toEqual({
15+
title: {
16+
inner: 'Title'
17+
},
18+
meta: [
19+
{ name: 'application-name', content: '' },
20+
{ name: 'description', content: 'Description', id: 'desc' },
21+
{ name: 'keywords', content: 'Keywords' },
22+
{ name: 'twitter:card', content: 'summary' },
23+
{ name: 'twitter:title', content: 'Title' },
24+
{ name: 'twitter:description', content: 'Description' },
25+
{ name: 'twitter:site', content: '@ceppromise' },
26+
{ name: 'twitter:creator', content: '@ceppromise' },
27+
{ itemprop: 'name', content: 'Title' },
28+
{ itemprop: 'desc', content: 'Description' },
29+
{ property: 'og:title', content: 'Title' },
30+
{ property: 'og:image', content: 'http://localhost:7000/images/test.png' }
31+
]
32+
});
33+
});
34+
35+
it('should build seo items with default image if no image filename has been provided', () => {
36+
const viewData = buildViewData();
37+
delete viewData.imageFilename;
38+
expect(seoService.buildHead(viewData)).toEqual({
39+
title: {
40+
inner: 'Title'
41+
},
42+
meta: [
43+
{ name: 'application-name', content: '' },
44+
{ name: 'description', content: 'Description', id: 'desc' },
45+
{ name: 'keywords', content: 'Keywords' },
46+
{ name: 'twitter:card', content: 'summary' },
47+
{ name: 'twitter:title', content: 'Title' },
48+
{ name: 'twitter:description', content: 'Description' },
49+
{ name: 'twitter:site', content: '@ceppromise' },
50+
{ name: 'twitter:creator', content: '@ceppromise' },
51+
{ itemprop: 'name', content: 'Title' },
52+
{ itemprop: 'desc', content: 'Description' },
53+
{ property: 'og:title', content: 'Title' },
54+
{ property: 'og:image', content: 'http://localhost:7000/images/cep-promise-288x288.png' }
55+
]
56+
});
57+
});
58+
});

0 commit comments

Comments
 (0)