Skip to content

Instantly share code, notes, and snippets.

View abedzantout's full-sized avatar
🌍
Hello World!

Abdul Rahman Zantout abedzantout

🌍
Hello World!
View GitHub Profile
@abedzantout
abedzantout / layout-tags.tsx
Created September 21, 2019 11:40
Updated Layout Component to include tags
import React, {FunctionComponent, Fragment, ReactNode} from 'react';
type Props = {
metaTags: MetaTags;
children: ReactNode;
}
const Layout: FunctionComponent<Props> = ({metaTags, children}) => {
return (
<Fragment>
@abedzantout
abedzantout / post.tsx
Last active September 23, 2019 07:33
Post.tsx without Meta Tags
import { NextPage } from 'next';
import React from 'react';
import ReactMarkdown from 'react-markdown';
import './styles.css';
import { ContentfulService } from '../../core/contentful';
import Layout from '../../shared/components/layout/layout.component';
@abedzantout
abedzantout / post.css
Created September 21, 2019 12:07
Post styling
.post-container {
margin: 1rem auto 1rem 4rem;
width: 65%;
}
.markdown p,
.markdown ul,
.markdown ol {
margin-bottom: 1.5rem;
// Helper functions
export const getNavigationLink = (slug) => `/post/${slug}`;
export const getHref = (slug) => ({
pathname: '/post',
query: {post: slug},
});
@abedzantout
abedzantout / contentful.ts
Created October 2, 2019 07:32
Contentful.ts with suggestions
import { createClient } from 'contentful';
import { BlogPost } from '../interfaces/post';
export const CONTENT_TYPE_BLOGPOST = 'blogPost';
export const CONTENT_TYPE_PERSON = 'author';
export const CONTENT_TYPE_TAGS = 'tag';
const Space = process.env.CONTENTFUL_SPACE;
const Token = process.env.CONTENTFUL_TOKEN;
@abedzantout
abedzantout / contentful-suggestions-function.ts
Created October 2, 2019 10:07
contentful suggestions function
async fetchSuggestions(tags: string[], currentArticleSlug: string) {
const limit = 3; // limit of posts we want to fetch
let entries = [];
const initialOptions = {
content_type: CONTENT_TYPE_BLOGPOST,
limit,
// find at least one matching tag, else undefined properties are not copied
'fields.tags.sys.id[in]': tags.length ? tags.join(',') : undefined,