Skip to content

Commit dbc4bb0

Browse files
committed
added husky, fixed lint error
1 parent c0422bf commit dbc4bb0

File tree

5 files changed

+219
-16
lines changed

5 files changed

+219
-16
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn lint-staged

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
"preview": "astro preview",
1414
"lint": "eslint .",
1515
"lint:fix": "eslint --fix .",
16-
"format": "prettier --write ."
16+
"format": "prettier --write .",
17+
"prepare": "husky"
18+
},
19+
"lint-staged": {
20+
"*.{js,ts,astro}": "eslint --fix",
21+
"*": "prettier --write --ignore-unknown"
1722
},
1823
"engines": {
1924
"node": ">=22.0.0"
@@ -33,6 +38,8 @@
3338
"@types/node": "^25.3.3",
3439
"eslint": "^10.0.2",
3540
"eslint-plugin-astro": "^1.6.0",
41+
"husky": "^9.1.7",
42+
"lint-staged": "^16.3.2",
3643
"prettier": "^3.8.1",
3744
"prettier-plugin-astro": "^0.14.1",
3845
"typescript": "^5.9.3",

src/components/ReadNext.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ for (const post of [prevPost, nextPost]) {
3838
<div class="read-next-inner">
3939
<h3 class="read-next-heading">Read Next</h3>
4040
<div class="read-next-feed">
41-
{cards.map(post => <PostCard post={post} />)}
41+
{cards.map(post => (
42+
<PostCard post={post} />
43+
))}
4244
</div>
4345
</div>
4446
</aside>

src/pages/posts/[...slug].astro

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ export async function getStaticPaths() {
1414
const prev = index > 0 ? sorted[index - 1] : null;
1515
const next = index < sorted.length - 1 ? sorted[index + 1] : null;
1616
const currentTags = post.data.tags ?? [];
17-
const relatedPosts = currentTags.length > 0
18-
? sorted
19-
.filter(p => p.id !== post.id && p.data.tags?.some(t => currentTags.includes(t)))
20-
.map(p => ({
21-
post: p,
22-
overlap: p.data.tags!.filter(t => currentTags.includes(t)).length,
23-
}))
24-
.sort((a, b) => b.overlap - a.overlap || b.post.data.date.valueOf() - a.post.data.date.valueOf())
25-
.map(r => r.post)
26-
: [];
17+
const relatedPosts =
18+
currentTags.length > 0
19+
? sorted
20+
.filter(p => p.id !== post.id && p.data.tags?.some(t => currentTags.includes(t)))
21+
.map(p => ({
22+
post: p,
23+
overlap: (p.data.tags ?? []).filter(t => currentTags.includes(t)).length,
24+
}))
25+
.sort(
26+
(a, b) =>
27+
b.overlap - a.overlap || b.post.data.date.valueOf() - a.post.data.date.valueOf(),
28+
)
29+
.map(r => r.post)
30+
: [];
2731
const authorData = post.data.author
2832
.map(authorId => authors.find(a => a.data.id === authorId)?.data)
2933
.filter(Boolean);

0 commit comments

Comments
 (0)