refactor: remove code background

This commit is contained in:
Guoqi Sun 2024-12-22 23:08:42 +08:00
parent fce10c4e32
commit 7fa06f4127
12 changed files with 52 additions and 133 deletions

View file

@ -4,10 +4,8 @@ import { common } from "~/config"
import "~/styles/comment.css"
---
<div class="relative z-10 my-10">
{
{
common.comments.enabled && common.comments.twikoo.enabled && (
<Twikoo client:only="react" />
)
}
</div>
}

View file

@ -2,7 +2,7 @@
const currentYear = new Date().getFullYear()
---
<footer class="relative z-10 flex flex-wrap items-center gap-1 py-10">
<footer class="flex flex-wrap items-center gap-1 py-10">
<p>&copy; {currentYear}</p>
{

View file

@ -7,6 +7,6 @@ const lang = getLangFromUrl(Astro.url)
const IntroContent = lang === "zh" ? IntroContentZh : IntroContentEn
---
<div class="relative z-10 my-10">
<div class="my-10">
<IntroContent />
</div>

View file

@ -17,7 +17,6 @@ const filteredPosts = posts.filter((post: any) => post.data.tags?.includes(tag))
---
<MainLayout>
<div class="relative z-10">
<div class="my-9 mt-2 text-2xl font-semibold">#{tag}</div>
{
@ -36,5 +35,4 @@ const filteredPosts = posts.filter((post: any) => post.data.tags?.includes(tag))
<p class="text-gray-500">{t("tag.no_posts")}</p>
)
}
</div>
</MainLayout>

View file

@ -1,74 +0,0 @@
import { useEffect, useState } from "react"
export function CodeBackground() {
const charGroups = {
brackets: {
chars: ["{", "}", "(", ")", "[", "]", "<", ">"],
weight: 3,
},
operators: {
chars: ["=", "+", "-", "*", "/", "%", "=>", "&&", "||", "|", "&", "..."],
weight: 2,
},
punctuation: {
chars: [".", ";", ":", ","],
weight: 4,
},
keywords: {
chars: [
"const",
"let",
"var",
"function",
"if",
"else",
"return",
"class",
"import",
"export",
"from",
"async",
"await",
"try",
"catch",
"interface",
"type",
"extends",
"implements",
],
weight: 1,
},
values: {
chars: ["null", "undefined", "true", "false", "void", "any", "never"],
weight: 1,
},
}
const [backgroundChars, setBackgroundChars] = useState<string[]>([])
useEffect(() => {
const getWeightedRandomChar = () => {
const weightedChars = Object.values(charGroups).reduce((acc, group) => {
const chars = Array(group.weight).fill(group.chars).flat()
return [...acc, ...chars]
}, [] as string[])
return weightedChars[Math.floor(Math.random() * weightedChars.length)]
}
const chars = new Array(2000).fill(null).map(() => getWeightedRandomChar())
setBackgroundChars(chars)
}, [])
return (
<div className="fixed inset-0 z-0 flex h-screen w-screen select-none flex-wrap overflow-hidden">
{backgroundChars.map((char, index) => (
<span
key={index}
className="px-1 text-sm text-transparent duration-[0.8s] hover:text-black/50 hover:duration-0 dark:hover:text-white/50"
>
{char}
</span>
))}
</div>
)
}

View file

@ -1,7 +1,6 @@
---
import "~/styles/globals.css"
import { NoiseBackground } from "~/components/react/noise-background"
import { CodeBackground } from "~/components/react/code-background"
import { getLangFromUrl } from "~/i18n/utils"
import { GoogleAnalytics } from "astro-google-analytics"
import { en, zh } from "~/config"
@ -85,6 +84,5 @@ const config = lang === "zh" ? zh : en
>
<slot />
<NoiseBackground />
<CodeBackground client:load />
</body>
</html>

View file

@ -16,11 +16,11 @@ const openGraphImage = !ogImage ? `/og/${filename}.png` : ogImage
needComment={needComment}
>
<main class="max-auto mb-10 w-full max-w-3xl">
<div class="relative z-10">
<Header />
<Navigation />
<slot />
</div>
<div class="my-10">
{needComment && <Comments />}
</div>
</main>
</BaseLayout>

View file

@ -21,7 +21,7 @@ const ogImage = "https://sunguoqi.com/me.png"
ogImage={ogImage}
needComment={true}
>
<div class="prose relative z-10 dark:prose-invert">
<div class="prose dark:prose-invert">
<AboutContent />
</div>
</MainLayout>

View file

@ -29,7 +29,6 @@ const years = Object.keys(postsByYear).sort((a, b) => Number(b) - Number(a))
---
<MainLayout>
<div class="relative z-10">
{
years.map((year) => (
<div class="year-group my-8">
@ -45,5 +44,4 @@ const years = Object.keys(postsByYear).sort((a, b) => Number(b) - Number(a))
</div>
))
}
</div>
</MainLayout>

View file

@ -1,7 +1,7 @@
---
import Blog from "~/components/astro/blog.astro"
import Footer from "~/components/astro/footer.astro"
import Intro from "~/components/astro/intro.astro"
import RecentBlogs from "~/components/astro/recent-blogs.astro"
import MainLayout from "~/layouts/main.astro"
import { getLanguagePaths } from "~/utils/langs"
@ -12,6 +12,6 @@ export function getStaticPaths() {
<MainLayout>
<Intro />
<Blog />
<RecentBlogs />
<Footer />
</MainLayout>

View file

@ -31,9 +31,7 @@ const { Content } = await render(post)
---
<MainLayout {...post.data}>
<article
class="prose relative z-10 w-full max-w-3xl overflow-hidden dark:prose-invert"
>
<article class="prose w-full max-w-3xl overflow-hidden dark:prose-invert">
<div class="flex flex-col gap-2">
<h2 class="!my-0 text-3xl font-semibold">{post.data.title}</h2>
<div class="my-3 text-gray-500 dark:text-white/80">
@ -54,6 +52,9 @@ const { Content } = await render(post)
))
}
</div>
<div class="my-10">
<Comments />
</div>
</article>
</MainLayout>