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 / gtag.ts
Created September 20, 2019 14:57
G tag page and event track
// Add your GA tracking id here
export const GA_TRACKING_ID = '';
const isProduction = process.env.NODE_ENV.toLowerCase() === 'production';
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const trackPageView = url => {
if (isProduction) {
// @ts-ignore
window.gtag('config', GA_TRACKING_ID, {
import React, { Fragment } from 'react';
import Document, { Head, Main, NextScript } from 'next/document';
import { GA_TRACKING_ID } from '../core/gtag';
type Props = {
isProduction: boolean,
}
export default class extends Document<Props> {
static async getInitialProps(ctx) {
import App from 'next/app';
import React from 'react';
import Router from 'next/router';
import {trackPageView} from '../core/gtag';
Router.events.on('routeChangeComplete', url => trackPageView(url));
class MyApp extends App {
render() {
@abedzantout
abedzantout / next.config.js
Created September 20, 2019 20:30
Allowing next to read from our .env file
const path = require('path');
const Dotenv = require('dotenv-webpack');
const next_config = {
webpack: config => {
config.plugins = config.plugins || [];
config.plugins = [
...config.plugins,
// Read the .env file
@abedzantout
abedzantout / next.config.js
Created September 20, 2019 20:55
Next Config Initial File
// next.config.js
const withCSS = require('@zeit/next-css');
module.exports = withCSS({});
@abedzantout
abedzantout / pages.index.tsx
Last active April 6, 2022 04:29
Pages/index.tsx without the meta tags
import React, {useEffect, useState} from 'react';
import {NextPage} from 'next';
import {useRouter} from 'next/router'
import {ContentfulService} from '../core/contentful';
import {BlogPost} from '../interfaces/post';
import Layout from '../shared/components/layout';
import Card from '../shared/components/card';
@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');
require('dotenv').config();
const { generateSitemap } = require('./sitemap');
generateSitemap(process.env.PUBLIC_DOMAIN, './out/');
@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
@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>)
};