pathname to view counter

This commit is contained in:
Sergey Yarkov 2020-07-16 15:10:19 +03:00
parent dc739b064d
commit dd773ee474
2 changed files with 7 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import ViewCounter from '../ViewCounter/ViewCounter'
import useSiteMetadataQuery from '../../hooks/useSiteMetadataQuery' import useSiteMetadataQuery from '../../hooks/useSiteMetadataQuery'
import slugify from '../../helpers/slugify' import slugify from '../../helpers/slugify'
import { Link } from 'gatsby' import { Link } from 'gatsby'
import { useLocation } from '@reach/router'
import ViewsIcon from '../../images/views-icon.svg' import ViewsIcon from '../../images/views-icon.svg'
import VkIcon from '../../images/vk-icon.svg' import VkIcon from '../../images/vk-icon.svg'
@ -14,6 +15,8 @@ import FacebookIcon from '../../images/facebook-icon__large.svg'
const Article = ({ data: { slug, keywords, title, image, description, category, tags, time, date }, html }) => { const Article = ({ data: { slug, keywords, title, image, description, category, tags, time, date }, html }) => {
const { siteMetadata: { siteUrl } } = useSiteMetadataQuery() const { siteMetadata: { siteUrl } } = useSiteMetadataQuery()
const { pathname } = useLocation()
return ( return (
<> <>
<SEO title={title} titleTemplate={false} keywords={keywords.join(', ')} description={description} image={`${siteUrl}${image.childImageSharp.fluid.src}`} type='article' /> <SEO title={title} titleTemplate={false} keywords={keywords.join(', ')} description={description} image={`${siteUrl}${image.childImageSharp.fluid.src}`} type='article' />
@ -26,7 +29,7 @@ const Article = ({ data: { slug, keywords, title, image, description, category,
</div> </div>
<div className="article-info__views"> <div className="article-info__views">
<ViewsIcon /> <ViewsIcon />
<ViewCounter id={slug} /> <ViewCounter id={pathname} />
</div> </div>
</div> </div>
<div className="right-info"> <div className="right-info">

View File

@ -26,7 +26,7 @@ collections:
label: "Category" label: "Category"
folder: 'content/categories' folder: 'content/categories'
create: true create: true
slug: "{{year}}-{{month}}-{{day}}" slug: "{{slug}}"
fields: fields:
- {label: "Template key", name: "templateKey", widget: "hidden", default: "category"} - {label: "Template key", name: "templateKey", widget: "hidden", default: "category"}
- {label: "Название категории", name: "title", widget: "string"} - {label: "Название категории", name: "title", widget: "string"}
@ -34,7 +34,7 @@ collections:
label: "Tag" label: "Tag"
folder: 'content/tags' folder: 'content/tags'
create: true create: true
slug: "{{year}}-{{month}}-{{day}}" slug: "{{slug}}"
fields: fields:
- {label: "Template key", name: "templateKey", widget: "hidden", default: "tag"} - {label: "Template key", name: "templateKey", widget: "hidden", default: "tag"}
- {label: "Название тэга", name: "title", widget: "string"} - {label: "Название тэга", name: "title", widget: "string"}
@ -42,7 +42,7 @@ collections:
label: "Book" label: "Book"
folder: 'content/books' folder: 'content/books'
create: true create: true
slug: "{{year}}-{{month}}-{{day}}" slug: "{{slug}}"
fields: fields:
- {label: "Template key", name: "templateKey", widget: "hidden", default: "book"} - {label: "Template key", name: "templateKey", widget: "hidden", default: "book"}
- {label: "Название книги", name: "title", widget: "string"} - {label: "Название книги", name: "title", widget: "string"}