Add seo, improve styles for dynamic content and add types

This commit is contained in:
Hazem Krimi
2021-01-15 19:01:37 +01:00
parent 3d23774abc
commit b48476b5d1
6 changed files with 322 additions and 147 deletions
+49 -8
View File
@@ -1,6 +1,9 @@
import { FC } from 'react';
import { getBlogPostsSlugs, getBlogPostdata } from '../../lib/blog';
import { useRouter } from 'next/router';
import { MdxRemote } from 'next-mdx-remote/types';
import { MDXEmbedProvider } from 'mdx-embed';
import { GetStaticPaths, GetStaticProps } from 'next';
import renderToString from 'next-mdx-remote/render-to-string';
import hydrate from 'next-mdx-remote/hydrate';
import styled from 'styled-components';
@@ -10,7 +13,7 @@ import Head from 'next/head';
import IconButton from '../../components/IconButton';
interface Props {
source: any;
source: MdxRemote.Source;
frontMatter: any;
}
@@ -89,9 +92,15 @@ const Wrapper = styled.div`
p,
h1,
h2,
h3 {
h3,
button {
margin: 0.5rem 0rem;
}
p * {
width: 100%;
height: auto;
}
}
`;
@@ -104,7 +113,37 @@ const BlogPost: FC<Props> = ({ source, frontMatter }) => {
return (
<>
<Head>
<title>{frontMatter.title}</title>
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
<meta name='author' content='Hazem Krimi' />
<meta
name='description'
content={
frontMatter.description
? frontMatter.description
: 'Hazem Krimi is a Full Stack JavaScript Developer and a Software Engineering Enthusiast'
}
/>
<link rel='shortcut icon' href='favicon.ico' type='image/x-icon' />
<link rel='canonical' href='https://hazemkrimi.tech' />
<meta property='og:image' content='/logo.jpg' />
<meta
property='og:description'
content={
frontMatter.description
? frontMatter.description
: 'Hazem Krimi is a Full Stack JavaScript Developer and a Software Engineering Enthusiast'
}
/>
<meta property='og:title' content={`${frontMatter.title} | Hazem Krimi`} />
<meta
name='keywords'
content={
frontMatter.tags
? frontMatter.tags.join(' ')
: 'Hazem, Krimi, Developer, Software, Engineer, Web, Mobile, Frontend, Backend, Fullstack, JavaScript, React.js, React Native, Node.js, Portfolio, Blog, Tutorials, Tech News'
}
/>
<title>{frontMatter.title} | Hazem Krimi</title>
</Head>
<Wrapper>
<div className='meta'>
@@ -125,7 +164,9 @@ const BlogPost: FC<Props> = ({ source, frontMatter }) => {
)}
<hr />
</div>
<div className='content'>{content}</div>
<MDXEmbedProvider>
<div className='content'>{content}</div>
</MDXEmbedProvider>
</Wrapper>
</>
);
@@ -133,14 +174,14 @@ const BlogPost: FC<Props> = ({ source, frontMatter }) => {
export default BlogPost;
export async function getStaticPaths() {
export const getStaticPaths: GetStaticPaths = async () => {
const paths = getBlogPostsSlugs();
return {
paths,
fallback: false
};
}
export async function getStaticProps({ params }: any) {
};
export const getStaticProps: GetStaticProps = async ({ params }: any) => {
const blogPostContent = await getBlogPostdata(params.slug);
const { data, content } = matter(blogPostContent);
const mdxSource = await renderToString(content, {
@@ -154,4 +195,4 @@ export async function getStaticProps({ params }: any) {
frontMatter: data
}
};
}
};
+40 -16
View File
@@ -4,6 +4,7 @@ import { getBlogPosts } from '../../lib/blog';
import styled from 'styled-components';
import Card from '../../components/Card';
import IconButton from '../../components/IconButton';
import Head from 'next/head';
interface Props {
blogPosts: {
@@ -54,22 +55,45 @@ const Index: FC<Props> = ({ blogPosts }) => {
const router = useRouter();
return (
<Wrapper>
<div className='back' onClick={() => router.back()}>
<IconButton icon='/arrow-left.svg' />
<span>Back</span>
</div>
<h1>Blog</h1>
<div className='articles-wrapper'>
{blogPosts.length !== 0 ? (
blogPosts.map(({ slug, ...rest }) => (
<Card {...rest} key={slug} onClick={() => router.push(`/blog/${slug}`)} />
))
) : (
<h4>Nothing for now</h4>
)}
</div>
</Wrapper>
<>
<Head>
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
<meta name='author' content='Hazem Krimi' />
<meta
name='description'
content='Hazem Krimi is a Full Stack JavaScript Developer and a Software Engineering Enthusiast'
/>
<link rel='shortcut icon' href='favicon.ico' type='image/x-icon' />
<link rel='canonical' href='https://hazemkrimi.tech' />
<meta property='og:image' content='/logo.jpg' />
<meta
property='og:description'
content='Hazem Krimi is a Full Stack JavaScript Developer and a Software Engineering Enthusiast'
/>
<meta property='og:title' content='Hazem Krimi' />
<meta
name='keywords'
content='Hazem, Krimi, Developer, Software, Engineer, Web, Mobile, Frontend, Backend, Fullstack, JavaScript, React.js, React Native, Node.js, Portfolio, Blog, Tutorials, Tech News'
/>
<title>Blog | Hazem Krimi</title>
</Head>
<Wrapper>
<div className='back' onClick={() => router.back()}>
<IconButton icon='/arrow-left.svg' />
<span>Back</span>
</div>
<h1>Blog</h1>
<div className='articles-wrapper'>
{blogPosts.length !== 0 ? (
blogPosts.map(({ slug, ...rest }) => (
<Card {...rest} key={slug} onClick={() => router.push(`/blog/${slug}`)} />
))
) : (
<h4>Nothing for now</h4>
)}
</div>
</Wrapper>
</>
);
};