优化性能、逻辑、冗余代码【2.0 版本】✅

This commit is contained in:
Han
2025-03-20 19:23:03 +08:00
parent fae69d44fd
commit d1b781ed6f
66 changed files with 287 additions and 205 deletions
+3 -3
View File
@@ -1,10 +1,10 @@
---
// 公共 Layout
import Layout from "../layouts/Layout.astro";
import Layout from "@/layouts/Layout/Layout.astro";
// Aside组件
import Aside from "../components/Aside.astro";
import Aside from "@/components/Aside/Aside.astro";
// 文章页面样式
import "../styles/Article.less";
import "@/styles/Article.less";
---
<Layout title="404 Not Found" keywords={[404]} description="404 Not Found">
+7 -7
View File
@@ -1,8 +1,8 @@
---
import { getCollection } from "astro:content";
import type { GetStaticPathsOptions } from "astro";
import setSearchJson from "../utils/vhSearch";
import moveTopToFirst from "../utils/moveTopToFirst";
import setSearchJson from "@/utils/vhSearch";
import moveTopToFirst from "@/utils/moveTopToFirst";
export async function getStaticPaths(options: GetStaticPathsOptions) {
const { paginate } = options;
const posts = (await getCollection("blog")).sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
@@ -20,16 +20,16 @@ export async function getStaticPaths(options: GetStaticPathsOptions) {
const { page } = Astro.props;
const { data, ...page_data } = page;
// 页面 Info
import SITE_CONFIG from "../config";
import SITE_CONFIG from "@/config";
const { Description } = SITE_CONFIG;
// 博客列表组件
import ArticleCard from "../components/ArticleCard.astro";
import ArticleCard from "@/components/ArticleCard/ArticleCard.astro";
// 公共 Layout
import Layout from "../layouts/Layout.astro";
import Layout from "@/layouts/Layout/Layout.astro";
// Aside组件
import Aside from "../components/Aside.astro";
import Aside from "@/components/Aside/Aside.astro";
// 分页组件
import Pagination from "../components/Pagination.astro";
import Pagination from "@/components/Pagination/Pagination.astro";
const currentPage = page_data.url.current.replace("/", "");
---
+3 -2
View File
@@ -2,11 +2,12 @@
title: "关于"
h1: "关于我"
desc: "Hi there, I’m Han 👋"
layout: "../../layouts/PageLayout.astro"
layout: "@/layouts/PageLayout/PageLayout.astro"
---
:::note{type="info"}
:::note{type="success"}
我是一名热爱前端开发并拥有丰富经验的工程师,喜欢探索新技术并应用于实际项目中。
我始终保持对新技术的热情,并将我的知识与经验分享在我的博客中。我期待在这里与你分享我的见解、经验和最新的技术动态。
:::
+5 -5
View File
@@ -1,16 +1,16 @@
---
import { getArchiveList } from "../../utils/getArchive";
import { getArchiveList } from "@/utils/getArchive";
// 获取归档列表
const articleList = await getArchiveList();
// 页面 Info
import SITE_CONFIG from "../../config";
import SITE_CONFIG from "@/config";
const { Description } = SITE_CONFIG;
// 公共 Layout
import Layout from "../../layouts/Layout.astro";
import Layout from "@/layouts/Layout/Layout.astro";
// Aside组件
import Aside from "../../components/Aside.astro";
import Aside from "@/components/Aside/Aside.astro";
// 文章列表组件
import Archive from "../../components/Archive.astro";
import Archive from "@/components/Archive/Archive.astro";
---
<Layout title="归档" description={Description}>
+17 -12
View File
@@ -1,5 +1,5 @@
---
import { getDescription, fmtTime } from "../../utils/index";
import { getDescription, fmtTime } from "@/utils/index";
import { type CollectionEntry, getCollection } from "astro:content";
import { render } from "astro:content";
export async function getStaticPaths() {
@@ -10,10 +10,10 @@ export async function getStaticPaths() {
type Props = CollectionEntry<"blog">;
const post: any = Astro.props;
// 获取封面图
import getCover from "../../utils/getCover";
import getCover from "@/utils/getCover";
const ARTICLE_COVER: string = await getCover(post.data.cover);
// 页面 Info
import SITE_CONFIG from "../../config";
import SITE_CONFIG from "@/config";
const { Site, Title, Author, Twikoo, GoogleAds } = SITE_CONFIG;
// 处理文章内容
const description = getDescription(post);
@@ -21,19 +21,21 @@ const { Content, remarkPluginFrontmatter } = await render(post);
// 文章字数和阅读时间
const { reading_time, article_word_count } = remarkPluginFrontmatter;
// 公共 Layout
import Layout from "../../layouts/Layout.astro";
import Layout from "@/layouts/Layout/Layout.astro";
// Aside组件
import Aside from "../../components/Aside.astro";
// Footer 组件
import Copyright from "../../components/Copyright.astro";
import Aside from "@/components/Aside/Aside.astro";
// Copyright 组件
import Copyright from "@/components/Copyright/Copyright.astro";
// Reward 组件
import Reward from "@/components/Reward/Reward.astro";
// 评论组件
import Comment from "../../components/Comment.astro";
import Comment from "@/components/Comment/Comment.astro";
// Google 广告组件
import GoogleAd from "../../components/GoogleAd.astro";
import GoogleAd from "@/components/GoogleAd/GoogleAd.astro";
// 文章页面样式
import "../../styles/Article.less";
import "@/styles/Article.less";
// 文章内容基础样式
import "../../styles/ArticleBase.less";
import "@/styles/ArticleBase.less";
---
<Layout title={post.data.title} keywords={post.data.tags} description={description} pagecover={ARTICLE_COVER}>
@@ -61,9 +63,12 @@ import "../../styles/ArticleBase.less";
</nav>
</main>
<footer>
<!-- 打赏组件 -->
<Reward />
<!-- 版权©️信息 -->
<Copyright site={Site} id={post.data.id} title={post.data.title} sitename={Title} time={fmtTime(post.data.date, "YYYY-MM-DD A")} auther={Author} />
<!-- 底部谷歌广告 -->
{GoogleAds.ad_Client && GoogleAds.articleAD_Slot && <GoogleAd className="vh-article-ad" slotID={GoogleAds.articleAD_Slot} />}
<Copyright site={Site} id={post.data.id} title={post.data.title} sitename={Title} time={fmtTime(post.data.date, "YYYY-MM-DD A")} auther={Author} />
</footer>
{Twikoo.envId && <Comment envId={Twikoo.envId} />}
</article>
+5 -5
View File
@@ -1,5 +1,5 @@
---
import { getCategoriesList } from "../../utils/getArchive";
import { getCategoriesList } from "@/utils/getArchive";
import { getCollection } from "astro:content";
export async function getStaticPaths(): Promise<any> {
const posts = await getCollection("blog");
@@ -9,14 +9,14 @@ export async function getStaticPaths(): Promise<any> {
const { categories } = Astro.params;
const articleList = await getCategoriesList(categories);
// 页面 Info
import SITE_CONFIG from "../../config";
import SITE_CONFIG from "@/config";
const { Description } = SITE_CONFIG;
// 公共 Layout
import Layout from "../../layouts/Layout.astro";
import Layout from "@/layouts/Layout/Layout.astro";
// Aside组件
import Aside from "../../components/Aside.astro";
import Aside from "@/components/Aside/Aside.astro";
// 文章列表组件
import Archive from "../../components/Archive.astro";
import Archive from "@/components/Archive/Archive.astro";
---
<Layout title={`分类 ${categories} 下的文章`} description={Description}>
+1 -1
View File
@@ -2,7 +2,7 @@
title: "朋友的新动态"
h1: "朋友的新动态 🎴"
desc: "来看看我的朋友们都在干嘛."
layout: "../../layouts/ToolLayout.astro"
layout: "@/layouts/ToolLayout/ToolLayout.astro"
type: "friends"
---
+1 -1
View File
@@ -2,7 +2,7 @@
title: "友情链接"
h1: "朋友圈 👭"
desc: "天下快意之事莫若友。"
layout: "../../layouts/ToolLayout.astro"
layout: "@/layouts/ToolLayout/ToolLayout.astro"
type: "links"
---
+1 -1
View File
@@ -2,7 +2,7 @@
title: "留言"
h1: "留言板 🌸"
desc: "快友之事莫若谈。"
layout: "../../layouts/ToolLayout.astro"
layout: "@/layouts/ToolLayout/ToolLayout.astro"
type: "message"
---
+2 -2
View File
@@ -1,7 +1,7 @@
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import { getDescription } from '../utils/index'
import SITE_CONFIG from '../config';
import { getDescription } from '@/utils/index'
import SITE_CONFIG from '@/config';
const { Title, Description } = SITE_CONFIG;
+5 -5
View File
@@ -1,5 +1,5 @@
---
import { getTagsList } from "../../utils/getArchive";
import { getTagsList } from "@/utils/getArchive";
import { getCollection } from "astro:content";
export async function getStaticPaths(): Promise<any> {
const posts = await getCollection("blog");
@@ -11,14 +11,14 @@ export async function getStaticPaths(): Promise<any> {
const { tags } = Astro.params;
const articleList = await getTagsList(tags);
// 页面 Info
import SITE_CONFIG from "../../config";
import SITE_CONFIG from "@/config";
const { Description } = SITE_CONFIG;
// 公共 Layout
import Layout from "../../layouts/Layout.astro";
import Layout from "@/layouts/Layout/Layout.astro";
// Aside组件
import Aside from "../../components/Aside.astro";
import Aside from "@/components/Aside/Aside.astro";
// 文章列表组件
import Archive from "../../components/Archive.astro";
import Archive from "@/components/Archive/Archive.astro";
---
<Layout title={`标签 ${tags} 下的文章`} description={Description}>
+1 -1
View File
@@ -2,7 +2,7 @@
title: "动态"
h1: "动态 🥫"
desc: "记录美好生活."
layout: "../../layouts/ToolLayout.astro"
layout: "@/layouts/ToolLayout/ToolLayout.astro"
type: "talking"
---