Skip to content

Commit dd2e30e

Browse files
committed
feat: add image blur loading
1 parent 8f7e4ab commit dd2e30e

File tree

11 files changed

+326
-27
lines changed

11 files changed

+326
-27
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Source code of my personal website & blog ✨
44

55
Check the live version [here](https://shellbear.me/) ⚡️
66

7-
[![home](./.github/img/home.webp)](https://shellbear.me/)
8-
[![blog](./.github/img/blog.webp)](https://shellbear.me/)
7+
[![home](.github/img/home.png)](https://shellbear.me/)
8+
[![blog](.github/img/blog.png)](https://shellbear.me/)
99

1010
## ✨ Features
1111

components/Separator.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import styled from 'styled-components';
2+
3+
const Separator = styled.hr`
4+
width: 100%;
5+
border: 1px solid rgba(0, 0, 0, 0.1);
6+
`;
7+
8+
export default Separator;

components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export { default as Card } from './Card';
1111
export { default as Image } from './Image';
1212
export { default as TransparentLink } from './TransparentLink';
1313
export { default as MDXContent } from './MDXContent';
14+
export { default as Separator } from './Separator';

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
config.resolve.fallback.fs = false;
1313
}
1414
config.module.rules.push({
15-
test: /\.md|\.mdx$/,
15+
test: /\.md|\.mdx|\.webp$/,
1616
use: 'raw-loader',
1717
});
1818

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@notionhq/client": "^2.2.0",
16+
"@plaiceholder/next": "^2.5.0",
1617
"fast-glob": "^3.2.11",
1718
"framer-motion": "^7.2.1",
1819
"gray-matter": "^4.0.3",
@@ -22,6 +23,7 @@
2223
"next-mdx-remote": "^4.1.0",
2324
"notion-client": "^6.13.8",
2425
"notion-utils": "^6.13.4",
26+
"plaiceholder": "^2.5.0",
2527
"prettier": "^2.7.1",
2628
"prismjs": "^1.29.0",
2729
"raw-loader": "^4.0.2",
@@ -30,6 +32,7 @@
3032
"react-icons": "^4.4.0",
3133
"react-notion-x": "^6.13.9",
3234
"reactdom": "^2.0.0",
35+
"sharp": "^0.31.0",
3336
"styled-components": "^5.3.5",
3437
"styled-system": "^5.1.5"
3538
},

pages/about/[slug].tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
NextPage,
66
} from 'next';
77
import Head from 'next/head';
8-
import { Container, Title, Text, MDXContent } from '@components';
8+
import { Container, Title, Text, MDXContent, Separator } from '@components';
99
import { getPosts, Post } from '@posts';
1010
import Image from 'next/image';
1111

@@ -48,6 +48,8 @@ const About: NextPage<InferGetStaticPropsType<typeof getStaticProps>> = ({
4848
alt={experience.data.title}
4949
layout="fill"
5050
objectFit="cover"
51+
placeholder="blur"
52+
blurDataURL={experience.data.blurImage}
5153
/>
5254
</Container>
5355
<Container mt="1rem" gridGap="1rem">
@@ -65,12 +67,7 @@ const About: NextPage<InferGetStaticPropsType<typeof getStaticProps>> = ({
6567
</Text>
6668
</Container>
6769
</Container>
68-
<hr
69-
style={{
70-
width: '100%',
71-
border: '1px solid rgba(0,0,0,0.1)',
72-
}}
73-
/>
70+
<Separator />
7471
<MDXContent {...experience.source} />
7572
</Container>
7673
);

posts/blog/go-dokku-deployment.md

Whitespace-only changes.

posts/blog/go-graphql-api.md

Whitespace-only changes.

posts/blog/styled-system.md

Whitespace-only changes.

posts/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'path';
44
import matter from 'gray-matter';
55
import { serialize } from 'next-mdx-remote/serialize';
66
import { MDXRemoteSerializeResult } from 'next-mdx-remote';
7+
import { getPlaiceholder } from 'plaiceholder';
78

89
const baseDir = path.join(process.cwd(), './posts/');
910

@@ -13,7 +14,7 @@ export interface Post {
1314
content: string;
1415
}
1516

16-
const getPosts = (dir: string): Promise<Post[]> => {
17+
const getPosts = async (dir: string): Promise<Post[]> => {
1718
const contentGlob = path.join(path.join(baseDir, dir), '/*.mdx');
1819
const files = glob.sync(contentGlob);
1920

@@ -25,6 +26,12 @@ const getPosts = (dir: string): Promise<Post[]> => {
2526
const { data, content } = matter(raw);
2627

2728
data.slug = slug;
29+
30+
if (data.image) {
31+
const { base64 } = await getPlaiceholder(data.image);
32+
data.blurImage = base64;
33+
}
34+
2835
const source = await serialize(content, {
2936
scope: data,
3037
});

0 commit comments

Comments
 (0)