Skip to content

Commit

Permalink
Merge pull request #1093 from trillium/ts.lint-tag-data-on-create
Browse files Browse the repository at this point in the history
fix: Lint tag-data.json when regenerated during dev/build step
  • Loading branch information
timlrx authored Jan 14, 2025
2 parents 21635a6 + 38b7d8d commit a5102b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
22 changes: 11 additions & 11 deletions app/tag-data.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"markdown": 1,
"code": 1,
"features": 1,
"next-js": 6,
"tailwind": 3,
"guide": 5,
"feature": 2,
"multi-author": 1,
"hello": 1,
"math": 1,
"ols": 1,
"github": 1,
"guide": 5,
"tailwind": 3,
"hello": 1,
"holiday": 1,
"canada": 1,
"images": 1,
"feature": 2,
"writings": 1,
"book": 1,
"reflection": 1,
"multi-author": 1
"holiday": 1,
"canada": 1,
"images": 1,
"markdown": 1,
"code": 1,
"features": 1
}
6 changes: 4 additions & 2 deletions contentlayer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import rehypePrismPlus from 'rehype-prism-plus'
import rehypePresetMinify from 'rehype-preset-minify'
import siteMetadata from './data/siteMetadata'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer.js'
import prettier from 'prettier'

const root = process.cwd()
const isProduction = process.env.NODE_ENV === 'production'
Expand Down Expand Up @@ -61,7 +62,7 @@ const computedFields: ComputedFields = {
/**
* Count the occurrences of all tags across blog posts and write to json file
*/
function createTagCount(allBlogs) {
async function createTagCount(allBlogs) {
const tagCount: Record<string, number> = {}
allBlogs.forEach((file) => {
if (file.tags && (!isProduction || file.draft !== true)) {
Expand All @@ -75,7 +76,8 @@ function createTagCount(allBlogs) {
})
}
})
writeFileSync('./app/tag-data.json', JSON.stringify(tagCount))
const formatted = await prettier.format(JSON.stringify(tagCount, null, 2), { parser: 'json' })
writeFileSync('./app/tag-data.json', formatted)
}

function createSearchIndex(allBlogs) {
Expand Down

0 comments on commit a5102b8

Please sign in to comment.