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 / 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,
@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;
// Helper functions
export const getNavigationLink = (slug) => `/post/${slug}`;
export const getHref = (slug) => ({
pathname: '/post',
query: {post: slug},
});
@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;
@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 / 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 / pages.index.tsx
Created September 21, 2019 10:29
initial index.tsx
import React from 'react';
import { NextPage } from 'next';
type Props = {}
const IndexPage: NextPage = (props: Props) => {
return (<div>Hello World!</div>)
};
@abedzantout
abedzantout / constants.ts
Created September 20, 2019 21:51
Meta tags constants
import { PageType, RobotsContent, Tag } from '../interfaces/tag';
import { concatenateStrings } from '../shared/helpers/helper';
export const defaultMetaTags: Tag = {
canonical: 'https://www.techhive.io',
description: 'Pushing you to the edge of technological innovation',
image: 'https://www.techhive.io/image.png',
robots: concatenateStrings(RobotsContent.index, RobotsContent.follow),
title: 'Techhive.IO',
type: PageType.website
require('dotenv').config();
const { generateSitemap } = require('./sitemap');
generateSitemap(process.env.PUBLIC_DOMAIN, './out/');
@abedzantout
abedzantout / sitemap.js
Last active September 20, 2019 21:22
Sitemap generator
/*
Generates a sitemap based on the entries in exportPathMap in next.config.js file
Don't forget to add the domain name as process variable PUBLIC_DOMAIN!
*/
const fs = require('fs');
// Read from the static map that's provided by next
const { exportPathMap } = require('../next.config');
const { generateAllArticles } = require('./helpers');