fix: update to upstream vitepress

Fixes WEB-25
This commit is contained in:
taskylizard 2024-09-01 15:12:33 +00:00
parent a7d86c439f
commit e337ab380f
No known key found for this signature in database
GPG key ID: 1820131ED1A24120
6 changed files with 356 additions and 260 deletions

View file

@ -1,3 +1,4 @@
import { fileURLToPath } from 'node:url'
import consola from 'consola'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
@ -8,6 +9,7 @@ import {
commitRef,
feedback,
meta,
nav,
search,
sidebar,
socialLinks
@ -58,6 +60,16 @@ export default defineConfig({
ssr: {
noExternal: ['@fmhy/components']
},
resolve: {
alias: [
{
find: /^.*VPSwitchAppearance\.vue$/,
replacement: fileURLToPath(
new URL('./theme/Appearance.vue', import.meta.url)
)
}
]
},
optimizeDeps: { exclude: ['workbox-window'] },
plugins: [
OptimizeExclude(),
@ -121,29 +133,7 @@ export default defineConfig({
},
outline: 'deep',
logo: '/fmhy.ico',
nav: [
{ text: '🔖 Glossary', link: 'https://rentry.org/The-Piracy-Glossary' },
{ text: '📑 Guides', link: 'https://rentry.co/fmhy-guides' },
{
text: '💾 Backups',
link: 'https://github.com/fmhy/FMHY/wiki/Backups'
},
{
text: '🪅 Ecosystem',
items: [
{ text: '💙 Feedback', link: '/feedback' },
{ text: '🌐 Search', link: '/posts/search' },
{ text: '🏞 Wallpapers', link: '/other/wallpapers' },
{ text: '📋 snowbin', link: 'https://pastes.fmhy.net' },
{ text: '🔍 SearXNG', link: 'https://searx.fmhy.net/' },
{ text: '🔍 Whoogle', link: 'https://whoogle.fmhy.net/' },
{
text: '🔗 Bookmarks',
link: 'https://github.com/fmhy/bookmarks'
}
]
}
],
nav,
sidebar,
socialLinks
}

View file

@ -28,8 +28,9 @@ export const meta = {
export const commitRef =
process.env.CF_PAGES && process.env.CF_PAGES_COMMIT_SHA
? `<a href="https://github.com/fmhy/FMHYEdit/commit/${process.env.CF_PAGES_COMMIT_SHA
}">${process.env.CF_PAGES_COMMIT_SHA.slice(0, 8)}</a>`
? `<a href="https://github.com/fmhy/FMHYEdit/commit/${
process.env.CF_PAGES_COMMIT_SHA
}">${process.env.CF_PAGES_COMMIT_SHA.slice(0, 8)}</a>`
: 'dev'
export const feedback = `<a href="/feedback" class="feedback-footer">Made with ❤</a>`
@ -113,7 +114,10 @@ export const socialLinks: DefaultTheme.SocialLink[] = [
{ icon: 'github', link: 'https://github.com/fmhy/FMHYEdit' },
{ icon: 'discord', link: 'https://discord.gg/Stz6y6NgNg' },
{
icon: 'reddit',
ariaLabel: 'Reddit',
icon: {
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Reddit</title><path d="M12 0C5.373 0 0 5.373 0 12c0 3.314 1.343 6.314 3.515 8.485l-2.286 2.286C.775 23.225 1.097 24 1.738 24H12c6.627 0 12-5.373 12-12S18.627 0 12 0Zm4.388 3.199c1.104 0 1.999.895 1.999 1.999 0 1.105-.895 2-1.999 2-.946 0-1.739-.657-1.947-1.539v.002c-1.147.162-2.032 1.15-2.032 2.341v.007c1.776.067 3.4.567 4.686 1.363.473-.363 1.064-.58 1.707-.58 1.547 0 2.802 1.254 2.802 2.802 0 1.117-.655 2.081-1.601 2.531-.088 3.256-3.637 5.876-7.997 5.876-4.361 0-7.905-2.617-7.998-5.87-.954-.447-1.614-1.415-1.614-2.538 0-1.548 1.255-2.802 2.803-2.802.645 0 1.239.218 1.712.585 1.275-.79 2.881-1.291 4.64-1.365v-.01c0-1.663 1.263-3.034 2.88-3.207.188-.911.993-1.595 1.959-1.595Zm-8.085 8.376c-.784 0-1.459.78-1.506 1.797-.047 1.016.64 1.429 1.426 1.429.786 0 1.371-.369 1.418-1.385.047-1.017-.553-1.841-1.338-1.841Zm7.406 0c-.786 0-1.385.824-1.338 1.841.047 1.017.634 1.385 1.418 1.385.785 0 1.473-.413 1.426-1.429-.046-1.017-.721-1.797-1.506-1.797Zm-3.703 4.013c-.974 0-1.907.048-2.77.135-.147.015-.241.168-.183.305.483 1.154 1.622 1.964 2.953 1.964 1.33 0 2.47-.81 2.953-1.964.057-.137-.037-.29-.184-.305-.863-.087-1.795-.135-2.769-.135Z"/></svg>'
},
link: 'https://reddit.com/r/FREEMEDIAHECKYEAH'
},
{
@ -125,6 +129,30 @@ export const socialLinks: DefaultTheme.SocialLink[] = [
}
]
export const nav: DefaultTheme.NavItem[] = [
{ text: '🔖 Glossary', link: 'https://rentry.org/The-Piracy-Glossary' },
{ text: '📑 Guides', link: 'https://rentry.co/fmhy-guides' },
{
text: '💾 Backups',
link: 'https://github.com/fmhy/FMHY/wiki/Backups'
},
{
text: '🪅 Ecosystem',
items: [
{ text: '💙 Feedback', link: '/feedback' },
{ text: '🌐 Search', link: '/posts/search' },
{ text: '🏞 Wallpapers', link: '/other/wallpapers' },
{ text: '📋 snowbin', link: 'https://pastes.fmhy.net' },
{ text: '🔍 SearXNG', link: 'https://searx.fmhy.net/' },
{ text: '🔍 Whoogle', link: 'https://whoogle.fmhy.net/' },
{
text: '🔗 Bookmarks',
link: 'https://github.com/fmhy/bookmarks'
}
]
}
]
export const sidebar: DefaultTheme.Sidebar | DefaultTheme.NavItemWithLink[] = [
{
text: '<span class="i-twemoji:books"></span> Beginners Guide',

View file

@ -20,6 +20,8 @@ export function generateMeta(context: TransformContext, hostname: string) {
const head: HeadConfig[] = []
const { pageData } = context
if (pageData.isNotFound) return head
const url = `${hostname}/${pageData.relativePath.replace(/((^|\/)index)?\.md$/, '$2')}`
head.push(
@ -30,6 +32,7 @@ export function generateMeta(context: TransformContext, hostname: string) {
['meta', { property: 'og:title', content: pageData.frontmatter.title }],
['meta', { name: 'twitter:title', content: pageData.frontmatter.title }]
)
if (pageData.frontmatter.description) {
head.push(
[
@ -48,6 +51,7 @@ export function generateMeta(context: TransformContext, hostname: string) {
]
)
}
if (pageData.frontmatter.image) {
head.push([
'meta',
@ -87,12 +91,14 @@ export function generateMeta(context: TransformContext, hostname: string) {
]
)
}
if (pageData.frontmatter.tag) {
head.push([
'meta',
{ property: 'article:tag', content: pageData.frontmatter.tag }
])
}
if (pageData.frontmatter.date) {
head.push([
'meta',
@ -102,6 +108,7 @@ export function generateMeta(context: TransformContext, hostname: string) {
}
])
}
if (pageData.lastUpdated && pageData.frontmatter.lastUpdated !== false) {
head.push([
'meta',

View file

@ -0,0 +1,72 @@
<script setup lang="ts">
import VPIconMoon from 'vitepress/dist/client/theme-default/components/icons/VPIconMoon.vue'
import VPIconSun from 'vitepress/dist/client/theme-default/components/icons/VPIconSun.vue'
const { isDark } = useData()
const toggleAppearance = inject('toggle-appearance', () => {
isDark.value = !isDark.value
})
const supportsViewTransition = ref(false)
onMounted(() => {
supportsViewTransition.value =
'startViewTransition' in document &&
window.matchMedia('(prefers-reduced-motion: no-preference)').matches
})
</script>
<template>
<button
type="button"
role="switch"
title="VPSwitchAppearance"
class="VPSwitchAppearance"
:aria-checked="isDark"
:data-view-transition="supportsViewTransition"
@click="toggleAppearance"
>
<ClientOnly>
<Transition name="fade" mode="out-in">
<VPIconSun v-if="!isDark" class="sun" />
<VPIconMoon v-else class="moon" />
</Transition>
</ClientOnly>
</button>
</template>
<style lang="scss" scoped>
.VPSwitchAppearance {
display: flex;
justify-content: center;
align-items: center;
width: 36px;
height: 36px;
color: var(--vp-c-text-2);
transition: color 0.5s;
&:hover {
color: var(--vp-c-text-1);
transition: color 0.25s;
}
& > :deep(svg) {
width: 20px;
height: 20px;
fill: currentColor;
}
&[data-view-transition='false'] {
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.1s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
}
}
</style>