Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit8ae8568

Browse files
committed
feat: Combine customBlocks inclusion/exclusion option
1 parent5c1dffb commit8ae8568

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

‎src/index.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,14 @@ export interface VuePluginOptions {
5757
[key:string]:string
5858
}
5959
/**
60-
* Exclude customBlocks for final build.
61-
*@default `['*']`
60+
* Exclude/Include customBlocks for final build.
61+
*@default `['!*']`
6262
*@example
6363
* ```js
64-
* VuePlugin({blackListCustomBlocks: ['markdown', 'test'] })
64+
* VuePlugin({customBlocks: ['markdown', '!test'] })
6565
* ```
6666
*/
67-
blackListCustomBlocks?:string[]
68-
/**
69-
* Include customBlocks for final build.
70-
*@default `[]`
71-
*@example
72-
* ```js
73-
* VuePlugin({ blackListCustomBlocks: ['markdown', 'test'] })
74-
* ```
75-
*/
76-
whiteListCustomBlocks?:string[]
67+
customBlocks?:string[]|(()=>boolean)
7768
/**
7869
* Inject CSS in JavaScript.
7970
*@default `true`
@@ -152,24 +143,20 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
152143
}
153144

154145
constshouldExtractCss=opts.css===false
155-
constblacklisted=newSet(opts.blackListCustomBlocks||['*'])
156-
constwhitelisted=newSet(opts.whiteListCustomBlocks||[])
157146

158-
constisAllowed=(customBlockType:string)=>
159-
(!blacklisted.has('*')||!blacklisted.has(customBlockType))&&
160-
(whitelisted.has('*')||whitelisted.has(customBlockType))
147+
constisAllowed=createCustomBlockFilter(opts.customBlocks)
161148

162149
constbeforeAssemble=
163150
opts.beforeAssemble||
164151
((d:DescriptorCompileResult):DescriptorCompileResult=>d)
165152

166153
constexposeFilename=
167154
typeofopts.exposeFilename==='boolean' ?opts.exposeFilename :false
155+
168156
deleteopts.beforeAssemble
169157
deleteopts.css
170158
deleteopts.exposeFilename
171-
deleteopts.blackListCustomBlocks
172-
deleteopts.whiteListCustomBlocks
159+
deleteopts.customBlocks
173160
deleteopts.defaultLang
174161
deleteopts.include
175162
deleteopts.exclude
@@ -382,3 +369,19 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
382369
}
383370
}
384371
}
372+
373+
functioncreateCustomBlockFilter(
374+
customBlocks?:string[]|((tag:string)=>boolean)
375+
):(tag:string)=>boolean{
376+
if(typeofcustomBlocks==='function')returncustomBlocks
377+
if(!Array.isArray(customBlocks))return()=>false
378+
379+
constallowed=newSet(customBlocks.filter(tag=>!tag.startsWith('!')))
380+
constnotAllowed=newSet(
381+
customBlocks.filter(tag=>tag.startsWith('!')).map(tag=>tag.substr(1))
382+
)
383+
384+
returntag=>
385+
(allowed.has('*')||allowed.has(tag))&&
386+
!(notAllowed.has('*')||notAllowed.has(tag))
387+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp