Skip to content

Commit

Permalink
fix: Ignores links in draft pages
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Oct 30, 2024
1 parent b7563c8 commit da925d5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 751 deletions.
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0"
},
"dependencies": {
"@astrojs/starlight": "0.15.0",
"astro": "4.0.4",
"@astrojs/starlight": "0.24.4",
"astro": "4.11.0",
"sharp": "0.32.6",
"starlight-links-validator": "workspace:*"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/starlight-links-validator/libs/remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const remarkStarlightLinksValidator: Plugin<[{ base: string; srcDir: URL
srcDir,
}) {
return (tree, file) => {
if (file.data.astro?.frontmatter?.draft) return

const slugger = new GitHubSlugger()
const filePath = normalizeFilePath(base, srcDir, file.history[0])
const slug = file.data.astro?.frontmatter?.slug
Expand Down Expand Up @@ -193,6 +195,7 @@ declare module 'vfile' {
interface DataMap {
astro?: {
frontmatter?: {
draft?: boolean
slug?: string
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/starlight-links-validator/tests/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('does not build with invalid links', async () => {

expect(status).toBe('error')

expectValidationErrorCount(output, 59, 4)
expectValidationErrorCount(output, 61, 4)

expectValidationErrors(output, 'test/', [
['/https://starlight.astro.build/', ValidationErrorType.InvalidLink],
Expand All @@ -30,6 +30,8 @@ test('does not build with invalid links', async () => {
['/unknown/', ValidationErrorType.InvalidLink],
['/unknown#title', ValidationErrorType.InvalidLink],
['/unknown/#title', ValidationErrorType.InvalidLink],
['/draft', ValidationErrorType.InvalidLink],
['/draft/', ValidationErrorType.InvalidLink],
['#links', ValidationErrorType.InvalidHash],
['/guides/example/#links', ValidationErrorType.InvalidHash],
['/icon.svg', ValidationErrorType.InvalidLink],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Draft
draft: true
---

This is a draft page.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ title: Test
- [Unknown page with hash](/unknown#title)
- [Unknown page with hash](/unknown/#title)

- [Draft page](/draft)
- [Draft page](/draft/)

# More links

- [Link to valid hash in this page](#some-links)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Draft
draft: true
---

This is a draft page.

[Invalid link](/unknown/)
Loading

0 comments on commit da925d5

Please sign in to comment.