feat(markdown-macro): update include to check for plain file type

This commit is contained in:
purocean
2025-01-09 15:55:40 +08:00
parent dc9e4b8780
commit 34a2e3475a
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -2,7 +2,6 @@ import { escapeRegExp, merge, omit } from 'lodash-es'
import frontMatter from 'front-matter'
import type { Plugin } from '@fe/context'
import type { BuildInSettings, Doc } from '@fe/types'
import { MARKDOWN_FILE_EXT } from '@share/misc'
import type { MenuItem } from '@fe/services/status-bar'
import { render } from '@fe/services/view'
import { t } from '@fe/services/i18n'
@@ -10,6 +9,7 @@ import { readFile } from '@fe/support/api'
import { getLogger, md5 } from '@fe/utils'
import { basename, dirname, resolve } from '@fe/utils/path'
import { getPurchased } from '@fe/others/premium'
import { isPlain } from '@fe/services/document'
import ctx from '@fe/context'
type Result = { __macroResult: true, vars?: Record<string, any>, value: string }
@@ -208,8 +208,8 @@ async function include (
return { __macroResult: true, value: 'Error: $include maximum call stack size exceeded [3]' }
}
if (!path.endsWith(MARKDOWN_FILE_EXT)) {
return { __macroResult: true, value: 'Error: $include markdown file only' }
if (!isPlain({ type: 'file', path })) {
return { __macroResult: true, value: 'Error: $include path is not a plain file' }
}
try {
+1 -1
View File
@@ -166,7 +166,7 @@ export function isEncrypted (doc?: Pick<Doc, 'path' | 'type'> | null): boolean {
* @param doc
* @returns
*/
export function isPlain (doc?: PathItemWithType) {
export function isPlain (doc?: Omit<PathItemWithType, 'repo'>) {
if (!doc) return false
return doc.type === 'file' &&