mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
feat(theme): exclude encrypt page in llmstxt (#758)
This commit is contained in:
parent
f9b8c6adf2
commit
73f4935ca9
@ -3,7 +3,7 @@ import { onClickOutside, useClipboard, useToggle } from '@vueuse/core'
|
||||
import { computed, onMounted, ref, useTemplateRef } from 'vue'
|
||||
import { withBase } from 'vuepress/client'
|
||||
import { ensureEndingSlash } from 'vuepress/shared'
|
||||
import { useData } from '../../composables/index.js'
|
||||
import { useData, useEncrypt } from '../../composables/index.js'
|
||||
|
||||
import '@vuepress/helper/transition/fade-in.css'
|
||||
|
||||
@ -12,6 +12,7 @@ interface MenuItem {
|
||||
text: string
|
||||
tagline: string
|
||||
icon: string
|
||||
type?: string
|
||||
}
|
||||
|
||||
const { claude = true, chatgpt = true } = defineProps<{
|
||||
@ -20,6 +21,7 @@ const { claude = true, chatgpt = true } = defineProps<{
|
||||
}>()
|
||||
|
||||
const { page, frontmatter, theme } = useData()
|
||||
const { isPageDecrypted } = useEncrypt()
|
||||
|
||||
const markdownLink = computed(() => {
|
||||
const url = withBase(page.value.path)
|
||||
@ -46,6 +48,7 @@ const menuList = computed(() => {
|
||||
text: theme.value.viewMarkdown ?? 'View as Markdown',
|
||||
tagline: theme.value.viewMarkdownTagline ?? 'View this page as plain text',
|
||||
icon: 'vpi-markdown',
|
||||
type: 'text/markdown',
|
||||
})
|
||||
|
||||
if (chatgpt) {
|
||||
@ -116,7 +119,7 @@ const copyPageText = computed(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="frontmatter.llmstxt !== false" class="vp-page-context-menu">
|
||||
<div v-if="frontmatter.llmstxt !== false && isPageDecrypted" class="vp-page-context-menu">
|
||||
<div class="page-context-button" type="button">
|
||||
<span class="page-context-copy" @click="onCopy">
|
||||
<span class="vpi-copy" :class="{ loading: !loaded, copied }" />
|
||||
@ -140,7 +143,8 @@ const copyPageText = computed(() => {
|
||||
<li v-for="item in menuList" :key="item.text">
|
||||
<a
|
||||
:href="item.link" target="_blank" rel="noopener noreferrer"
|
||||
:aria-label="item.text" data-allow-mismatch
|
||||
:aria-label="item.text" :type="item.type"
|
||||
data-allow-mismatch
|
||||
>
|
||||
<span :class="item.icon" />
|
||||
<span>
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import type { LLMPage, LlmsPluginOptions, LLMState } from '@vuepress/plugin-llms'
|
||||
import type { App, PluginConfig } from 'vuepress'
|
||||
import type { ThemeSidebarItem } from '../../shared/index.js'
|
||||
import type { App, Page, PluginConfig } from 'vuepress'
|
||||
import type { ThemePageData, ThemeSidebarItem } from '../../shared/index.js'
|
||||
import { generateTOCLink as rawGenerateTOCLink, llmsPlugin as rawLlmsPlugin } from '@vuepress/plugin-llms'
|
||||
import { ensureEndingSlash, ensureLeadingSlash, isPlainObject } from 'vuepress/shared'
|
||||
import { getThemeConfig } from '../loadConfig/index.js'
|
||||
import { isEncryptPage } from '../prepare/prepareEncrypt.js'
|
||||
import { withBase } from '../utils/index.js'
|
||||
|
||||
export function llmsPlugin(app: App, userOptions: true | LlmsPluginOptions): PluginConfig {
|
||||
@ -117,7 +118,10 @@ export function llmsPlugin(app: App, userOptions: true | LlmsPluginOptions): Plu
|
||||
return tableOfContent
|
||||
}
|
||||
|
||||
const options = getThemeConfig()
|
||||
return [rawLlmsPlugin({
|
||||
// 启用全站加密、或者页面被加密的情况下不启用
|
||||
filter: page => options.encrypt?.global ? false : !isEncryptPage(page as Page<ThemePageData>, options.encrypt),
|
||||
...userLLMsTxt,
|
||||
llmsTxtTemplateGetter: {
|
||||
toc: tocGetter,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user