From 972bea55b703a92e7907a1de55358fc3c4e75626 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Wed, 6 Nov 2019 22:10:25 +0400 Subject: [PATCH] Make guide page dynamic --- components/guide-footer/index.js | 18 ++++++++++++------ components/guide-header/index.js | 22 ++++++++++++++-------- data/authors.json | 11 ++++++++--- data/guides.json | 12 ++++++------ data/site.json | 4 ++++ lib/guide.js | 9 ++++++++- pages/guides/[guide].js | 4 ++-- 7 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 data/site.json diff --git a/components/guide-footer/index.js b/components/guide-footer/index.js index 4166997f9..e1d3e4b85 100644 --- a/components/guide-footer/index.js +++ b/components/guide-footer/index.js @@ -1,22 +1,28 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFacebookSquare, faGithub, faHackerNewsSquare, faRedditSquare, faTwitter, faTwitterSquare } from '@fortawesome/free-brands-svg-icons' import { AuthorBio, AuthorImg, AuthorInfoWrap, AuthorMeta, ContributeIcon, FooterBg, FooterContainer, FooterWrap, ShareIcons, ShareWrap } from './style'; +import { getContributionUrl } from "../../lib/guide"; -const GuideFooter = (props) => ( +const GuideFooter = ({ + guide, + guide: { + author = {} + } = {} +}) => ( - + Improve this Guide Contribute - + Follow the author Author @@ -37,10 +43,10 @@ const GuideFooter = (props) => ( - + -

Kamran Ahmed

- Lead engineer at Tajawal. Lover of all things web and opensource. Created roadmap.sh to help the confused ones. +

{ author.name }

+ { author.bio }
diff --git a/components/guide-header/index.js b/components/guide-header/index.js index d25baa91e..e3ea5c965 100644 --- a/components/guide-header/index.js +++ b/components/guide-header/index.js @@ -9,21 +9,27 @@ import { GuideTitle, HeaderWrap, } from './style'; +import { getContributionUrl } from "lib/guide"; -const GuideHeader = (props) => ( +const GuideHeader = ({ + guide, + guide: { + author = {} + } = {} +}) => ( - - - Kamran Ahmed + + + { author.name } · - Wednesday, October 9th 2019 + { guide.createdAt } · - Improve this Guide + Improve this Guide - Design Patterns for Humans - An ultra-simplified explanation to design patterns + { guide.title } + { guide.description } diff --git a/data/authors.json b/data/authors.json index beae6b42b..be71f04bb 100644 --- a/data/authors.json +++ b/data/authors.json @@ -2,16 +2,21 @@ { "username": "kamranahmedse", "name": "Kamran Ahmed", - "picture": "/static/authors/kamranahmedse.jpeg" + "twitter": "https://twitter.com/kamranahmedse", + "picture": "/static/authors/kamranahmedse.jpeg", + "bio": "Lead engineer at Tajawal. Lover of all things web and opensource. Created roadmap.sh to help the confused ones." }, { "username": "ziishaned", "name": "Zeeshan Ahmed", - "picture": "/static/authors/ziishaned.png" + "twitter": "https://twitter.com/ziishaned", + "picture": "/static/authors/ziishaned.png", + "bio": "Playing with computers ever since I started walking. Loves hiking, cycling, JavaScript, OpenSource, challenging myself and communities." }, { "username": "idnan", "name": "Adnan Ahmed", + "twitter": "https://twitter.com/idnan", "picture": "/static/authors/idnan.jpeg" } -] \ No newline at end of file +] diff --git a/data/guides.json b/data/guides.json index 5e75f86c7..d2c8003b1 100644 --- a/data/guides.json +++ b/data/guides.json @@ -5,7 +5,7 @@ "url": "/guides/design-patterns-for-humans", "featured": true, "author": "kamranahmedse", - "createdAt": "June 12, 2019", + "createdAt": "Wednesday, June 12, 2019", "updatedAt": "June 12, 2019" }, { @@ -14,7 +14,7 @@ "url": "/guides/learn-regex", "featured": true, "author": "ziishaned", - "createdDate": "June 19, 2019", + "createdAt": "Wednesday, June 19, 2019", "updatedAt": "June 19, 2019" }, { @@ -23,7 +23,7 @@ "url": "/guides/bash-guide", "featured": true, "author": "idnan", - "createdAt": "May 18, 2018", + "createdAt": "Wednesday, May 18, 2018", "updatedAt": "May 18, 2018" }, { @@ -32,7 +32,7 @@ "url": "/guides/dns-in-one-picture", "featured": true, "author": "kamranahmedse", - "createdAt": "May 11, 2018", + "createdAt": "Wednesday, May 11, 2018", "updatedAt": "May 11, 2018" }, { @@ -41,7 +41,7 @@ "url": "/guides/using-react-hooks", "featured": true, "author": "kamranahmedse", - "createdAt": "October 22, 2019", + "createdAt": "Wednesday, October 22, 2019", "updatedAt": "October 22, 2019" }, { @@ -51,6 +51,6 @@ "featured": true, "author": "kamranahmedse", "updatedAt": "November 01, 2019", - "createdAt": "November 01, 2019" + "createdAt": "Wednesday, November 01, 2019" } ] diff --git a/data/site.json b/data/site.json new file mode 100644 index 000000000..e3b6900b8 --- /dev/null +++ b/data/site.json @@ -0,0 +1,4 @@ +{ + "repoUrl": "https://github.com/kamranahmedse/roadmap-next", + "dataUrl": "/tree/master/data" +} diff --git a/lib/guide.js b/lib/guide.js index 7911ba475..08b1a55ea 100644 --- a/lib/guide.js +++ b/lib/guide.js @@ -1,4 +1,7 @@ import guides from "data/guides"; +import authors from "data/authors"; +import siteConfig from "data/site"; + export const getRequestedGuide = req => { const guide = guides.find(guide => guide.url === req.url); @@ -14,8 +17,8 @@ export const getRequestedGuide = req => { try { return { ...guide, + author: authors.find(author => author.username === guide.author) || {}, component: require(`../data/${path}.md`).default, - // component: require(guide.path.replace(/^\//, '')).default }; } catch (e) { console.log(e); @@ -23,3 +26,7 @@ export const getRequestedGuide = req => { return null; }; + +export const getContributionUrl = (guide) => { + return `${siteConfig.repoUrl}${siteConfig.dataUrl}${guide.url}.md` +}; diff --git a/pages/guides/[guide].js b/pages/guides/[guide].js index 3fcbf97e8..529bdc88a 100644 --- a/pages/guides/[guide].js +++ b/pages/guides/[guide].js @@ -14,12 +14,12 @@ const Guide = ({ guide }) => { return ( - + - + ); };