Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit bbed044

Browse files
author
Colin McDonnell
committed
Major updates to site
1 parent adc55e5 commit bbed044

File tree

5 files changed

+108
-73
lines changed

5 files changed

+108
-73
lines changed

README.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,30 @@ Just add a Markdown file under `md/blog/` to create a new blog post:
116116

117117
## Google Analytics
118118

119-
Just add your Google Analytics ID (e.g. e.g. 'UA-999999999-1' ) to `globals.ts` and Devii will automatically add the appropriate Google Analytics snippet to your site. Go to `/pages/_app.ts` to see how this works or customize this behavior.
119+
Just add your Google Analytics ID (e.g. 'UA-999999999-1') to `globals.ts` and Devii will automatically add the appropriate Google Analytics snippet to your site. Go to `/pages/_app.ts` to see how this works or customize this behavior.
120120

121121
## Frontmatter support
122122

123-
Every Markdown file can include a "frontmatter block" containing various metadata. This is the frontmatter blog from the sample blog post (`md/blog/test.md`):
123+
Every Markdown file can include a "frontmatter block" containing various metadata. Devii provides a `loadPost` utility that loads a Markdown file, parses it's frontmatter metadata, and returns a structured `PostData` object:
124+
125+
```ts
126+
type PostData = {
127+
path: string;
128+
title?: string;
129+
subtitle?: string;
130+
description?: string; // used for SEO
131+
canonicalUrl?: string; // used for SEO
132+
datePublished?: number; // Unix timestamp
133+
author?: string;
134+
authorPhoto?: string;
135+
authorHandle?: string; // twitter handle
136+
tags?: string[];
137+
bannerPhoto?: string;
138+
thumbnailPhoto?: string;
139+
};
140+
```
141+
142+
For example, here is the frontmatter blog from the sample blog post (`md/blog/the-ultimate-tech-stack.md`):
124143

125144
```
126145
---
@@ -137,23 +156,6 @@ thumbnailPhoto: /brook.jpg
137156
---
138157
```
139158

140-
This metadata will be loaded and parsed into a TypeScript object with the following type.
141-
142-
```ts
143-
type PostData = {
144-
path: string;
145-
title?: string;
146-
subtitle?: string;
147-
content: string;
148-
datePublished?: number;
149-
author?: string;
150-
authorPhoto?: string;
151-
tags?: string[];
152-
bannerPhoto?: string;
153-
thumbnailPhoto?: string;
154-
};
155-
```
156-
157159
View `/loader.ts` to see how this works.
158160

159161
## Medium-inspired design
@@ -204,18 +206,18 @@ export const getStaticProps = async () => {
204206
};
205207
```
206208

207-
There are a few utility functions in `loader.ts` that Devii uses.
209+
There are a few utility functions in `loader.ts` that Devii uses. All functions are _async_! All functions accept a _relative_ path which is expected to be \_relative to the `md/` directory. For instance `loadPost('blog/test.md'`) would load `/md/blog/test.md`.
208210

209-
- `loadPost` loads/parses a Markdown file and returns a `PostData`. It takes on argument, the name of a file in the `md/` directory. For instance `loadPost('about.md')` would load `/md/about.md` and `loadPost('blog/test.md'`) would load `/md/blog/test.md`.
210-
- `loadBlogPosts`: loads/parses all the files in `/md/blog/`. Returns `PostData[]`. Used in `index.tsx` to read a list of all published blog posts.
211-
- `loadMarkdownFile`: loads a Markdown file but doesn't parse it. Returns the string content. Useful if you want to implement certain parts of a page in Markdown and other parts in React.
212-
- `loadMarkdownFiles`: accepts a [glob](https://docs.python.org/3/library/glob.html) pattern and loads all the files inside `/md/` whose names match the pattern. Used internally by `loadBlogPosts`.
211+
- `loadPost` loads/parses a Markdown file and returns a `PostData`
212+
- `loadBlogPosts`: loads/parses all the files in `/md/blog/`. Returns `PostData[]`. Used in `index.tsx` to load/render a list of all published blog posts
213+
- `loadMarkdownFile`: loads a Markdown file but doesn't parse it. Returns the string content. Useful if you want to implement some parts of a page in Markdown and other parts in React
214+
- `loadMarkdownFiles`: accepts a [glob](https://docs.python.org/3/library/glob.html) pattern and loads all the files inside `/md/` whose names match the pattern. Used internally by `loadBlogPosts`
213215

214216
## Static generation
215217

216218
You can generate a fully static version of your site using `yarn build && yarn export`. This step is entirely powered by Next.js. The static site is exported to the `out` directory.
217219

218-
After its generated, use your static file hosting service of choice (Firebase Hosting, Amazon S3, Vercel) to deploy your site.
220+
After it's generated, use your static file hosting service of choice (Vercel, Netlify, Firebase Hosting, Amazon S3) to deploy your site.
219221

220222
## Global configs
221223

loader.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type PostData = {
88
content: string;
99
description?: string;
1010
canonicalUrl?: string;
11+
published: boolean;
1112
datePublished?: number;
1213
author?: string;
1314
authorPhoto?: string;
@@ -31,6 +32,7 @@ export const mdToPost = (file: RawFile): PostData => {
3132
path,
3233
title: metadata.data.title,
3334
subtitle: metadata.data.subtitle || null,
35+
published: metadata.data.published || false,
3436
datePublished: metadata.data.datePublished || null,
3537
tags: metadata.data.tags || null,
3638
description: metadata.data.description || null,

md/blog/dan-abramov.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Dan Abramov knows about Devii
3+
published: true
34
datePublished: 1594425078471
45
author: Colin McDonnell
56
tags:

md/blog/devii.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Devii's killer features
33
subtitle: Bringing the power of React, TypeScript, and static generation to dev blogs everywhere
4+
published: true
45
datePublished: 1589064522569
56
author: Ben Bitdiddle
67
tags:

pages/index.tsx

Lines changed: 77 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,63 @@
11
import Head from 'next/head';
22

3-
import { PostData, loadBlogPosts } from '../loader';
3+
import { PostData, loadBlogPosts, loadMarkdownFile } from '../loader';
44
import { PostCard } from '../components/PostCard';
55
import { generateRSS } from '../rssUtil';
66
import { Markdown } from '../components/Markdown';
77
import { config } from '../globals';
88

9-
const Home = (props: { readme: string; posts: PostData[] }) => {
9+
const sectionStyle = {
10+
width: '100%',
11+
padding: '100px 10vw',
12+
display: 'flex',
13+
flexDirection: 'column',
14+
alignItems: 'center',
15+
} as const;
16+
17+
const pStyle = { lineHeight: 1.7 };
18+
19+
const Home = (props: {
20+
introduction: string;
21+
features: string;
22+
readme: string;
23+
posts: PostData[];
24+
}) => {
1025
return (
1126
<div style={{ width: '100%' }}>
1227
<Head>
1328
<title>Introducing Devii</title>
1429
<link rel="icon" href="/favicon.ico" />
1530
</Head>
16-
<div style={{ maxWidth: '400px', margin: 'auto', padding: '50px 0px' }}>
17-
<h3>Welcome to Devii</h3>
18-
<p style={{ padding: '10px 0px', color: '#666666' }}>
19-
This site is entirely built with Devii! In fact, the{' '}
20-
<a href="https://github.com/vriad/devii">Devii repo</a> contains the
21-
code for the site you're looking at now.
22-
</p>
23-
<p style={{ padding: '10px 0px', color: '#666666' }}>
24-
After you clone/fork it, you can use this code to learn how Devii
25-
works. Then you can rip out everything you don't like, customize
26-
everything else, and build your own tools and components on top of the
27-
foundation Devii provides.
28-
</p>
29-
<p style={{ padding: '10px 0px', color: '#666666' }}>
30-
Your personal website is the online manifestation of you. Devii
31-
doesn't really provide much out of the box. It provides some nice
32-
Medium-style default styles for your blog posts and some tools for
33-
loading/rendering Markdown. But you'll have to implement your own
34-
homepage more or less from scratch. And that's the point! Don't settle
35-
for some theme. Build something that represents you.
36-
</p>
31+
<div style={{ maxWidth: '500px', margin: 'auto', padding: '50px 0px' }}>
32+
<Markdown source={props.introduction} />
3733
</div>
38-
<div style={{ width: '100%', padding: '100px 10vw' }}>
34+
<div style={sectionStyle}>
35+
<h2 style={{ margin: '4px 0px', fontSize: '34pt' }}>Features</h2>
36+
<div style={{ maxWidth: '600px' }}>
37+
<Markdown source={props.features} />
38+
</div>
39+
</div>
40+
<div style={sectionStyle}>
41+
<h2 style={{ margin: '4px 0px', fontSize: '34pt' }}>My blog posts</h2>
42+
<p style={{ maxWidth: '600px', paddingBottom: '30px', ...pStyle }}>
43+
This section demonstrates the power of dynamic imports. Every Markdown
44+
file under <code>/md/blog</code> is automatically parsed into a
45+
structured TypeScript object and available in the `props.posts` array.
46+
These blog post "cards" are implemented in the
47+
`/components/PostCard.tsx` component.
48+
</p>
3949
<div
4050
style={{
41-
display: 'flex',
42-
flexDirection: 'column',
43-
alignItems: 'center',
51+
display: 'grid',
52+
gridTemplateColumns: `repeat(auto-fit, minmax(300px,1fr))`,
53+
gridRowGap: '8px',
54+
gridColumnGap: '8px',
4455
width: '100%',
4556
}}
4657
>
47-
<h2 style={{ margin: '4px 0px', fontSize: '34pt' }}>My blog posts</h2>
48-
<p>
49-
Any new markdown file under <code>/md/blog</code> will automatically
50-
appear here.
51-
</p>
52-
<div
53-
style={{
54-
display: 'grid',
55-
gridTemplateColumns: `repeat(auto-fit, minmax(300px,1fr))`,
56-
gridRowGap: '8px',
57-
gridColumnGap: '8px',
58-
width: '100%',
59-
}}
60-
>
61-
{props.posts.map((post, j) => {
62-
return <PostCard post={post} key={j} />;
63-
})}
64-
</div>
58+
{props.posts.map((post, j) => {
59+
return <PostCard post={post} key={j} />;
60+
})}
6561
</div>
6662
</div>
6763

@@ -96,10 +92,22 @@ const Home = (props: { readme: string; posts: PostData[] }) => {
9692

9793
<div style={{ width: '100%', margin: '100px 0px' }}>
9894
<h2 style={{ textAlign: 'center', fontSize: '34pt' }}>README.md</h2>
99-
<p style={{ textAlign: 'center', maxWidth: '600px', margin: 'auto' }}>
95+
<p
96+
style={{
97+
textAlign: 'center',
98+
maxWidth: '600px',
99+
margin: 'auto',
100+
...pStyle,
101+
}}
102+
>
100103
Below is the README.md for devii. It was imported and rendered using
101104
Next.js dynamic imports. The rest of this page (including this
102-
paragraph) are rendered with React. 🎉
105+
paragraph) are rendered with React. You can also read the README on
106+
GitHub at{' '}
107+
<a href="https://github.com/vriad/devii">
108+
https://github.com/vriad/devii
109+
</a>
110+
.
103111
</p>
104112
</div>
105113
<div
@@ -118,12 +126,33 @@ const Home = (props: { readme: string; posts: PostData[] }) => {
118126
<Markdown source={props.readme} />
119127
</div>
120128
</div>
129+
<div style={sectionStyle}>
130+
<h2
131+
style={{ margin: '4px 0px', fontSize: '22pt', paddingBottom: '30px' }}
132+
>
133+
Get started
134+
</h2>
135+
<button
136+
style={{
137+
padding: '10px 30px',
138+
backgroundColor: config.accentColor,
139+
color: 'white',
140+
fontSize: '14pt',
141+
border: 'none',
142+
borderRadius: '10px',
143+
}}
144+
>
145+
Fork Devii on GitHub
146+
</button>
147+
</div>
121148
</div>
122149
);
123150
};
124151
export default Home;
125152

126153
export const getStaticProps = async () => {
154+
const introduction = await loadMarkdownFile('introduction.md');
155+
const features = await loadMarkdownFile('features.md');
127156
const readmeFile = await import(`../${'README.md'}`);
128157
const readme = readmeFile.default;
129158

@@ -133,6 +162,6 @@ export const getStaticProps = async () => {
133162
// during build step.
134163
await generateRSS(posts);
135164

136-
const props = { readme, posts };
165+
const props = { introduction, features, readme, posts };
137166
return { props };
138167
};

0 commit comments

Comments
 (0)