-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
48 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'next-validate-link': patch | ||
--- | ||
|
||
parse frontmatter only with files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
export async function checkExternalUrl(url: string): Promise<boolean> { | ||
import type { ErrorReason } from './validate'; | ||
|
||
export async function checkExternalUrl( | ||
url: string, | ||
): Promise<ErrorReason | undefined> { | ||
const parsed = new URL(url); | ||
if (parsed.hostname === 'localhost') return true; | ||
if (parsed.hostname === 'localhost') return; | ||
|
||
const res = await fetch(parsed, { | ||
method: 'HEAD', | ||
}).catch(() => undefined); | ||
|
||
if (!res) return false; | ||
if (!res) return 'not-found'; | ||
|
||
if (!res.ok) { | ||
if (res.status === 404) return false; | ||
if (res.status === 404) return 'not-found'; | ||
|
||
console.warn(`${url} responded status ${res.status}, is it expected?`); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
import path from 'node:path'; | ||
import fs from 'node:fs/promises'; | ||
import FastGlob, { type Pattern } from 'fast-glob'; | ||
import type { FileObject } from './validate'; | ||
import matter from 'gray-matter'; | ||
|
||
export async function readFileFromPath(file: string) { | ||
export async function readFileFromPath(file: string): Promise< | ||
FileObject & { | ||
data?: object; | ||
} | ||
> { | ||
const content = await fs | ||
.readFile(path.resolve(file)) | ||
.then((res) => res.toString()); | ||
|
||
const parsed = matter(content); | ||
|
||
return { | ||
path: file, | ||
content: content, | ||
data: parsed.data, | ||
content: parsed.content, | ||
}; | ||
} | ||
|
||
export async function readFiles( | ||
patterns: Pattern | Pattern[], | ||
): Promise<FileObject[]> { | ||
const files = await FastGlob(patterns); | ||
|
||
return await Promise.all(files.map(readFileFromPath)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters