@@ -8,50 +8,76 @@ interface ISEOMetadata {
88 meta ?: any [ ] ;
99 description ?: string ;
1010 image ?: string ;
11+ pathname ?: string ;
12+ keywords ?: string [ ] ;
1113}
1214
13- const SEOMetadata : React . FC < ISEOMetadata > = ( { image = '' , pageTitle, description = '' , lang = 'en' , meta = [ ] } ) => {
14- const { site, allFile } = useStaticQuery (
15- graphql `
16- query {
17- site {
18- siteMetadata {
19- title
20- description
21- author
22- siteUrl
23- }
15+ const SEOMetadata : React . FC < ISEOMetadata > = ( {
16+ image = '' ,
17+ pageTitle,
18+ description = '' ,
19+ lang = 'pl' ,
20+ meta = [ ] ,
21+ pathname = '' ,
22+ keywords = [ ] ,
23+ } ) => {
24+ const { site, allFile } = useStaticQuery ( graphql `
25+ query {
26+ site {
27+ siteMetadata {
28+ title
29+ description
30+ author
31+ siteUrl
2432 }
25- allFile(filter: {name: {eq: "background3"}, ext: {eq: ".jpg"}}) {
26- edges {
27- node {
28- publicURL
29- }
33+ }
34+ allFile(filter: { name: { eq: "background3" }, ext: { eq: ".jpg" } }) {
35+ edges {
36+ node {
37+ publicURL
3038 }
3139 }
3240 }
33- `
34- ) ;
41+ }
42+ ` ) ;
3543
3644 const metaDescription = description || site . siteMetadata . description ;
37- const browserTabTitle = `${ pageTitle } | Pola Web` ;
38- const metaImage = image ? image : `${ site . siteMetadata . siteUrl } ${ allFile . edges [ 0 ] . node . publicURL } `
45+ const siteTitle = site . siteMetadata . title || 'Pola' ;
46+ const fullTitle = `${ pageTitle } | ${ siteTitle } ` ;
47+ const metaImage = image || `${ site . siteMetadata . siteUrl } ${ allFile . edges [ 0 ] . node . publicURL } ` ;
48+ const canonicalUrl = pathname ? `${ site . siteMetadata . siteUrl } ${ pathname } ` : site . siteMetadata . siteUrl ;
49+
50+ const defaultKeywords = [
51+ 'polskie produkty' ,
52+ 'polskie firmy' ,
53+ 'kod EAN' ,
54+ 'sprawdz czy produkt jest polski' ,
55+ 'Pola aplikacja' ,
56+ ] ;
57+
58+ const allKeywords = [ ...new Set ( [ ...defaultKeywords , ...keywords ] ) ] ;
3959
4060 return (
4161 < Helmet
4262 htmlAttributes = { {
4363 lang,
4464 } }
45- title = { browserTabTitle }
46- titleTemplate = { `%s | ${ site . siteMetadata . title } ` }
65+ title = { fullTitle }
66+ titleTemplate = { `%s` }
4767 meta = { [
4868 {
4969 name : 'description' ,
5070 content : metaDescription ,
5171 } ,
72+ allKeywords . length > 0
73+ ? {
74+ name : 'keywords' ,
75+ content : allKeywords . join ( ', ' ) ,
76+ }
77+ : { } ,
5278 {
5379 property : 'og:title' ,
54- content : pageTitle ,
80+ content : fullTitle ,
5581 } ,
5682 {
5783 property : 'og:description' ,
@@ -61,35 +87,55 @@ const SEOMetadata: React.FC<ISEOMetadata> = ({ image = '', pageTitle, descriptio
6187 property : 'og:type' ,
6288 content : 'website' ,
6389 } ,
90+ {
91+ property : 'og:site_name' ,
92+ content : siteTitle ,
93+ } ,
94+ {
95+ property : 'og:url' ,
96+ content : canonicalUrl ,
97+ } ,
6498 {
6599 name : 'twitter:card' ,
66- content : 'summary ' ,
100+ content : 'summary_large_image ' ,
67101 } ,
68102 {
69103 name : 'twitter:creator' ,
70104 content : site . siteMetadata . author ,
71105 } ,
106+ {
107+ name : 'twitter:site' ,
108+ content : site . siteMetadata . author ,
109+ } ,
72110 {
73111 name : 'twitter:title' ,
74- content : pageTitle ,
112+ content : fullTitle ,
75113 } ,
76114 {
77115 name : 'twitter:description' ,
78116 content : metaDescription ,
79117 } ,
80118 {
81- name : 'og:image' ,
119+ property : 'og:image' ,
82120 content : metaImage ,
83121 } ,
84122 {
85123 name : 'twitter:image' ,
86124 content : metaImage ,
87125 } ,
88126 {
89- name : 'og:image:width' ,
127+ property : 'og:image:width' ,
90128 content : '1200' ,
91129 } ,
92- ] . concat ( meta ) }
130+ ]
131+ . filter ( Boolean as any )
132+ . concat ( meta ) }
133+ link = { [
134+ {
135+ rel : 'canonical' ,
136+ href : canonicalUrl ,
137+ } ,
138+ ] }
93139 />
94140 ) ;
95141} ;
0 commit comments