Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

feat: keep custom block type when block has lang #371

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,19 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {

descriptor.customBlocks.forEach((block, index) => {
if (!isAllowed(block.type)) return
const vuePartRequest = createVuePartRequest(
filename,
(typeof block.attrs.lang === 'string' && block.attrs.lang) ||
createVuePartRequest.defaultLang[block.type],
'customBlocks',
index,
block.type
)
result.code +=
'\n' +
`export * from '${createVuePartRequest(
filename,
(typeof block.attrs.lang === 'string' && block.attrs.lang) ||
createVuePartRequest.defaultLang[block.type] ||
block.type,
'customBlocks',
index
)}'`
`export * from '${vuePartRequest}'\n` +
`import __custom_block_${index}__ from '${vuePartRequest}'\n` +
`__custom_block_${index}__(__vue_component__)`
})

dT(
Expand Down
13 changes: 10 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export interface VuePartRequestMeta {
}

export interface VuePartRequestCreator {
(filename: string, lang: string, type: string, index?: number): string
(
filename: string,
lang: string,
type: string,
index?: number,
blockType?: string
): string

defaultLang: {
[key: string]: string
Expand Down Expand Up @@ -68,15 +74,16 @@ export const createVuePartRequest: VuePartRequestCreator = ((
filename: string,
lang: string | undefined,
type: string,
index?: number
index?: number,
blockType?: string
): string => {
lang = lang || createVuePartRequest.defaultLang[type]

const match = GET_QUERY.exec(filename)

const query = match ? queryString.parse(match[2]) : {}

query[PARAM_NAME] = [type, index, lang]
query[PARAM_NAME] = [type, index, blockType, lang]
.filter(it => it !== undefined)
.join('.')

Expand Down