Skip to content

Commit e9974ce

Browse files
committed
Add posts
1 parent 4bb25b7 commit e9974ce

File tree

5 files changed

+92
-9
lines changed

5 files changed

+92
-9
lines changed

pages/blog/index.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
import Layout from '../../src/components/layout';
2-
// import { PER_PAGE_FIRST, totalPagesCount } from '../../src/utils/pagination';
3-
// import Pagination from '../../src/components/blog/pagination';
4-
// import Posts from '../../src/components/blog/posts';
1+
/**
2+
* External Dependencies.
3+
*/
54
import axios from 'axios';
6-
import { GET_POSTS_ENDPOINT, HEADER_FOOTER_ENDPOINT } from '../../src/utils/constants/endpoints';
5+
6+
/**
7+
* Internal Dependencies.
8+
*/
9+
import Layout from '../../src/components/layout';
10+
import { HEADER_FOOTER_ENDPOINT } from '../../src/utils/constants/endpoints';
711
import { getPosts } from '../../src/utils/blog';
12+
import Posts from '../../src/components/posts';
813

9-
const Blog = ( { headerFooter } ) => {
10-
// const pagesCount = totalPagesCount( data?.posts?.pageInfo?.offsetPagination?.total ?? 0 );
14+
const Blog = ( { headerFooter, postsData } ) => {
15+
console.log( 'postsData', postsData );
1116
return (
1217
<Layout headerFooter={ headerFooter || {} } seo={null}>
13-
{/*<Posts posts={data?.posts?.edges ?? []}/>*/}
14-
{/*<Pagination pagesCount={pagesCount} postName="blog" />*/}
18+
<h1>Blog</h1>
19+
<Posts posts={postsData?.posts_data ?? []}/>
20+
{/*<Pagination pagesCount={postsData?.page_count} postName="blog" />*/}
1521
</Layout>
1622
);
1723
};

src/components/layout/header/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ const Header = ( { header } ) => {
5252
dangerouslySetInnerHTML={ { __html: menuItem.title } }/>
5353
</Link>
5454
) ) : null }
55+
<Link href="/blog">
56+
<a className="block mt-4 lg:inline-block lg:mt-0 hover:text-brand-royal-blue duration-500 mr-10">Blog</a>
57+
</Link>
5558
</div>
5659
<div className="text-sm font-medium">
5760
<a href="#responsive-header"

src/components/posts/index.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* External Dependencies.
3+
*/
4+
import PropTypes from 'prop-types';
5+
import { isEmpty, isArray } from 'lodash';
6+
7+
/**
8+
* Internal Dependency.
9+
*/
10+
import Post from './post';
11+
12+
13+
const Posts = ( { posts } ) => {
14+
15+
if ( isEmpty( posts ) && ! isArray( posts ) ) {
16+
return null;
17+
}
18+
19+
return (
20+
<div className="flex flex-wrap -mb-4">
21+
{
22+
posts.map( ( post, index ) => {
23+
return (
24+
<div
25+
key={ `${ post?.id ?? '' }-${ index }` ?? '' }
26+
className="w-full md:w-1/2 lg:w-1/3 mb-4 px-2"
27+
>
28+
<Post post={ post }/>
29+
</div>
30+
);
31+
} )
32+
}
33+
</div>
34+
);
35+
};
36+
37+
Posts.propTypes = {
38+
posts: PropTypes.array,
39+
};
40+
41+
Posts.defaultProps = {
42+
posts: [],
43+
};
44+
45+
export default Posts;

src/components/posts/post.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Link from 'next/link';
2+
import Image from '../image';
3+
import { sanitize } from '../../utils/miscellaneous';
4+
5+
const Post = ( {post} ) => {
6+
7+
return (
8+
<div className="mb-8">
9+
<figure className="overflow-hidden mb-4">
10+
<Image
11+
sourceUrl={ post?.attachment_image?.img_src ?? '' }
12+
title={ post?.title ?? '' }
13+
width="400"
14+
height="225"
15+
layout="fill"
16+
containerClassNames="w-96 sm:-w-600px md:w-400px h-56 sm:h-338px md:h-225px"
17+
/>
18+
</figure>
19+
<Link href={`/blog/${post?.slug}/`}>
20+
<a>
21+
<h2 className="font-bold mb-3 text-lg hover:text-blue-500" dangerouslySetInnerHTML={{__html: sanitize( post?.title ?? '' )}}/>
22+
</a>
23+
</Link>
24+
<div dangerouslySetInnerHTML={{__html: sanitize( post?.excerpt ?? '' )}}/>
25+
</div>
26+
);
27+
};
28+
29+
export default Post;

src/utils/constants/posts.js

Whitespace-only changes.

0 commit comments

Comments
 (0)