Skip to content

Commit a5102b8

Browse files
authored
Merge pull request #1093 from trillium/ts.lint-tag-data-on-create
fix: Lint tag-data.json when regenerated during dev/build step
2 parents 21635a6 + 38b7d8d commit a5102b8

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

app/tag-data.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"markdown": 1,
3-
"code": 1,
4-
"features": 1,
52
"next-js": 6,
3+
"tailwind": 3,
4+
"guide": 5,
5+
"feature": 2,
6+
"multi-author": 1,
7+
"hello": 1,
68
"math": 1,
79
"ols": 1,
810
"github": 1,
9-
"guide": 5,
10-
"tailwind": 3,
11-
"hello": 1,
12-
"holiday": 1,
13-
"canada": 1,
14-
"images": 1,
15-
"feature": 2,
1611
"writings": 1,
1712
"book": 1,
1813
"reflection": 1,
19-
"multi-author": 1
14+
"holiday": 1,
15+
"canada": 1,
16+
"images": 1,
17+
"markdown": 1,
18+
"code": 1,
19+
"features": 1
2020
}

contentlayer.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import rehypePrismPlus from 'rehype-prism-plus'
2424
import rehypePresetMinify from 'rehype-preset-minify'
2525
import siteMetadata from './data/siteMetadata'
2626
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer.js'
27+
import prettier from 'prettier'
2728

2829
const root = process.cwd()
2930
const isProduction = process.env.NODE_ENV === 'production'
@@ -61,7 +62,7 @@ const computedFields: ComputedFields = {
6162
/**
6263
* Count the occurrences of all tags across blog posts and write to json file
6364
*/
64-
function createTagCount(allBlogs) {
65+
async function createTagCount(allBlogs) {
6566
const tagCount: Record<string, number> = {}
6667
allBlogs.forEach((file) => {
6768
if (file.tags && (!isProduction || file.draft !== true)) {
@@ -75,7 +76,8 @@ function createTagCount(allBlogs) {
7576
})
7677
}
7778
})
78-
writeFileSync('./app/tag-data.json', JSON.stringify(tagCount))
79+
const formatted = await prettier.format(JSON.stringify(tagCount, null, 2), { parser: 'json' })
80+
writeFileSync('./app/tag-data.json', formatted)
7981
}
8082

8183
function createSearchIndex(allBlogs) {

0 commit comments

Comments
 (0)