Add gtag and fix icons height

pull/1331/head
Kamran Ahmed 5 years ago
parent 565da5548b
commit 21b715dc57
  1. 8
      components/guide-footer/style.js
  2. 12
      components/helmet/index.js
  3. 12
      components/share-guide/index.js
  4. 11
      components/share-guide/style.js
  5. 6
      data/guides.json
  6. 14
      layouts/default/index.js
  7. 17
      lib/gtag.js
  8. 7
      lib/guide.js
  9. 2
      next.config.js
  10. 12
      pages/guides/[guide].js

@ -26,7 +26,8 @@ export const ShareWrap = styled.div`
color: #101010; color: #101010;
svg { svg {
height: 18px; height: 18px !important;
width: 18px !important;
color: #757575; color: #757575;
margin-left: 7px; margin-left: 7px;
transition: all 0.2s ease; transition: all 0.2s ease;
@ -108,9 +109,8 @@ export const AuthorBio = styled.p`
export const AuthorImg = styled.img` export const AuthorImg = styled.img`
border-radius: 100%; border-radius: 100%;
height: 100px; height: 100px !important;
width: 100px; width: 100px !important;
border-radius: 100%;
margin-right: 22px; margin-right: 22px;
`; `;

@ -1,5 +1,6 @@
import NextHead from 'next/head'; import NextHead from 'next/head';
import siteConfig from 'data/site'; import siteConfig from 'data/site';
import { GA_TRACKING_ID } from 'lib/gtag';
const prepareTitle = (givenTitle) => { const prepareTitle = (givenTitle) => {
givenTitle = givenTitle || siteConfig.title; givenTitle = givenTitle || siteConfig.title;
@ -52,6 +53,17 @@ const Helmet = (props) => (
<link rel="icon" type="image/png" sizes="16x16" href="/static/manifest/icon16.png" /> <link rel="icon" type="image/png" sizes="16x16" href="/static/manifest/icon16.png" />
<link rel="shortcut icon" href="/static/manifest/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="/static/manifest/favicon.ico" type="image/x-icon" />
<link rel="icon" href="/static/manifest/favicon.ico" type="image/x-icon" /> <link rel="icon" href="/static/manifest/favicon.ico" type="image/x-icon" />
{ /* Global Site Tag (gtag.js) - Google Analytics */ }
<script async src={ `https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}` } />
<script dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_TRACKING_ID}');
`,
}} />
</NextHead> </NextHead>
); );

@ -12,20 +12,14 @@ const ShareGuide = ({
}) => ( }) => (
<ShareWrap> <ShareWrap>
<ShareIconsList className="d-sm-none d-md-none d-lg-flex d-xl-flex"> <ShareIconsList className="d-sm-none d-md-none d-lg-flex d-xl-flex">
<ShareIcon> <ShareIcon href={ getTwitterShareUrl({ text: `${guide.title} by @${author.twitter}`, url: guide.url })} target="_blank">
<a href={ getTwitterShareUrl({ text: `${guide.title} by @${author.twitter}`, url: guide.url })} target="_blank">
<FontAwesomeIcon icon={ faTwitterSquare } /> <FontAwesomeIcon icon={ faTwitterSquare } />
</a>
</ShareIcon> </ShareIcon>
<ShareIcon> <ShareIcon href={ getFacebookShareUrl({ text: guide.title, url: guide.url }) } target="_blank">
<a href={ getFacebookShareUrl({ text: guide.title, url: guide.url }) } target="_blank">
<FontAwesomeIcon icon={ faFacebookSquare } /> <FontAwesomeIcon icon={ faFacebookSquare } />
</a>
</ShareIcon> </ShareIcon>
<ShareIcon> <ShareIcon href={ getRedditShareUrl({ text: guide.title, url: guide.url })} target="_blank">
<a href={ getRedditShareUrl({ text: guide.title, url: guide.url })} target="_blank">
<FontAwesomeIcon icon={ faRedditSquare } /> <FontAwesomeIcon icon={ faRedditSquare } />
</a>
</ShareIcon> </ShareIcon>
</ShareIconsList> </ShareIconsList>
</ShareWrap> </ShareWrap>

@ -15,18 +15,23 @@ export const ShareWrap = styled.div`
flex-direction: column; flex-direction: column;
position: absolute; position: absolute;
padding: 0 0; padding: 0 0;
top: 2px; top: 6px;
left: -50px; left: -50px;
height: 100%; height: 100%;
`; `;
export const ShareIcon = styled.span` export const ShareIcon = styled.a`
display: block;
width: 22px;
height: 22px;
margin-bottom: 8px; margin-bottom: 8px;
svg { svg {
height: 22px; height: 22px !important;
width: 22px !important;
color: #757575; color: #757575;
transition: all 0.2s; transition: all 0.2s;
vertical-align: top;
} }
&:hover svg { &:hover svg {

@ -3,6 +3,7 @@
"title": "Design Patterns for Humans", "title": "Design Patterns for Humans",
"description": "A language agnostic, ultra-simplified explanation to design patterns", "description": "A language agnostic, ultra-simplified explanation to design patterns",
"url": "/guides/design-patterns-for-humans", "url": "/guides/design-patterns-for-humans",
"fileName": "design-patterns-for-humans",
"featured": true, "featured": true,
"author": "kamranahmedse", "author": "kamranahmedse",
"createdAt": "2019-01-23T17:00:00.860Z", "createdAt": "2019-01-23T17:00:00.860Z",
@ -12,6 +13,7 @@
"title": "Learn Regex", "title": "Learn Regex",
"description": "An easy to understand guide on regular expressions with real world examples", "description": "An easy to understand guide on regular expressions with real world examples",
"url": "/guides/learn-regex", "url": "/guides/learn-regex",
"fileName": "learn-regex",
"featured": true, "featured": true,
"author": "ziishaned", "author": "ziishaned",
"createdAt": "2019-01-23T17:00:00.860Z", "createdAt": "2019-01-23T17:00:00.860Z",
@ -21,6 +23,7 @@
"title": "Bash Guide", "title": "Bash Guide",
"description": "Easy to understand guide for bash with real world usage examples.", "description": "Easy to understand guide for bash with real world usage examples.",
"url": "/guides/bash-guide", "url": "/guides/bash-guide",
"fileName": "bash-guide",
"featured": true, "featured": true,
"author": "idnan", "author": "idnan",
"createdAt": "2019-01-23T17:00:00.860Z", "createdAt": "2019-01-23T17:00:00.860Z",
@ -30,6 +33,7 @@
"title": "DNS in One Picture", "title": "DNS in One Picture",
"description": "Quick illustrative guide on how a website is found on the internet.", "description": "Quick illustrative guide on how a website is found on the internet.",
"url": "/guides/dns-in-one-picture", "url": "/guides/dns-in-one-picture",
"fileName": "dns-in-one-picture",
"featured": true, "featured": true,
"author": "kamranahmedse", "author": "kamranahmedse",
"createdAt": "2019-11-01T12:00:00.860Z", "createdAt": "2019-11-01T12:00:00.860Z",
@ -39,6 +43,7 @@
"title": "Using React Hooks", "title": "Using React Hooks",
"description": "Start using React hooks in your react applications today with this guide.", "description": "Start using React hooks in your react applications today with this guide.",
"url": "/guides/using-react-hooks", "url": "/guides/using-react-hooks",
"fileName": "using-react-hooks",
"featured": true, "featured": true,
"author": "kamranahmedse", "author": "kamranahmedse",
"createdAt": "2019-01-23T17:00:00.860Z", "createdAt": "2019-01-23T17:00:00.860Z",
@ -48,6 +53,7 @@
"title": "HTTP Caching", "title": "HTTP Caching",
"description": "Everything you need to know about web caching", "description": "Everything you need to know about web caching",
"url": "/guides/http-caching", "url": "/guides/http-caching",
"fileName": "http-caching",
"featured": true, "featured": true,
"author": "kamranahmedse", "author": "kamranahmedse",
"updatedAt": "2019-10-09T12:00:00.860Z", "updatedAt": "2019-10-09T12:00:00.860Z",

@ -1,11 +1,21 @@
import React from 'react';
import Helmet from 'components/helmet'; import Helmet from 'components/helmet';
import './global.scss'; import './global.scss';
import { firePageView } from '../../lib/gtag';
const DefaultLayout = (props) => ( class DefaultLayout extends React.Component {
componentDidMount() {
firePageView(window.location.pathname);
}
render() {
return (
<div> <div>
<Helmet /> <Helmet />
{ props.children } { this.props.children }
</div> </div>
); );
}
}
export default DefaultLayout; export default DefaultLayout;

@ -0,0 +1,17 @@
export const GA_TRACKING_ID = 'UA-139582634-1';
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const firePageView = url => {
window.gtag('config', GA_TRACKING_ID, {
page_path: url,
})
};
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
export const event = ({ action, category, label, value }) => {
window.gtag('event', action, {
event_category: category,
event_label: label,
value: value,
})
};

@ -2,23 +2,16 @@ import guides from "data/guides";
import authors from "data/authors"; import authors from "data/authors";
import siteConfig from "data/site"; import siteConfig from "data/site";
export const getRequestedGuide = req => { export const getRequestedGuide = req => {
const guide = guides.find(guide => guide.url === req.url); const guide = guides.find(guide => guide.url === req.url);
if (!guide) { if (!guide) {
return null; return null;
} }
// We will use this URL format to find the relevant markdown
// file inside the `/data` directory. For example `/guides/learn-regex`
// has to have `/guides/learn-regex.md` file inside the `data` directory
const path = guide.url.replace(/^\//, '');
try { try {
return { return {
...guide, ...guide,
author: authors.find(author => author.username === guide.author) || {}, author: authors.find(author => author.username === guide.author) || {},
component: require(`../data/${path}.md`).default,
}; };
} catch (e) { } catch (e) {
console.log(e); console.log(e);

@ -36,7 +36,7 @@ const options = {
config.resolve.modules.push(path.resolve('./')); config.resolve.modules.push(path.resolve('./'));
// Allow loading images // Allow loading images and fonts
config.module.rules.push({ config.module.rules.push({
test: /\.(png|jpg|gif|eot|ttf|woff|woff2)$/, test: /\.(png|jpg|gif|eot|ttf|woff|woff2)$/,
use: { use: {

@ -5,20 +5,22 @@ import GuideHeader from 'components/guide-header';
import GuideBody from 'components/guide-body'; import GuideBody from 'components/guide-body';
import ShareGuide from 'components/share-guide'; import ShareGuide from 'components/share-guide';
import GuideFooter from 'components/guide-footer'; import GuideFooter from 'components/guide-footer';
import { getRequestedGuide } from "lib/guide"; import { getRequestedGuide } from 'lib/guide';
import Helmet from '../../components/helmet'; import Helmet from 'components/helmet';
const Guide = ({ guide }) => { const Guide = ({ guide }) => {
if (!guide) { if (!guide) {
return <Error statusCode={ 404 } /> return <Error statusCode={ 404 } />
} }
const GuideContent = require(`../../data/guides/${guide.fileName}.md`).default;
return ( return (
<GuideLayout> <GuideLayout>
<Helmet title={ guide.title } description={ guide.description } /> <Helmet title={ guide.title } description={ guide.description } />
<GuideHeader guide={ guide } /> <GuideHeader guide={ guide } />
<GuideBody> <GuideBody>
<guide.component /> <GuideContent />
<ShareGuide guide={ guide } /> <ShareGuide guide={ guide } />
</GuideBody> </GuideBody>
<GuideFooter guide={ guide } /> <GuideFooter guide={ guide } />
@ -26,9 +28,9 @@ const Guide = ({ guide }) => {
); );
}; };
Guide.getInitialProps = serverOnlyProps(({ req }) => { Guide.getInitialProps = serverOnlyProps(async ({ req }) => {
return { return {
guide: getRequestedGuide(req), guide: await getRequestedGuide(req),
}; };
}); });

Loading…
Cancel
Save