mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-07-26 04:04:27 +02:00
refactor: using react hooks
This commit is contained in:
4
src/hooks/index.js
Normal file
4
src/hooks/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
// @flow
|
||||
export { default as useSiteMetadata } from './use-site-metadata';
|
||||
export { default as useCategoriesList } from './use-categories-list';
|
||||
export { default as useTagsList } from './use-tags-list';
|
23
src/hooks/use-categories-list.js
Normal file
23
src/hooks/use-categories-list.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// @flow
|
||||
import { useStaticQuery, graphql } from 'gatsby';
|
||||
|
||||
const useCategoriesList = () => {
|
||||
const { allMarkdownRemark } = useStaticQuery(
|
||||
graphql`
|
||||
query CategoriesListQuery {
|
||||
allMarkdownRemark(
|
||||
filter: { frontmatter: { template: { eq: "post" }, draft: { ne: true } } }
|
||||
) {
|
||||
group(field: frontmatter___category) {
|
||||
fieldValue
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
return allMarkdownRemark.group;
|
||||
};
|
||||
|
||||
export default useCategoriesList;
|
41
src/hooks/use-site-metadata.js
Normal file
41
src/hooks/use-site-metadata.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
import { useStaticQuery, graphql } from 'gatsby';
|
||||
|
||||
const useSiteMetadata = () => {
|
||||
const { site } = useStaticQuery(
|
||||
graphql`
|
||||
query SiteMetaData {
|
||||
site {
|
||||
siteMetadata {
|
||||
author {
|
||||
name
|
||||
bio
|
||||
photo
|
||||
contacts {
|
||||
email
|
||||
telegram
|
||||
twitter
|
||||
github
|
||||
rss
|
||||
vkontakte
|
||||
}
|
||||
}
|
||||
menu {
|
||||
label
|
||||
path
|
||||
}
|
||||
url
|
||||
title
|
||||
subtitle
|
||||
copyright
|
||||
disqusShortname
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
return site.siteMetadata;
|
||||
};
|
||||
|
||||
export default useSiteMetadata;
|
23
src/hooks/use-tags-list.js
Normal file
23
src/hooks/use-tags-list.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// @flow
|
||||
import { useStaticQuery, graphql } from 'gatsby';
|
||||
|
||||
const useTagsList = () => {
|
||||
const { allMarkdownRemark } = useStaticQuery(
|
||||
graphql`
|
||||
query TagsListQuery {
|
||||
allMarkdownRemark(
|
||||
filter: { frontmatter: { template: { eq: "post" }, draft: { ne: true } } }
|
||||
) {
|
||||
group(field: frontmatter___tags) {
|
||||
fieldValue
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
return allMarkdownRemark.group;
|
||||
};
|
||||
|
||||
export default useTagsList;
|
Reference in New Issue
Block a user