diff --git a/plugins/plugin-md-power/src/client/components/CodeEditor.vue b/plugins/plugin-md-power/src/client/components/CodeEditor.vue index 22a07b09..10c24cce 100644 --- a/plugins/plugin-md-power/src/client/components/CodeEditor.vue +++ b/plugins/plugin-md-power/src/client/components/CodeEditor.vue @@ -48,7 +48,9 @@ function highlight() { } function updateScroll() { - container && (container.scrollLeft = textAreaEl.value?.scrollLeft || 0) + if (container) { + container.scrollLeft = textAreaEl.value?.scrollLeft || 0 + } } watch([input], highlight, { flush: 'post' }) diff --git a/plugins/plugin-md-power/src/client/components/CodeSandbox.vue b/plugins/plugin-md-power/src/client/components/CodeSandbox.vue index e542f965..6d4a6a9f 100644 --- a/plugins/plugin-md-power/src/client/components/CodeSandbox.vue +++ b/plugins/plugin-md-power/src/client/components/CodeSandbox.vue @@ -11,12 +11,19 @@ const SANDBOX = 'allow-forms allow-modals allow-popups allow-presentation allow- const source = computed(() => { const params = new URLSearchParams() - props.filepath && params.set(props.type === 'embed' ? 'module' : 'file', encodeURIComponent(props.filepath)) + if (props.filepath) { + params.set(props.type === 'embed' ? 'module' : 'file', encodeURIComponent(props.filepath)) + } if (props.type === 'embed') { params.set('view', props.layout ? props.layout.replace(/,/g, '+') : 'Editor+Preview') - props.console && params.set('expanddevtools', '1') - props.navbar === false && params.set('hidenavigation', '1') + + if (props.console) { + params.set('expanddevtools', '1') + } + if (props.navbar === false) { + params.set('hidenavigation', '1') + } } else { params.set('from-embed', '') diff --git a/plugins/plugin-md-power/src/node/features/codepen.ts b/plugins/plugin-md-power/src/node/features/codepen.ts index 403801de..83cdc3e1 100644 --- a/plugins/plugin-md-power/src/node/features/codepen.ts +++ b/plugins/plugin-md-power/src/node/features/codepen.ts @@ -34,9 +34,16 @@ export const codepenPlugin: PluginWithOptions = (md) => { content: (meta) => { const { title = 'Codepen', height, width } = meta const params = new URLSearchParams() - meta.editable && params.set('editable', 'true') - meta.tab && params.set('default-tab', meta.tab) - meta.theme && params.set('theme-id', meta.theme) + + if (meta.editable) { + params.set('editable', 'true') + } + if (meta.tab) { + params.set('default-tab', meta.tab) + } + if (meta.theme) { + params.set('theme-id', meta.theme) + } const middle = meta.preview ? '/embed/preview/' : '/embed/' diff --git a/plugins/plugin-md-power/src/node/features/icons/writer.ts b/plugins/plugin-md-power/src/node/features/icons/writer.ts index f279b13b..750afdf5 100644 --- a/plugins/plugin-md-power/src/node/features/icons/writer.ts +++ b/plugins/plugin-md-power/src/node/features/icons/writer.ts @@ -130,7 +130,7 @@ async function genIconContent(iconName: string, cb: (content: string) => void) { iconJson = JSON.parse(await fs.readFile(filename, 'utf-8')) iconDataCache.set(collect, iconJson) } - catch (e) { + catch { logger.warn(`[plugin-md-power] Can not find icon, ${collect} is missing!`) } } diff --git a/plugins/plugin-md-power/src/node/features/langRepl.ts b/plugins/plugin-md-power/src/node/features/langRepl.ts index 49ba8391..277d13af 100644 --- a/plugins/plugin-md-power/src/node/features/langRepl.ts +++ b/plugins/plugin-md-power/src/node/features/langRepl.ts @@ -33,10 +33,15 @@ export async function langReplPlugin(app: App, md: markdownIt, { kotlin = false, rust = false, }: ReplOptions) { - kotlin && createReplContainer(md, 'kotlin') - go && createReplContainer(md, 'go') - rust && createReplContainer(md, 'rust') - + if (kotlin) { + createReplContainer(md, 'kotlin') + } + if (go) { + createReplContainer(md, 'go') + } + if (rust) { + createReplContainer(md, 'rust') + } theme ??= { light: 'github-light', dark: 'github-dark' } const data: ReplEditorData = { grammars: {} } as ReplEditorData diff --git a/plugins/plugin-md-power/src/node/features/video/bilibili.ts b/plugins/plugin-md-power/src/node/features/video/bilibili.ts index f561d9e8..b4d4fd52 100644 --- a/plugins/plugin-md-power/src/node/features/video/bilibili.ts +++ b/plugins/plugin-md-power/src/node/features/video/bilibili.ts @@ -41,11 +41,26 @@ export const bilibiliPlugin: PluginWithOptions = (md) => { content(meta) { const params = new URLSearchParams() - meta.bvid && params.set('bvid', meta.bvid) - meta.aid && params.set('aid', meta.aid) - meta.cid && params.set('cid', meta.cid) - meta.page && params.set('p', meta.page.toString()) - meta.time && params.set('t', meta.time.toString()) + if (meta.bvid) { + params.set('bvid', meta.bvid) + } + + if (meta.aid) { + params.set('aid', meta.aid) + } + + if (meta.cid) { + params.set('cid', meta.cid) + } + + if (meta.page) { + params.set('p', meta.page.toString()) + } + + if (meta.time) { + params.set('t', meta.time.toString()) + } + params.set('autoplay', meta.autoplay ? '1' : '0') const source = `${BILIBILI_LINK}?${params.toString()}` diff --git a/plugins/plugin-md-power/src/node/features/video/youtube.ts b/plugins/plugin-md-power/src/node/features/video/youtube.ts index b5bdf78e..98fdea7a 100644 --- a/plugins/plugin-md-power/src/node/features/video/youtube.ts +++ b/plugins/plugin-md-power/src/node/features/video/youtube.ts @@ -34,10 +34,21 @@ export const youtubePlugin: PluginWithOptions = (md) => { content(meta) { const params = new URLSearchParams() - meta.autoplay && params.set('autoplay', '1') - meta.loop && params.set('loop', '1') - meta.start && params.set('start', meta.start.toString()) - meta.end && params.set('end', meta.end.toString()) + if (meta.autoplay) { + params.set('autoplay', '1') + } + + if (meta.loop) { + params.set('loop', '1') + } + + if (meta.start) { + params.set('start', meta.start.toString()) + } + + if (meta.end) { + params.set('end', meta.end.toString()) + } const source = `${YOUTUBE_LINK}/${meta.id}?${params.toString()}` diff --git a/plugins/plugin-md-power/src/node/plugin.ts b/plugins/plugin-md-power/src/node/plugin.ts index 8da9f5fd..b275a856 100644 --- a/plugins/plugin-md-power/src/node/plugin.ts +++ b/plugins/plugin-md-power/src/node/plugin.ts @@ -32,11 +32,13 @@ export function markdownPowerPlugin(options: MarkdownPowerPluginOptions = {}): P onInitialized: async () => await initIcon(), extendsBundlerOptions(bundlerOptions) { - options.repl && addViteOptimizeDepsInclude( - bundlerOptions, - app, - ['shiki/core', 'shiki/wasm'], - ) + if (options.repl) { + addViteOptimizeDepsInclude( + bundlerOptions, + app, + ['shiki/core', 'shiki/wasm'], + ) + } }, extendsMarkdown: async (md: MarkdownIt, app) => { diff --git a/plugins/plugin-search/src/client/components/SearchBox.vue b/plugins/plugin-search/src/client/components/SearchBox.vue index ef94a45f..ed03394a 100644 --- a/plugins/plugin-search/src/client/components/SearchBox.vue +++ b/plugins/plugin-search/src/client/components/SearchBox.vue @@ -163,7 +163,9 @@ const disableReset = computed(() => { }) function focusSearchInput(select = true) { searchInput.value?.focus() - select && searchInput.value?.select() + if (select) { + searchInput.value?.select() + } } onMounted(() => { diff --git a/theme/src/client/components/VPBackToTop.vue b/theme/src/client/components/VPBackToTop.vue index 78e19d03..bdd4c814 100644 --- a/theme/src/client/components/VPBackToTop.vue +++ b/theme/src/client/components/VPBackToTop.vue @@ -40,7 +40,9 @@ const show = computed(() => { let timer: NodeJS.Timeout | null = null function resetScrolling() { - timer && clearTimeout(timer) + if (timer) { + clearTimeout(timer) + } timer = setTimeout(() => { isScrolling.value = false }, 1000) diff --git a/theme/src/client/components/VPContent.vue b/theme/src/client/components/VPContent.vue index 238e7744..5011fbdf 100644 --- a/theme/src/client/components/VPContent.vue +++ b/theme/src/client/components/VPContent.vue @@ -1,5 +1,5 @@ diff --git a/theme/src/client/components/VPSwitchAppearance.vue b/theme/src/client/components/VPSwitchAppearance.vue index 7b13690b..1690093f 100644 --- a/theme/src/client/components/VPSwitchAppearance.vue +++ b/theme/src/client/components/VPSwitchAppearance.vue @@ -1,5 +1,5 @@