style: lint fix

This commit is contained in:
pengzhanbo 2024-07-17 00:06:42 +08:00
parent 98e85b0ece
commit 6a8e2d9158
29 changed files with 217 additions and 90 deletions

View File

@ -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' })

View File

@ -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', '')

View File

@ -34,9 +34,16 @@ export const codepenPlugin: PluginWithOptions<never> = (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/'

View File

@ -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!`)
}
}

View File

@ -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

View File

@ -41,11 +41,26 @@ export const bilibiliPlugin: PluginWithOptions<never> = (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()}`

View File

@ -34,10 +34,21 @@ export const youtubePlugin: PluginWithOptions<never> = (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()}`

View File

@ -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) => {

View File

@ -163,7 +163,9 @@ const disableReset = computed(() => {
})
function focusSearchInput(select = true) {
searchInput.value?.focus()
select && searchInput.value?.select()
if (select) {
searchInput.value?.select()
}
}
onMounted(() => {

View File

@ -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)

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, nextTick, watch } from 'vue'
import { nextTick, watch } from 'vue'
import VPBlog from '@theme/Blog/VPBlog.vue'
import VPDoc from '@theme/VPDoc.vue'
import VPPage from '@theme/VPPage.vue'

View File

@ -78,7 +78,7 @@ onMounted(() => {
margin-left: var(--vp-sidebar-width);
}
.vp-footer.vp-footer.has-sidebar .container {
.vp-footer.has-sidebar .container {
margin-left: calc(0px - var(--vp-sidebar-width));
}
}

View File

@ -47,11 +47,15 @@ function onItemInteraction(e: MouseEvent | Event) {
if ('key' in e && e.key !== 'Enter')
return
!props.item.link && toggle()
if (!props.item.link) {
toggle()
}
}
function onCaretClick() {
props.item.link && toggle()
if (props.item.link) {
toggle()
}
}
</script>

View File

@ -1,5 +1,5 @@
<script lang="ts" setup>
import { computed, inject, ref, watchPostEffect } from 'vue'
import { inject, ref, watchPostEffect } from 'vue'
import VPSwitch from '@theme/VPSwitch.vue'
import { useData } from '../composables/data.js'

View File

@ -17,7 +17,9 @@ export function useFlyout(options: UseFlyoutOptions) {
const focus = ref(false)
if (inBrowser) {
!active && activateFocusTracking()
if (!active) {
activateFocusTracking()
}
listeners++

View File

@ -91,13 +91,17 @@ export function useHomeHeroTintPlate(
onMounted(() => {
if (canvas.value && enable.value) {
ctx = canvas.value.getContext('2d')!
timer && window.cancelAnimationFrame(timer)
if (timer) {
window.cancelAnimationFrame(timer)
}
run()
}
})
onUnmounted(() => {
timer && window.cancelAnimationFrame(timer)
if (timer) {
window.cancelAnimationFrame(timer)
}
})
function run() {

View File

@ -60,14 +60,21 @@ export function useNav(): UseNavReturn {
}
function toggleScreen(): void {
isScreenOpen.value ? closeScreen() : openScreen()
if (isScreenOpen.value) {
closeScreen()
}
else {
openScreen()
}
}
/**
* Close screen when the user resizes the window wider than tablet size.
*/
function closeScreenOnTabletWindow(): void {
window.outerWidth >= 768 && closeScreen()
if (window.outerWidth >= 768) {
closeScreen()
}
}
const route = useRoute()

View File

@ -295,7 +295,12 @@ export function useSidebar(): UseSidebarReturn {
}
const toggle = (): void => {
isOpen.value ? close() : open()
if (isOpen.value) {
close()
}
else {
open()
}
}
return {
@ -386,7 +391,9 @@ export function useSidebarControl(item: ComputedRef<ResolvedSidebarItem>): Sideb
})
watchPostEffect(() => {
;(isActiveLink.value || hasActiveLink.value) && (collapsed.value = false)
if (isActiveLink.value || hasActiveLink.value) {
collapsed.value = false
}
})
const toggle = (): void => {

View File

@ -57,8 +57,8 @@ export function scrollTo(
const change = top - currentTop
const timer = setInterval(() => {
currentStep++
if (currentStep >= step)
timer && clearInterval(timer)
if (currentStep >= step && timer)
clearInterval(timer)
setScrollTop(target, tween(currentStep, currentTop, change, step))
}, 1000 / 60)

View File

@ -177,10 +177,12 @@ export function resolveOptions(
if (note && sidebar && sidebar !== 'auto') {
const res = resolveLinkBySidebar(sidebar, pathJoin(notes?.dir || '', note.dir || ''))
const file = ensureLeadingSlash(relativePath)
if (res[file])
if (res[file]) {
args.push(res[file])
else
res[path.dirname(file)] && args.push(res[path.dirname(file)])
}
else if (res[path.dirname(file)]) {
args.push(res[path.dirname(file)])
}
}
return pathJoin(...args, nanoid(), '/')

View File

@ -1,4 +1,10 @@
import { addViteConfig, addViteOptimizeDepsExclude, addViteOptimizeDepsInclude, addViteSsrNoExternal } from '@vuepress/helper'
import {
addViteConfig,
addViteOptimizeDepsExclude,
addViteOptimizeDepsInclude,
addViteSsrNoExternal,
chainWebpack,
} from '@vuepress/helper'
import type { App } from 'vuepress'
export function extendsBundlerOptions(bundlerOptions: any, app: App): void {
@ -16,4 +22,18 @@ export function extendsBundlerOptions(bundlerOptions: any, app: App): void {
'@vuepress/plugin-reading-time',
'@vuepress/plugin-watermark',
])
chainWebpack(bundlerOptions, app, (config) => {
config.module
.rule('scss')
.use('sass-loader')
.tap((options: any) => ({
api: 'modern-compiler',
...options,
sassOptions: {
silenceDeprecations: ['mixed-decls'],
...options.sassOptions,
},
}))
})
}

View File

@ -51,14 +51,18 @@ export function resolveThemeData(app: App, options: PlumeThemeLocaleOptions): Pl
text: PRESET_LOCALES[localePath].blog,
link: withBase(blogLink, locale),
})
blog.tags !== false && navbar.push({
text: PRESET_LOCALES[localePath].tag,
link: withBase(blog.tagsLink || `${blogLink}/tags/`, locale),
})
blog.archives !== false && navbar.push({
text: PRESET_LOCALES[localePath].archive,
link: withBase(blog.archivesLink || `${blogLink}/archives/`, locale),
})
if (blog.tags !== false) {
navbar.push({
text: PRESET_LOCALES[localePath].tag,
link: withBase(blog.tagsLink || `${blogLink}/tags/`, locale),
})
}
if (blog.archives !== false) {
navbar.push({
text: PRESET_LOCALES[localePath].archive,
link: withBase(blog.archivesLink || `${blogLink}/archives/`, locale),
})
}
themeData.locales![locale].navbar = navbar
}

View File

@ -49,7 +49,9 @@ export async function extendsMarkdown(md: Markdown, app: App): Promise<void> {
const update = (filepath: string, data: CacheData): void => {
writeFile(`${basename}/${filepath}`, data)
timer && clearTimeout(timer)
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(async () => writeFile(metaFilepath, metadata), 200)
}
const rawRender = md.render

View File

@ -58,7 +58,9 @@ export async function initConfigLoader(
loader.configFile = await findConfigPath(app, configFile)
onChange && loader.changeEvents.push(onChange)
if (onChange) {
loader.changeEvents.push(onChange)
}
const { config, dependencies = [] } = await loader.load()
loader.loaded = true
@ -103,7 +105,9 @@ export function watchConfigFile(app: App, watchers: any[]) {
export async function onConfigChange(onChange: ChangeEvent) {
if (loader && !loader.changeEvents.includes(onChange)) {
loader.changeEvents.push(onChange)
loader.loaded && onChange(loader.resolvedConfig)
if (loader.loaded) {
onChange(loader.resolvedConfig)
}
}
}

View File

@ -46,7 +46,9 @@ export function genCode(app: App): { js: string, css: string } {
const { frontmatter: { tags } } = page
if (tags) {
toArray(tags).forEach((tag) => {
tag && tagList.add(tag as string)
if (tag) {
tagList.add(tag as string)
}
})
}
})

View File

@ -69,7 +69,9 @@ export async function preparedBlogData(
excerpt: '',
}
isEncryptPage(page, encrypt) && (data.encrypt = true)
if (isEncryptPage(page, encrypt)) {
data.encrypt = true
}
if (page.contentRendered.includes(EXCERPT_SPLIT)) {
const contents = page.contentRendered.split(EXCERPT_SPLIT)

View File

@ -38,18 +38,23 @@ function getSidebarData(
else if (isPlainObject(sidebar)) {
entries(sidebar).forEach(([dirname, config]) => {
const prefix = normalizeLink(localePath, dirname)
config === 'auto'
? autoDirList.push(prefix)
: isArray(config)
? autoDirList.push(...findAutoDirList(config, prefix))
: config.items === 'auto'
? autoDirList.push(normalizeLink(prefix, config.prefix))
: autoDirList.push(
...findAutoDirList(
config.items || [],
normalizeLink(prefix, config.prefix),
),
)
if (config === 'auto') {
autoDirList.push(prefix)
}
else if (isArray(config)) {
autoDirList.push(...findAutoDirList(config, prefix))
}
else if (config.items === 'auto') {
autoDirList.push(normalizeLink(prefix, config.prefix))
}
else {
autoDirList.push(
...findAutoDirList(
config.items || [],
normalizeLink(prefix, config.prefix),
),
)
}
})
}
else if (sidebar === 'auto') {
@ -121,8 +126,8 @@ function getAutoDirSidebar(
if (!isHome) {
items.push(current)
}
else {
!parent && items.unshift(current)
else if (!parent) {
items.unshift(current)
}
}
if (dir.endsWith('.md')) {
@ -159,9 +164,8 @@ function findAutoDirList(sidebar: (string | SidebarItem)[], prefix = ''): string
if (item.items === 'auto') {
list.push(nextPrefix)
}
else {
item.items?.length
&& list.push(...findAutoDirList(item.items, nextPrefix))
else if (item.items?.length) {
list.push(...findAutoDirList(item.items, nextPrefix))
}
}
})

View File

@ -42,22 +42,28 @@ export async function setupPage(
}))
// 添加 标签页
blog.tags !== false && pageList.push(createPage(app, {
path: withBase(blog.tagsLink || `${link}/tags/`, localePath),
frontmatter: { lang, _pageLayout: 'blog-tags', title: getTitle(locale, 'tag') },
}))
if (blog.tags !== false) {
pageList.push(createPage(app, {
path: withBase(blog.tagsLink || `${link}/tags/`, localePath),
frontmatter: { lang, _pageLayout: 'blog-tags', title: getTitle(locale, 'tag') },
}))
}
// 添加归档页
blog.archives !== false && pageList.push(createPage(app, {
path: withBase(blog.archivesLink || `${link}/archives/`, localePath),
frontmatter: { lang, _pageLayout: 'blog-archives', title: getTitle(locale, 'archive') },
}))
if (blog.archives !== false) {
pageList.push(createPage(app, {
path: withBase(blog.archivesLink || `${link}/archives/`, localePath),
frontmatter: { lang, _pageLayout: 'blog-archives', title: getTitle(locale, 'archive') },
}))
}
// 添加分类页
blog.categories !== false && pageList.push(createPage(app, {
path: withBase(blog.categoriesLink || `${link}/categories/`, localePath),
frontmatter: { lang, _pageLayout: 'blog-categories', title: getTitle(locale, 'category') },
}))
if (blog.categories !== false) {
pageList.push(createPage(app, {
path: withBase(blog.categoriesLink || `${link}/categories/`, localePath),
frontmatter: { lang, _pageLayout: 'blog-categories', title: getTitle(locale, 'category') },
}))
}
}
app.pages.push(...await Promise.all(pageList))
@ -137,7 +143,9 @@ export function autoCategory(
const categoryList: PageCategoryData[] = list
.map((category, index) => {
const match = category.match(RE_CATEGORY) || []
!cache[match[2]] && !match[1] && (cache[match[2]] = uuid++)
if (!cache[match[2]] && !match[1]) {
cache[match[2]] = uuid++
}
return {
id: hash(list.slice(0, index + 1).join('-')).slice(0, 6),
sort: Number(match[1] || cache[match[2]]),

View File

@ -40,7 +40,9 @@ export function plumeTheme(options: PlumeThemeOptions = {}): Theme {
configFile,
onChange: ({ localeOptions, autoFrontmatter }) => {
autoFrontmatter ??= pluginOptions.frontmatter
autoFrontmatter !== false && initAutoFrontmatter(localeOptions, autoFrontmatter)
if (autoFrontmatter !== false) {
initAutoFrontmatter(localeOptions, autoFrontmatter)
}
},
})