mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
style: lint fix
This commit is contained in:
parent
98e85b0ece
commit
6a8e2d9158
@ -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' })
|
||||
|
||||
@ -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', '')
|
||||
|
||||
@ -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/'
|
||||
|
||||
|
||||
@ -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!`)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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()}`
|
||||
|
||||
@ -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()}`
|
||||
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -163,7 +163,9 @@ const disableReset = computed(() => {
|
||||
})
|
||||
function focusSearchInput(select = true) {
|
||||
searchInput.value?.focus()
|
||||
select && searchInput.value?.select()
|
||||
if (select) {
|
||||
searchInput.value?.select()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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>
|
||||
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
@ -17,7 +17,9 @@ export function useFlyout(options: UseFlyoutOptions) {
|
||||
const focus = ref(false)
|
||||
|
||||
if (inBrowser) {
|
||||
!active && activateFocusTracking()
|
||||
if (!active) {
|
||||
activateFocusTracking()
|
||||
}
|
||||
|
||||
listeners++
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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 => {
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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(), '/')
|
||||
|
||||
@ -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,
|
||||
},
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -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]]),
|
||||
|
||||
@ -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)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user