Skip to content

Commit 419e1a5

Browse files
committed
microcms-js-sdkを使った実装に変更
1 parent c729966 commit 419e1a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1124
-4954
lines changed

.eslintrc.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ module.exports = {
77
extends: [
88
'eslint:recommended',
99
'plugin:@typescript-eslint/recommended',
10-
'next',
1110
'next/core-web-vitals',
1211
// 競合を避けるため、prettierは一番最後に書く
13-
'plugin:prettier/recommended',
12+
'prettier',
1413
],
1514
globals: {
1615
Atomics: 'readonly',
@@ -37,24 +36,11 @@ module.exports = {
3736
},
3837
plugins: [],
3938
rules: {
40-
// prettier の設定
41-
'prettier/prettier': [
42-
'error',
43-
{
44-
trailingComma: 'es5',
45-
tabWidth: 2,
46-
semi: false,
47-
singleQuote: true,
48-
printWidth: 120,
49-
},
50-
],
5139
// React Hooks のための設定
5240
'react-hooks/rules-of-hooks': 'error',
5341
'react-hooks/exhaustive-deps': 'warn',
5442
// prop types を使っていないので off
5543
'react/prop-types': 'off',
56-
// Next.js では React を import しなくてもよいので off にする
57-
'react/react-in-jsx-scope': 'off',
5844
// 関数の引数や返り値に必ず型をつけるルールを off にする
5945
// アプリケーションをより堅牢にしたい場合は、このルールを on にしてください
6046
'@typescript-eslint/explicit-module-boundary-types': 'off',

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 公式microCMSブログ
1+
# 公式 microCMS ブログ
22

33
サイト: https://blog.microcms.io/
44
ソースコード: https://github.com/wantainc/microcms-blog
@@ -111,22 +111,22 @@ type: オブジェクト形式
111111

112112
## 環境変数
113113

114-
プロジェクトルートに`.env.local`ファイルを作成し、以下の項目を設定してください。
114+
プロジェクトルートに`.env`ファイルを作成し、以下の項目を設定してください。
115115

116-
- API_KEY(microCMS の API キー)
117-
- SERVICE_ID(microCMS のサービス ID)
116+
- NEXT_PUBLIC_API_KEY(microCMS の API キー)
117+
- NEXT_PUBLIC_SERVICE_ID(microCMS のサービス ID)
118118
- NEXT_PUBLIC_GOOGLE_ANALYTICS_ID(Google Analytics の ID)
119119
- NEXT_PUBLIC_SITE_URL
120120
- NEXT_PUBLIC_BASE_PATH(BasePath が'/'なら空白で大丈夫です)
121121

122122
例:
123123

124-
```
124+
```env
125125
API_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
126126
SERVICE_ID=your-service-id
127127
NEXT_PUBLIC_GOOGLE_ANALYTICS_ID=G-xxxxxxxxxx
128128
NEXT_PUBLIC_SITE_URL=https://blog.microcms.io
129-
NEXT_PUBLIC_BASE_PATH=/test
129+
NEXT_PUBLIC_BASE_PATH=/test(or NEXT_PUBLIC_BASE_PATH=)
130130
```
131131

132132
## 開発方法

aspida.config.js

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

jest.config.js

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

next-env.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/// <reference types="next" />
2-
/// <reference types="next/types/global" />
32
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

next.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
const withPlugins = require('next-compose-plugins')
21
const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true' })
32

43
const basePath = process.env.NEXT_PUBLIC_BASE_PATH
54

6-
module.exports = withPlugins([[withBundleAnalyzer]], {
5+
module.exports = withBundleAnalyzer({
76
reactStrictMode: true,
8-
future: {
9-
strictPostcssConfiguration: true,
10-
},
117
basePath,
128
trailingSlash: true,
139
images: {
1410
loader: 'imgix',
1511
path: '',
1612
},
13+
eslint: {
14+
dirs: ['pages', 'src'],
15+
},
1716
})

package.json

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
"analyze": "ANALYZE=true yarn build",
77
"dev": "run-p dev:*",
88
"dev:next": "next dev",
9-
"dev:path": "pathpida --watch",
10-
"dev:api": "aspida --watch",
11-
"build": "pathpida && aspida && next build",
9+
"dev:path": "pathpida --output src/utils --watch",
10+
"build": "pathpida --output src/utils && next build",
1211
"start": "next start",
13-
"test": "jest",
1412
"fix": "prettier --write './**/*.{js,jsx,ts,tsx}'",
1513
"lint-staged": "lint-staged",
1614
"lint": "next lint",
@@ -25,50 +23,38 @@
2523
]
2624
},
2725
"dependencies": {
28-
"@aspida/axios": "1.7.1",
29-
"axios": "0.21.1",
30-
"dayjs": "1.10.6",
31-
"highlight.js": "11.2.0",
32-
"microcms-richedit-processer": "1.0.3",
33-
"next": "11.0.1",
26+
"dayjs": "1.10.7",
27+
"highlight.js": "11.4.0",
28+
"microcms-js-sdk": "2.0.0",
29+
"microcms-richedit-processer": "1.0.4",
30+
"next": "12.0.8",
3431
"react": "17.0.2",
3532
"react-dom": "17.0.2",
36-
"react-scroll": "1.8.3",
37-
"react-use": "17.2.4",
33+
"react-scroll": "1.8.4",
34+
"react-use": "17.3.2",
3835
"rss": "1.2.2",
39-
"swr": "0.5.6"
36+
"swr": "1.1.2"
4037
},
4138
"devDependencies": {
42-
"@babel/core": "7.15.0",
43-
"@next/bundle-analyzer": "11.0.1",
44-
"@testing-library/jest-dom": "5.14.1",
45-
"@testing-library/react": "12.0.0",
46-
"@testing-library/react-hooks": "7.0.1",
47-
"@types/react": "17.0.17",
39+
"@next/bundle-analyzer": "12.0.8",
40+
"@types/prettier": "^2.4.3",
41+
"@types/react": "17.0.38",
4842
"@types/react-scroll": "1.8.3",
4943
"@types/rss": "0.0.29",
50-
"@typescript-eslint/eslint-plugin": "4.29.1",
51-
"@typescript-eslint/parser": "4.29.1",
52-
"babel-jest": "27.0.6",
53-
"dotenv": "10.0.0",
54-
"eslint": "7.32.0",
55-
"eslint-config-next": "11.0.1",
44+
"@typescript-eslint/eslint-plugin": "5.10.0",
45+
"@typescript-eslint/parser": "5.10.0",
46+
"eslint": "8.7.0",
47+
"eslint-config-next": "12.0.8",
5648
"eslint-config-prettier": "8.3.0",
57-
"eslint-plugin-prettier": "3.4.0",
58-
"globby": "11.0.4",
59-
"husky": "7.0.1",
60-
"jest": "27.0.6",
61-
"jest-watch-typeahead": "0.6.4",
62-
"lint-staged": "11.1.2",
63-
"next-compose-plugins": "2.2.1",
64-
"next-transpile-modules": "8.0.0",
49+
"eslint-plugin-prettier": "4.0.0",
50+
"husky": "7.0.4",
51+
"lint-staged": "12.2.2",
6552
"npm-run-all": "4.1.5",
66-
"pathpida": "0.15.4",
67-
"postcss": "8.3.6",
68-
"postcss-custom-properties": "11.0.0",
53+
"pathpida": "0.17.0",
54+
"postcss": "8.4.5",
55+
"postcss-custom-properties": "12.1.3",
6956
"postcss-nested": "5.0.6",
70-
"prettier": "2.3.2",
71-
"react-test-renderer": "17.0.2",
72-
"typescript": "4.3.5"
57+
"prettier": "2.5.1",
58+
"typescript": "4.5.5"
7359
}
7460
}

pages/[slug].tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import Head from 'next/head'
44

55
import { BlogDetailLayout } from '~/src/components/BlogDetailLayout'
66
import { BlogDetailLayoutProps } from '~/src/components/BlogDetailLayout/BlogDetailLayout'
7-
import { apiClient } from '~/src/utils/apiClient'
8-
import { getContents } from '~/src/utils/getContents'
97
import { DESCRIPTION, OG_DESCRIPTION, OG_IMAGE, OG_TITLE, returnTitle } from '~/src/utils/meta'
10-
import { headers } from '~/src/utils/microCMSHeaders'
8+
import { getBlog, getGlobalContents } from '~/src/utils/microCMS/getContents'
119

1210
export const getAllSlugPaths = async () => {
13-
const { contents } = await getContents()
11+
const { contents } = await getGlobalContents()
1412
const paths = contents.map((content) => ({
1513
params: {
1614
slug: content.id,
@@ -42,14 +40,11 @@ export const getStaticProps: GetStaticProps<Props> = async ({ params, preview, p
4240
if (params === undefined || typeof params.slug !== 'string')
4341
throw Error('pagesのディレクトリ構造かファイル名が間違っています。')
4442

45-
const contents = await getContents()
46-
const content = await apiClient.blog._slug(params.slug).$get({
47-
headers,
48-
query: {
49-
depth: 2,
50-
draftKey: preview ? (previewData as { [key: string]: string }).draftKey : undefined,
51-
},
52-
})
43+
const contents = await getGlobalContents()
44+
const content = await getBlog({
45+
depth: 2,
46+
draftKey: preview ? (previewData as { [key: string]: string }).draftKey : undefined,
47+
})(params.slug)
5348
const { body, toc } = await processingDom(content.body)
5449
content.body = body
5550

pages/api/preview.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NextApiRequest, NextApiResponse } from 'next'
22

3-
import { apiClient } from '~/src/utils/apiClient'
4-
import { headers } from '~/src/utils/microCMSHeaders'
3+
import { getBlog } from '~/src/utils/microCMS/getContents'
54

65
const preview = async (req: NextApiRequest, res: NextApiResponse) => {
76
const { draftKey, slug } = req.query
@@ -10,7 +9,7 @@ const preview = async (req: NextApiRequest, res: NextApiResponse) => {
109
return
1110
}
1211

13-
const data = await apiClient.blog._slug(slug).$get({ headers, query: { fields: 'id', draftKey } })
12+
const data = await getBlog({ fields: 'id', draftKey })(slug)
1413

1514
if (!data) {
1615
return res.status(401).json({ message: 'Invalid slug' })

pages/api/search.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import type { NextApiRequest, NextApiResponse } from 'next'
22

3-
import { Methods } from '~/src/api/blog'
4-
import { apiClient } from '~/src/utils/apiClient'
5-
import { headers } from '~/src/utils/microCMSHeaders'
3+
import { getBlogs } from '~/src/utils/microCMS/getContents'
64

7-
type Data = Methods['get']['resBody']
8-
9-
const search = async (req: NextApiRequest, res: NextApiResponse<Data>) => {
5+
const search = async (req: NextApiRequest, res: NextApiResponse) => {
106
if (typeof req.query.q !== 'string') {
117
res.status(404).end()
128
return
139
}
1410

15-
const data = await apiClient.blog.$get({
16-
headers,
17-
query: {
18-
q: req.query.q,
19-
},
11+
const data = await getBlogs({
12+
q: req.query.q,
2013
})
2114

2215
res.status(200).json({ ...data })

0 commit comments

Comments
 (0)