-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
273ab9e
commit 46d5dc5
Showing
18 changed files
with
1,338 additions
and
889 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"presets": ["next/babel"], | ||
"plugins": [["styled-components", { "ssr": true }], ["@babel/plugin-proposal-optional-chaining"]] | ||
"plugins": [["styled-components", { "ssr": true }], ["@babel/plugin-proposal-optional-chaining"], "macros", "preval"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from "react"; | ||
import Highlight, { defaultProps, Language } from "prism-react-renderer"; | ||
import theme from "prism-react-renderer/themes/nightOwl"; | ||
import Pre from "./Pre"; | ||
|
||
interface CodeBlockProps { | ||
children: React.ReactNode; | ||
className?: string; | ||
} | ||
|
||
const CodeBlock: React.FC<CodeBlockProps> = ({ children, className }) => { | ||
const language = className?.replace(/language-/, ""); | ||
return ( | ||
<Highlight | ||
{...defaultProps} | ||
code={children as string} | ||
language={language as Language} | ||
theme={theme} | ||
> | ||
{({ | ||
className, | ||
style, | ||
tokens, | ||
getLineProps, | ||
getTokenProps | ||
}): React.ReactNode => ( | ||
<Pre className={className} style={{ ...style, padding: "20px" }}> | ||
{tokens.map((line, i) => ( | ||
<div key={i} {...getLineProps({ line, key: i })}> | ||
{line.map((token, key) => ( | ||
<span key={key} {...getTokenProps({ token, key })} /> | ||
))} | ||
</div> | ||
))} | ||
</Pre> | ||
)} | ||
</Highlight> | ||
); | ||
}; | ||
|
||
const InlineCode: React.FC<CodeBlockProps> = ({ children, className }) => { | ||
const language = className?.replace(/language-/, ""); | ||
return ( | ||
<Highlight | ||
{...defaultProps} | ||
code={children as string} | ||
language={language as Language} | ||
theme={theme} | ||
> | ||
{({ | ||
className, | ||
style, | ||
tokens, | ||
getLineProps, | ||
getTokenProps | ||
}): React.ReactNode => ( | ||
<code className={className} style={style}> | ||
{tokens.map((line, i) => ( | ||
<div key={i} {...getLineProps({ line, key: i })}> | ||
{line.map((token, key) => ( | ||
<span key={key} {...getTokenProps({ token, key })} /> | ||
))} | ||
</div> | ||
))} | ||
</code> | ||
)} | ||
</Highlight> | ||
); | ||
}; | ||
|
||
export { CodeBlock, InlineCode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Box } from "rebass/styled-components"; | ||
import styled from "styled-components"; | ||
|
||
export default styled(Box).attrs({ | ||
as: "pre", | ||
p: 3, | ||
mb: 3, | ||
fontSize: "15px" | ||
})` | ||
display: block; | ||
white-space: pre; | ||
white-space: pre-wrap; | ||
word-break: break-all; | ||
word-wrap: break-word; | ||
border-radius: 3px; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
export const meta = { | ||
"published": true, | ||
"publishedAt": "2020-01-12", | ||
"title": "My First Blog", | ||
"summary": "An explanation of how I built this blog as well as why I did it." | ||
} | ||
|
||
## My First Blog | ||
|
||
My reason for starting a blog was simple. I wanted to start a personal side project. | ||
After working for nearly a year (half of that year as intern), I realized that I have | ||
ridden of the high that joining a new job gives and that this was the time to experiment. | ||
|
||
<br /> | ||
|
||
As part of my job, as I googled for answers like we all do, I found some amazing personal | ||
blogs, such as this one by [Dan Abarmov](https://overreacted.io/). Blogs give a place to | ||
express your technical opinions, and also generally improve your long form writing skills. | ||
So I decided to make my first personal project a blog. | ||
|
||
<br /> | ||
|
||
Having decided on building a blog, I started gathering my requirements. This was the list of | ||
things I wanted to do: | ||
- Use TypeScript - According to the [StackOverflow 2019 Survey](https://insights.stackoverflow.com/survey/2019#technology-_-most-loved-dreaded-and-wanted-languages) | ||
TypeScript is one of the most loved languages. I wanted to see what the fuss was all about. | ||
- Use Statically / Server rendered React - We use React at work, and wanted to explore features that I had not used yet. | ||
- Use Styled-Components - Wanted to learn this so that I could use it at work | ||
- Deploy this is a serverless manner. | ||
|
||
### Whatever you want to do, it's almost always solved | ||
|
||
In the case of Statically / Server generated react, there are two main competitors, Next and Gatsby. A quick [google search](https://www.google.com/search?q=next+vs+gatsby) | ||
will show you the pros and cons of each. I went with Next.js primarily because of it's integration with [now.sh](https://zeit.co/home). I achieved serverless deployments | ||
and server rendered react in one go. An especially impressive feature of Next is [Automatic Static Optimization](https://nextjs.org/docs/advanced-features/automatic-static-optimization) | ||
It automatically emits a hydrated React application if you don't use the getInitialProps function. Plus, it helps that it uses PHP like pages directory! | ||
|
||
<br /> | ||
|
||
Having decided to use Next.js, I looked for prior art. I found [Juan Olvera's blog](https://jolvera.dev/) and through that [Max Stoiber's blog](https://mxstbr.com/). | ||
Serendipitously, Max Stoiber is one of the co-founder's of Styled-Components! So I used their code bases as \*ahem\* inspiration, and made my own. | ||
A shoutout to both of them, I would not have a website without their blogs. | ||
|
||
### Things I learned while building this website | ||
|
||
|
||
#### TypeScript and Rebass | ||
TypeScript is worth it, but in larger code bases, or code bases that are likely to evolve. It helps communicate the type of data your component takes | ||
very well and also catches invalid props at compile time, saving a lot of time! However, working on a small blog, I found types just to be a hinderance, | ||
especially with the strict typescript rules to prohibit the any type. And quite frequently, I found the compilation errors next to useless and hard to | ||
debug. I also could not use it on the NodeJS code. At least, not easily. Next.js, TypeScript and Node.js seemed to require conflicting javascript module | ||
systems, which I had learned about just because of this. TypeScript does not support the require syntax, while Node.js demands it. Facing all these issues, | ||
I reverted to javascript for the get-blog-posts.js helper module. | ||
|
||
Another thing to note is that rebass v4.0+ has moved to use Theme-UI, so to use styled-components with rebass, you have to import it like so: | ||
|
||
<br /> | ||
|
||
```javascript | ||
import { Box } from 'rebass/styled-components' | ||
import styled from 'styled-components' | ||
|
||
// Use Box now and style it as you wish | ||
|
||
const StyledBox = styled(Box)` | ||
color='blue'; | ||
` | ||
``` | ||
|
||
Also, to use it with TypeScript, you will have to edit your tsconfig.json file and add the following: | ||
|
||
```json | ||
{ | ||
"baseUrl": ".", | ||
"paths": { | ||
"rebass/styled-components": [ | ||
"node_modules/@types/rebass" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
#### CSS and Design is still hard | ||
|
||
If you look at my website closely (well, you don't really need to look at it closely) you'll find that in terms of styling it's | ||
a mix of the two blogs I've previously mentioned. Styling and design is really hard. Which is probably why nocode tools like | ||
[webflow](https://webflow.com/) are hot right now. CSS Styling seems like an easily automatable task, and soon designers will take | ||
care of it rather then developers. | ||
|
||
|
||
### Features yet to be built | ||
|
||
As I was working on this website, I realized there are somethings that still have to be built to get a proper blog. | ||
- A commenting system. I'll probably have a look at webmention or some other component that can be used. | ||
- A RSS Feed | ||
|
||
<br /> | ||
|
||
I'll be adding these as and when I have time, but my primary focus will be on writing some blog posts! |
Oops, something went wrong.
46d5dc5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: