Skip to content

Commit

Permalink
Merge pull request #81 from igor-starostenko/develop
Browse files Browse the repository at this point in the history
v2.2.2
  • Loading branch information
igor-starostenko authored Jan 1, 2023
2 parents e6a003d + 8147eac commit 9846f36
Show file tree
Hide file tree
Showing 27 changed files with 1,104 additions and 1,577 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public/browserconfig.xml
public/icons/
public/manifest.json
public/sitemap.xml
public/sitemap*.xml
public/robots.txt
File renamed without changes.
17 changes: 0 additions & 17 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
const path = require('path');
const Dotenv = require('dotenv-webpack');

const next_config = {
images: {
domains: ['images.ctfassets.net'],
...{ ...(process.env.IMAGE_OPTIMIZATION ? {} : { loader: 'custom' }) },
},
webpack: (config) => {
config.plugins = config.plugins || [];

config.plugins = [
...config.plugins,
// Read the .env file
new Dotenv({
path: path.join(__dirname, '.env'),
systemvars: true,
}),
];

return config;
},
};

module.exports = { ...next_config };
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@
"node": ">=17.0.1"
},
"dependencies": {
"@contentful/rich-text-react-renderer": "^15.6.2",
"babel-plugin-styled-components": "^1.13.3",
"contentful": "^9.1.4",
"@contentful/rich-text-react-renderer": "^15.16.2",
"babel-plugin-styled-components": "^2.0.7",
"contentful": "^9.2.14",
"dotenv": "^10.0.0",
"framer-motion": "^5.2.1",
"next": "^12.1.0",
"next": "^13.0.7",
"prop-types": "^15.6.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-images": "^1.2.0-beta.7",
"react-photo-gallery": "^8.0.0",
"styled-components": "^5.3.3"
"react-syntax-highlighter": "^15.5.0",
"styled-components": "^5.3.6"
},
"devDependencies": {
"ava": "^3.15.0",
Expand All @@ -46,16 +47,15 @@
"contentful-migration": "^4.5.9",
"core-js": "^3.19.1",
"directory-named-webpack-plugin": "^4.0.0",
"dotenv-webpack": "^7.0.3",
"eslint": "<8.0.0",
"eslint-config-next": "12.0.3",
"eslint-config-next": "^12.2.3",
"eslint-config-prettier": "^8.3.0",
"favicons": "^6.2.2",
"favicons": "^7.0.2",
"lighthouse": "^8.6.0",
"mkdirp": "^1.0.4",
"next-sitemap": "^1.6.203",
"node-gyp": "^8.4.0",
"next-sitemap": "^3.1.43",
"node-gyp": "^9.3.1",
"prettier": "^2.4.1",
"webpack": "^5.62.1"
"webpack": "^5.75.0"
}
}
12 changes: 6 additions & 6 deletions scripts/favicons.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const favicons = require('favicons');
const { favicons } = require('favicons');
const path = require('path');
const fs = require('fs');

Expand Down Expand Up @@ -41,29 +41,29 @@ const configuration = {
},
};

const callback = function(err, res) {
const callback = function (err, res) {
if (err) {
console.log(err.message);
return;
}

res.images.forEach(image => {
res.images.forEach((image) => {
fs.writeFile(
path.resolve(__dirname, '../public/icons/', image.name),
image.contents,
err => {
(err) => {
if (err) {
console.log(err);
}
}
);
});

res.files.forEach(file => {
res.files.forEach((file) => {
fs.writeFile(
path.resolve(__dirname, '../public/', file.name),
file.contents,
err => {
(err) => {
if (err) {
console.log(err);
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/article/article.css.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export const Card = styled.article`
`;

export const SLink = styled(Link)`
width: 100%;
text-decoration: none;
`;

export const Row = styled.div`
width: 100%;
display: inline-flex;
`;

export const Thumb = styled.div`
Expand All @@ -41,6 +43,8 @@ export const Description = styled.p`
`;

export const Date = styled.span`
min-width: 20%;
text-align: right;
margin-bottom: 1rem;
margin-top: 2.5rem;
color: ${colors.grey};
Expand All @@ -54,6 +58,7 @@ export const MobileDate = styled.span`
display: none;
color: ${colors.grey};
float: right;
margin-top: 1rem;
${MEDIA.PHONE`
display: block;
`};
Expand All @@ -66,7 +71,7 @@ export const Tags = styled.div`

export const Tag = styled.span`
margin: 0.5rem 10px 0.5rem 0px;
padding: 3px;
padding: 5px;
border-radius: 7px;
color: ${colors.darkGrey};
background: ${colors.lightestGrey};
Expand Down
39 changes: 17 additions & 22 deletions src/components/article/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const formatDate = (dateString) => {

const Article = ({
index,
category,
path,
title,
image,
Expand All @@ -34,32 +35,28 @@ const Article = ({
tags,
linkText,
}) => {
const href = `/posts/${path}`;
const href = `/${category}/${path}`;

return (
<Card>
{image && (
<SLink href={href}>
<a>
<Thumb
style={{
marginTop: `${index === 0 ? 0 : 5.5}rem`,
}}
>
<Image
src={`https:${image.file.url}`}
alt={title}
{...image.file.details.image}
/>
</Thumb>
</a>
<Thumb
style={{
marginTop: `${index === 0 ? 0 : 5.5}rem`,
}}
>
<Image
src={`https:${image.file.url}`}
alt={title}
{...image.file.details.image}
/>
</Thumb>
</SLink>
)}
<Row>
<SLink href={href}>
<a>
<Title as="h2">{title}</Title>
</a>
<Title as="h2">{title}</Title>
</SLink>
<DateText>{formatDate(date)}</DateText>
</Row>
Expand All @@ -69,18 +66,16 @@ const Article = ({
))}
</Tags>
<Description>
{description}{' '}
<Link href={href}>
<a>{linkText || 'Read more'}</a>
</Link>
{description} <Link href={href}>{linkText || 'Read more'}</Link>
</Description>
<MobileDate>{date}</MobileDate>
<MobileDate>{formatDate(date)}</MobileDate>
</Card>
);
};

Article.propTypes = {
index: PropTypes.number.isRequired,
category: PropTypes.string.isRequired,
path: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion src/components/box/box.css.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export const Container = styled.div`
margin: 0 auto;
${MEDIA.PHONE`
padding: 2rem 3rem 8rem 3rem;
padding: 0rem 3rem 8rem 3rem;
`}
`;
115 changes: 115 additions & 0 deletions src/components/category/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import React, { useEffect, useState } from 'react';
import { useRouter } from 'next/router';
import PropTypes from 'prop-types';
import Layout from 'components/layout';
import Box from 'components/box';
import Head from 'components/head';
import Filter from 'components/filter';
import Article from 'components/article';
import Pagination from 'components/pagination';

const Category = ({ page, posts }) => {
const pageSize = 10;
const totalPages = Math.ceil(posts.total / pageSize);
const router = useRouter();
const pageNum = parseInt(router.query.page);
const [displayCount, setDisplayCount] = useState(
pageNum ? pageNum * pageSize : pageSize
);

// Listen to scroll positions for loading more data on scroll
useEffect(() => {
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
});

const handleScroll = () => {
// To get page offset of last article
const lastRecordLoaded = document.querySelector('div > article:last-child');
if (lastRecordLoaded) {
const lastRecordLoadedOffset =
lastRecordLoaded.offsetTop + lastRecordLoaded.clientHeight;
const pageOffset = window.pageYOffset + window.innerHeight;
// Detects when last record is in view
if (pageOffset > lastRecordLoadedOffset) {
if (displayCount < posts.total) {
const newDisplayCount = displayCount + pageSize;
setDisplayCount(
newDisplayCount > posts.total ? posts.total : newDisplayCount
);
}
}
}
};

const startIndex = pageNum ? pageNum * pageSize - pageSize : 0;
const displayPosts = posts.items.slice(startIndex, startIndex + displayCount);

return (
<Layout>
<Head pageTitle={page.title} />
<Box>
<Filter
path={router.asPath}
title={page.title}
displayCount={displayPosts.length}
totalCount={posts.total}
/>
<div>
{displayPosts.map((post, index) => (
<Article
key={post.id}
index={index}
image={post.thumbnail}
category={post.category}
path={post.path}
title={post.title}
date={post.date}
description={post.description}
tags={post.tags}
linkText={post.linkText}
/>
))}
</div>
{displayPosts.length < posts.total - (pageNum || 1) * pageSize ? (
<Pagination pageNum={pageNum || 1} totalPages={totalPages} />
) : (
''
)}
</Box>
</Layout>
);
};

Category.propTypes = {
page: PropTypes.shape({
id: PropTypes.string.isRequired,
createdAt: PropTypes.string,
updatedAt: PropTypes.string,
title: PropTypes.string.isRequired,
}).isRequired,
posts: PropTypes.shape({
limit: PropTypes.number.isRequired,
skip: PropTypes.number.isRequired,
total: PropTypes.number.isRequired,
items: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
createdAt: PropTypes.string,
updatedAt: PropTypes.string,
title: PropTypes.string.isRequired,
date: PropTypes.string.isRequired,
layout: PropTypes.string.isRequired,
draft: PropTypes.bool.isRequired,
category: PropTypes.string.isRequired,
tags: PropTypes.arrayOf(PropTypes.string),
description: PropTypes.string.isRequired,
}).isRequired
),
linkText: PropTypes.string,
}).isRequired,
};

export default Category;
Loading

0 comments on commit 9846f36

Please sign in to comment.