Skip to content

Commit cc9332c

Browse files
author
wutali
committed
Clean up project
1 parent 91cd566 commit cc9332c

18 files changed

+116
-82
lines changed

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
# Next.js blog template for Netlify
22

3-
This is a boilerplate for building blogs with only Netlify stacks.
3+
This is a boilerplate for building blogs with only Netlify stacks.
44

55
There are some boilerplate for the combination of Next.js and Netlify on GitHub.
66
These boilerplate have good document and good tutorial to get started Next.js and Netlify easily
7-
but they are too simple if the blog having common features has needed.
7+
but they are too simple if the blog having common features has needed.
88

9-
Next.js blog template for Netlify has already implemented these common features for building
9+
Next.js blog template for Netlify has already implemented these common features for building
1010
blogs with only using Next.js and Netlify stacks.
1111

1212
## Features
1313

14-
* Full-text search:
15-
* Categorization & Tagging:
16-
* Author:
17-
* Pagination:
18-
* CMS:
14+
- Full-text search:
15+
- Tagging:
16+
- Author:
17+
- Pagination:
18+
- CMS:
19+
- Selectable post layout:
20+
- Social metadata:
1921

2022
## Dependencies
2123

22-
* TypeScript:
23-
* Next.js:
24-
* Netlify:
24+
- TypeScript:
25+
- Next.js:
26+
- Netlify:
27+
- MDX:
28+
29+
## Getting started
2530

2631
## Usage
32+
2733
### Modify content by Netlify CMS
34+
2835
### Enable Netlify Large Media to handle large files
36+
2937
### Preview content before it's released
3038

3139
## Customization
3240

33-
## Sources
41+
### Define category metadata
42+
43+
### Add new layout for each post page
44+
45+
### Localize CMS
46+
47+
## Sources

authors.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"url": "https://wutali-nextjs-netlify-blog.netlify.app/",
3+
"site_title": "Next.js Netlify Blog",
4+
"site_description": "Next.js blog template for Netlify",
5+
"posts_per_page": 5
6+
}

global.d.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
declare module 'remark-html' {
2-
const html: any
3-
export default html
1+
declare module "*.svg" {
2+
import * as React from "react";
3+
4+
export const ReactComponent: React.FunctionComponent<React.SVGProps<
5+
SVGSVGElement
6+
>>;
7+
8+
export default ReactComponent;
9+
}
10+
11+
declare module "*.json" {
12+
const value: any;
13+
export default value;
14+
}
15+
16+
declare module "*.yml" {
17+
const value: any;
18+
export default value;
419
}

meta/authors.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
authors:
2+
- slug: wutali
3+
name: Takahiro Fujiwara
4+
introduction:
5+
Co-founder and CTO at Fuller, Inc. / Software & Data Engineer /
6+
Python / Golang / React

tags.yml renamed to meta/tags.yml

File renamed without changes.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"next-mdx-enhanced": "^3.1.0",
1919
"normalize.css": "^8.0.1",
2020
"react": "16.13.1",
21-
"react-dom": "16.13.1",
22-
"remark": "^12.0.0",
23-
"remark-html": "^11.0.1"
21+
"react-dom": "16.13.1"
2422
},
2523
"devDependencies": {
2624
"@types/jest": "^26.0.9",

public/admin/config.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ media_folder: public/images
55
public_folder: images
66

77
collections:
8-
- name: "settings"
9-
label: "Settings"
8+
- name: "config"
9+
label: "Config"
1010
delete: false
1111
editor:
1212
preview: false
1313
files:
1414
- name: "general"
15-
label: "Site Settings"
16-
file: "settings.yml"
15+
label: "Site Config"
16+
file: "config.json"
1717
description: "General site settings"
1818
fields:
1919
- label: "URL"
@@ -38,24 +38,28 @@ collections:
3838
files:
3939
- name: "authors"
4040
label: "Authors"
41-
file: "authors.yml"
41+
file: "meta/authors.yml"
4242
description: "Author descriptions"
4343
fields:
4444
- name: authors
4545
label: Authors
4646
label_singular: "Author"
4747
widget: list
4848
fields:
49+
- label: "Slug"
50+
name: "slug"
51+
widget: "string"
52+
hint: "The part of a URL identifies the author"
4953
- label: "Name"
5054
name: "name"
5155
widget: "string"
5256
hint: "First and Last"
53-
- label: "Description"
54-
name: "description"
55-
widget: "markdown"
57+
- label: "Introduction"
58+
name: "introduction"
59+
widget: "text"
5660
- name: "tags"
5761
label: "Tags"
58-
file: "tags.yml"
62+
file: "meta/tags.yml"
5963
description: "List of tags"
6064
fields:
6165
- name: tags

settings.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/components/Layout.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Head from "next/head";
22
import Navigation from "./Navigation";
3-
import settings from "../lib/settings";
3+
import config from "../lib/config";
44

55
type Props = {
66
children: React.ReactNode;
@@ -10,14 +10,14 @@ export default function Layout({ children }: Props) {
1010
<div className="root">
1111
<Head>
1212
<meta charSet="utf-8" />
13-
<title>{settings.site_title}</title>
14-
<meta name="description" content={settings.site_description} />
13+
<title>{config.site_title}</title>
14+
<meta name="description" content={config.site_description} />
1515
<meta name="viewport" content="width=device-width, initial-scale=1" />
1616

17-
<meta property="og:title" content={settings.site_title} />
17+
<meta property="og:title" content={config.site_title} />
1818
<meta property="og:type" content="website" />
19-
<meta property="og:url" content={settings.url} />
20-
<meta property="og:image" content={settings.url + "/og_image.png"} />
19+
<meta property="og:url" content={config.url} />
20+
<meta property="og:image" content={config.url + "/og_image.png"} />
2121

2222
<link rel="manifest" href="/site.webmanifest" />
2323
<link rel="apple-touch-icon" href="/icon.png" />

src/lib/authors.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
import authors from "../../meta/authors.yml";
2+
3+
export type AuthorContent = {
4+
readonly slug: string;
5+
readonly name: string;
6+
readonly introduction: string;
7+
};
8+
9+
const authorMap: { [key: string]: AuthorContent } = generateAuthorMap();
10+
11+
function generateAuthorMap(): { [key: string]: AuthorContent } {
12+
let result: { [key: string]: AuthorContent } = {};
13+
for (const author of authors.authors) {
14+
result[author.slug] = author;
15+
}
16+
return result;
17+
}
18+
119
export function getAuthor(slug: string) {
2-
// TODO: Impl.
20+
return authorMap[slug];
321
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
type Settings = {
1+
import config from "../../config.json";
2+
3+
type Config = {
24
readonly url: string;
35
readonly site_title: string;
46
readonly site_description: string;
57
readonly posts_per_page: number;
68
};
79

8-
const settings = require("../../settings.yml") as Settings;
9-
10-
export default settings;
10+
export default config as Config;

src/lib/tags.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const tags = require("../../tags.yml").tags;
1+
import tags from "../../meta/tags.yml";
22

33
export type TagContent = {
44
readonly slug: string;
@@ -9,7 +9,7 @@ const tagMap: { [key: string]: TagContent } = generateTagMap();
99

1010
function generateTagMap(): { [key: string]: TagContent } {
1111
let result: { [key: string]: TagContent } = {};
12-
for (const tag of tags) {
12+
for (const tag of tags.tags) {
1313
result[tag.slug] = tag;
1414
}
1515
return result;
@@ -20,5 +20,5 @@ export function getTag(slug: string) {
2020
}
2121

2222
export function listTags(): TagContent[] {
23-
return tags;
23+
return tags.tags;
2424
}

src/pages/posts/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GetStaticProps } from "next";
33
import { listPostContent, PostContent, countPosts } from "../../lib/posts";
44
import PostList from "../../components/PostList";
55
import { TagContent, listTags } from "../../lib/tags";
6-
import settings from "../../lib/settings";
6+
import config from "../../lib/config";
77

88
type Props = {
99
posts: PostContent[];
@@ -22,11 +22,11 @@ export default function Index({ posts, tags, pagination }: Props) {
2222
}
2323

2424
export const getStaticProps: GetStaticProps = async () => {
25-
const posts = listPostContent(1, settings.posts_per_page);
25+
const posts = listPostContent(1, config.posts_per_page);
2626
const tags = listTags();
2727
const pagination = {
2828
current: 1,
29-
pages: Math.ceil(countPosts() / settings.posts_per_page),
29+
pages: Math.ceil(countPosts() / config.posts_per_page),
3030
};
3131
return {
3232
props: {

src/pages/posts/page/[page].tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Layout from "../../../components/Layout";
33
import PostList from "../../../components/PostList";
44
import { countPosts, listPostContent, PostContent } from "../../../lib/posts";
55
import { listTags, TagContent } from "../../../lib/tags";
6-
import settings from "../../../lib/settings";
6+
import config from "../../../lib/config";
77

88
type Props = {
99
posts: PostContent[];
@@ -23,11 +23,11 @@ export default function Page({ posts, tags, pagination }: Props) {
2323

2424
export const getStaticProps: GetStaticProps = async ({ params }) => {
2525
const current = parseInt(params.page as string);
26-
const posts = listPostContent(current, settings.posts_per_page);
26+
const posts = listPostContent(current, config.posts_per_page);
2727
const tags = listTags();
2828
const pagination = {
2929
current: current,
30-
pages: Math.ceil(countPosts() / settings.posts_per_page),
30+
pages: Math.ceil(countPosts() / config.posts_per_page),
3131
};
3232
return {
3333
props: {
@@ -39,7 +39,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
3939
};
4040

4141
export const getStaticPaths: GetStaticPaths = async () => {
42-
const pages = Math.ceil(countPosts() / settings.posts_per_page);
42+
const pages = Math.ceil(countPosts() / config.posts_per_page);
4343
const paths = Array.from(Array(pages - 1).keys()).map((it) => ({
4444
params: { page: (it + 2).toString() },
4545
}));

src/pages/posts/tags/[[...slug]].tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Layout from "../../../components/Layout";
33
import { GetStaticProps, GetStaticPaths } from "next";
44
import { listPostContent, PostContent, countPosts } from "../../../lib/posts";
55
import { listTags, getTag, TagContent } from "../../../lib/tags";
6-
import settings from "../../../lib/settings";
6+
import config from "../../../lib/config";
77

88
type Props = {
99
posts: PostContent[];
@@ -26,13 +26,13 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
2626
const [slug, current] = [queries[0], queries[1]];
2727
const posts = listPostContent(
2828
current ? parseInt(current as string) : 1,
29-
settings.posts_per_page,
29+
config.posts_per_page,
3030
slug
3131
);
3232
const tag = getTag(slug);
3333
const pagination = {
3434
current: current ? parseInt(current as string) : 1,
35-
pages: Math.ceil(countPosts(slug) / settings.posts_per_page),
35+
pages: Math.ceil(countPosts(slug) / config.posts_per_page),
3636
};
3737
return {
3838
props: {
@@ -45,7 +45,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
4545

4646
export const getStaticPaths: GetStaticPaths = async () => {
4747
const paths = listTags().flatMap((tag) => {
48-
const pages = Math.ceil(countPosts(tag.slug) / settings.posts_per_page);
48+
const pages = Math.ceil(countPosts(tag.slug) / config.posts_per_page);
4949
return Array.from(Array(pages).keys()).map((page) =>
5050
page === 0
5151
? {

tsconfig.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": [
5-
"dom",
6-
"dom.iterable",
7-
"esnext"
8-
],
4+
"lib": ["dom", "dom.iterable", "esnext"],
95
"allowJs": true,
106
"skipLibCheck": true,
117
"strict": false,
@@ -18,12 +14,6 @@
1814
"isolatedModules": true,
1915
"jsx": "preserve"
2016
},
21-
"exclude": [
22-
"node_modules"
23-
],
24-
"include": [
25-
"next-env.d.ts",
26-
"**/*.ts",
27-
"**/*.tsx"
28-
]
17+
"exclude": ["node_modules"],
18+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
2919
}

typing.d.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)