Skip to content

Commit 43b6804

Browse files
JBurningnekomeowww
andauthored
feat(bi-link): exclude patterns (#458)
* Exclude Patterns for Bi-Directional Links Ads configurable exclude patterns for bi-directional link searching. * Update packages/markdown-it-bi-directional-links/src/index.ts Co-authored-by: Neko <[email protected]> * Update packages/markdown-it-bi-directional-links/src/index.ts Co-authored-by: Neko <[email protected]> * chore: update packages/markdown-it-bi-directional-links/src/index.ts --------- Co-authored-by: Neko <[email protected]>
1 parent e9a94fa commit 43b6804

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

docs/pages/en/integrations/markdown-it-bi-directional-links/getting-started.md

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ interface BiDirectionalLinksOptions {
102102
* @default '*.md, *.png, *.jpg, *.jpeg, *.gif, *.svg, *.webp, *.ico, *.bmp, *.tiff, *.apng, *.avif, *.jfif, *.pjpeg, *.pjp, *.png, *.svg, *.webp, *.xbm'
103103
*/
104104
includesPatterns?: string[]
105+
/**
106+
* Excludes files added from `includePatterns` from being searched if it matches at least one of these patterns.
107+
*
108+
* @default '_*, dist, node_modules'
109+
*/
110+
excludesPatterns?: string[]
105111
/**
106112
* Whether to include debugging logs.
107113
*

docs/pages/zh-CN/integrations/markdown-it-bi-directional-links/getting-started.md

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ interface BiDirectionalLinksOptions {
9898
* @default '*.md, *.png, *.jpg, *.jpeg, *.gif, *.svg, *.webp, *.ico, *.bmp, *.tiff, *.apng, *.avif, *.jfif, *.pjpeg, *.pjp, *.png, *.svg, *.webp, *.xbm'
9999
*/
100100
includesPatterns?: string[]
101+
/**
102+
* Excludes files added from `includePatterns` from being searched if it matches at least one of these patterns.
103+
*
104+
* @default '_*, dist, node_modules'
105+
*/
106+
excludesPatterns?: string[]
101107
/**
102108
* Whether to include debugging logs.
103109
*

packages/markdown-it-bi-directional-links/src/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ export interface BiDirectionalLinksOptions {
192192
* @default '*.md, *.png, *.jpg, *.jpeg, *.gif, *.svg, *.webp, *.ico, *.bmp, *.tiff, *.apng, *.avif, *.jfif, *.pjpeg, *.pjp, *.png, *.svg, *.webp, *.xbm, *.mp3, *.flac, *.wav, *.ogg, *.opus, *.mp4, *.webm, *.acc, *.mp4, *.webm, *.mov, *.mkv, *.ogg'
193193
*/
194194
includesPatterns?: string[]
195+
/**
196+
* Excludes files added from `includePatterns` from being searched if it matches at least one of these patterns.
197+
*
198+
* @default '_*, dist, node_modules'
199+
*/
200+
excludesPatterns?: string[]
195201
/**
196202
* Whether to include debugging logs.
197203
*
@@ -229,12 +235,14 @@ export interface BiDirectionalLinksOptions {
229235
* @param options.dir - The directory to search for bi-directional links.
230236
* @param options.baseDir - The base directory joined as href for bi-directional links.
231237
* @param options.includesPatterns - The glob patterns to search for bi-directional links.
238+
* @param options.excludesPatterns - The glob patterns to exclude files from search.
232239
* @returns A markdown-it plugin.
233240
*/
234241
export const BiDirectionalLinks: (options?: BiDirectionalLinksOptions) => PluginSimple = (options) => {
235242
const rootDir = options?.dir ?? cwd()
236243
const baseDir = options?.baseDir ?? '/'
237244
const includes = options?.includesPatterns ?? []
245+
const excludes = options?.excludesPatterns ?? ['_*', 'dist', 'node_modules']
238246
const debugOn = options?.debug ?? false
239247
const noNoMatchedFileWarning = options?.noNoMatchedFileWarning ?? false
240248
const stillRenderNoMatched = options?.stillRenderNoMatched ?? false
@@ -254,11 +262,7 @@ export const BiDirectionalLinks: (options?: BiDirectionalLinksOptions) => Plugin
254262
onlyFiles: true,
255263
absolute: true,
256264
cwd: rootDir,
257-
ignore: [
258-
'_*',
259-
'dist',
260-
'node_modules',
261-
],
265+
ignore: excludes,
262266
})
263267

264268
for (const file of files) {

0 commit comments

Comments
 (0)