diff --git a/astro.config.mjs b/astro.config.mjs index aeb2c96..97ca0d9 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,8 +1,10 @@ -// @ts-check +import path from "path"; import mdx from '@astrojs/mdx'; import sitemap from '@astrojs/sitemap'; -import { defineConfig } from 'astro/config'; import Compress from "@playform/compress"; +import { defineConfig } from 'astro/config'; +import { fileURLToPath } from 'url'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Markdown 配置================ import remarkMath from "remark-math"; import rehypeSlug from "rehype-slug"; @@ -16,47 +18,31 @@ import swup from '@swup/astro'; export default defineConfig({ site: SITE_INFO.Site, build: { assets: 'vh_static' }, - integrations: [ - swup({ - theme: false, - animationClass: "vh-animation-", - containers: [".vh-animation"], - smoothScrolling: true, - progress: true, - cache: true, - preload: true, - accessibility: true, - updateHead: true, - updateBodyClass: false, - globalInstance: true - }), - Compress({ - CSS: false, - Image: false, - Action: { Passed: async () => true }, - }), - sitemap({ - changefreq: 'weekly', - priority: 0.7, - lastmod: new Date(), - // 处理末尾带 / 的 url - serialize: (item) => ({ ...item, url: item.url.endsWith('/') ? item.url.slice(0, -1) : item.url }) - }), - mdx({ extendMarkdownConfig: false }) - ], + integrations: [swup({ + theme: false, + animationClass: "vh-animation-", + containers: [".vh-animation"], + smoothScrolling: true, + progress: true, + cache: true, + preload: true, + accessibility: true, + updateHead: true, + updateBodyClass: false, + globalInstance: true + }), + Compress({ CSS: false, Image: false, Action: { Passed: async () => true } }), + sitemap({ + changefreq: 'weekly', priority: 0.7, lastmod: new Date(), + // 处理末尾带 / 的 url + serialize: (item) => ({ ...item, url: item.url.endsWith('/') ? item.url.slice(0, -1) : item.url }) + }), mdx({ extendMarkdownConfig: false })], markdown: { - remarkPlugins: [ - remarkMath, - remarkDirective, - remarkNote, - ], - rehypePlugins: [ - rehypeKatex, - rehypeSlug, - addClassNames - ], + remarkPlugins: [remarkMath, remarkDirective, remarkNote,], + rehypePlugins: [rehypeKatex, rehypeSlug, addClassNames], syntaxHighlight: 'shiki', shikiConfig: { theme: 'github-light' }, }, + vite: { resolve: { alias: { "@": path.resolve(__dirname, "./src"), "@public": path.resolve(__dirname, "./public") } } }, server: { host: '0.0.0.0' } -}); +}); \ No newline at end of file diff --git a/package.json b/package.json index b759f9a..51b77d1 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,12 @@ "newpost": "node ./script/newpost.js" }, "dependencies": { - "@astrojs/mdx": "^4.1.1", + "@astrojs/mdx": "^4.2.1", "@astrojs/rss": "^4.0.11", - "@astrojs/sitemap": "^3.2.1", + "@astrojs/sitemap": "^3.3.0", "@swup/astro": "^1.5.0", "aplayer": "^1.10.1", - "astro": "^5.4.3", + "astro": "^5.5.3", "overlayscrollbars": "^2.11.1", "vanilla-lazyload": "^19.1.3", "vh-plugin": "^1.2.2" diff --git a/public/assets/images/alipay.webp b/public/assets/images/alipay.webp new file mode 100644 index 0000000..610cf3e Binary files /dev/null and b/public/assets/images/alipay.webp differ diff --git a/public/assets/images/wechat.webp b/public/assets/images/wechat.webp new file mode 100644 index 0000000..658f4b6 Binary files /dev/null and b/public/assets/images/wechat.webp differ diff --git a/src/components/Archive.astro b/src/components/Archive/Archive.astro similarity index 89% rename from src/components/Archive.astro rename to src/components/Archive/Archive.astro index 4a9738d..5636d94 100644 --- a/src/components/Archive.astro +++ b/src/components/Archive/Archive.astro @@ -1,8 +1,8 @@ --- -import { fmtTime } from "../utils/index"; +import { fmtTime } from "@/utils/index"; const { articleList } = Astro.props; // 文章页面样式 -import "../styles/Archive.less"; +import "./Archive.less"; ---
diff --git a/src/styles/Archive.less b/src/components/Archive/Archive.less similarity index 100% rename from src/styles/Archive.less rename to src/components/Archive/Archive.less diff --git a/src/components/ArticleCard.astro b/src/components/ArticleCard/ArticleCard.astro similarity index 82% rename from src/components/ArticleCard.astro rename to src/components/ArticleCard/ArticleCard.astro index 937e1ae..22a0455 100644 --- a/src/components/ArticleCard.astro +++ b/src/components/ArticleCard/ArticleCard.astro @@ -1,14 +1,14 @@ --- import { Image } from "astro:assets"; -import { getDescription, fmtTime } from "../utils/index"; -const { post, index } = Astro.props; +import { getDescription, fmtTime } from "@/utils/index"; +const { post } = Astro.props; // 获取文章的摘要 const description = getDescription(post); // 获取封面图 -import getCover from "../utils/getCover"; +import getCover from "@/utils/getCover"; const ARTICLE_COVER: string = await getCover(post.data.cover); // 文章Item组件样式 -import "../styles/components/ArticleCard.less"; +import "./ArticleCard.less"; ---
diff --git a/src/styles/components/ArticleCard.less b/src/components/ArticleCard/ArticleCard.less similarity index 100% rename from src/styles/components/ArticleCard.less rename to src/components/ArticleCard/ArticleCard.less diff --git a/src/components/Aside.astro b/src/components/Aside/Aside.astro similarity index 90% rename from src/components/Aside.astro rename to src/components/Aside/Aside.astro index 4f4e068..cd02d06 100644 --- a/src/components/Aside.astro +++ b/src/components/Aside/Aside.astro @@ -2,12 +2,12 @@ // 静态图片 import { Image } from "astro:assets"; // 时间处理 -import { fmtTime } from "../utils/index"; +import { fmtTime } from "@/utils/index"; // 获取用户配置数据 -import SITE_CONFIG from "../config"; +import SITE_CONFIG from "@/config"; const { Avatar, Author, Motto, WebSites, GoogleAds } = SITE_CONFIG; // 获取文章数据 -import { getCategories, getTags, getRecommendArticles } from "../utils/getPostInfo"; +import { getCategories, getTags, getRecommendArticles } from "@/utils/getPostInfo"; // 分类列表 const categories = getCategories(); // 热门标签 @@ -15,9 +15,9 @@ const tags = getTags(); // 最新文章 const recommendArticles = getRecommendArticles(); // Google 广告组件 -import GoogleAd from "../components/GoogleAd.astro"; +import GoogleAd from "@/components/GoogleAd/GoogleAd.astro"; // 侧边栏样式 -import "../styles/components/Aside.less"; +import "./Aside.less"; ---
diff --git a/src/pages/categories/[...categories].astro b/src/pages/categories/[...categories].astro index 6e2d9c8..42a3749 100644 --- a/src/pages/categories/[...categories].astro +++ b/src/pages/categories/[...categories].astro @@ -1,5 +1,5 @@ --- -import { getCategoriesList } from "../../utils/getArchive"; +import { getCategoriesList } from "@/utils/getArchive"; import { getCollection } from "astro:content"; export async function getStaticPaths(): Promise { const posts = await getCollection("blog"); @@ -9,14 +9,14 @@ export async function getStaticPaths(): Promise { 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"; --- diff --git a/src/pages/friends/index.md b/src/pages/friends/index.md index 3916851..ba1ab95 100644 --- a/src/pages/friends/index.md +++ b/src/pages/friends/index.md @@ -2,7 +2,7 @@ title: "朋友的新动态" h1: "朋友的新动态 🎴" desc: "来看看我的朋友们都在干嘛." -layout: "../../layouts/ToolLayout.astro" +layout: "@/layouts/ToolLayout/ToolLayout.astro" type: "friends" --- diff --git a/src/pages/links/index.md b/src/pages/links/index.md index 15d0c3d..c296b34 100644 --- a/src/pages/links/index.md +++ b/src/pages/links/index.md @@ -2,7 +2,7 @@ title: "友情链接" h1: "朋友圈 👭" desc: "天下快意之事莫若友。" -layout: "../../layouts/ToolLayout.astro" +layout: "@/layouts/ToolLayout/ToolLayout.astro" type: "links" --- diff --git a/src/pages/message/index.md b/src/pages/message/index.md index 2afec00..85d49b2 100644 --- a/src/pages/message/index.md +++ b/src/pages/message/index.md @@ -2,7 +2,7 @@ title: "留言" h1: "留言板 🌸" desc: "快友之事莫若谈。" -layout: "../../layouts/ToolLayout.astro" +layout: "@/layouts/ToolLayout/ToolLayout.astro" type: "message" --- diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index 88d6c16..8eec8e5 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -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; diff --git a/src/pages/tag/[...tags].astro b/src/pages/tag/[...tags].astro index 50d2b39..73a0234 100644 --- a/src/pages/tag/[...tags].astro +++ b/src/pages/tag/[...tags].astro @@ -1,5 +1,5 @@ --- -import { getTagsList } from "../../utils/getArchive"; +import { getTagsList } from "@/utils/getArchive"; import { getCollection } from "astro:content"; export async function getStaticPaths(): Promise { const posts = await getCollection("blog"); @@ -11,14 +11,14 @@ export async function getStaticPaths(): Promise { 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"; --- diff --git a/src/pages/talking/index.md b/src/pages/talking/index.md index b01221d..8209978 100644 --- a/src/pages/talking/index.md +++ b/src/pages/talking/index.md @@ -2,7 +2,7 @@ title: "动态" h1: "动态 🥫" desc: "记录美好生活." -layout: "../../layouts/ToolLayout.astro" +layout: "@/layouts/ToolLayout/ToolLayout.astro" type: "talking" --- diff --git a/src/scripts/Comment.ts b/src/scripts/Comment.ts index e70338a..c0e1ee6 100644 --- a/src/scripts/Comment.ts +++ b/src/scripts/Comment.ts @@ -1,8 +1,8 @@ -import SITE_INFO from "../config"; +import SITE_INFO from "@/config"; // 图片灯箱 -import "../../public/assets/js/view-image.min.js"; +import "@public/assets/js/view-image.min.js"; declare const ViewImage: any; -import { LoadScript } from "../utils/index"; +import { LoadScript } from "@/utils/index"; declare const twikoo: any; // 处理评论区数据 diff --git a/src/scripts/Footer.ts b/src/scripts/Footer.ts index b80780b..3d95698 100644 --- a/src/scripts/Footer.ts +++ b/src/scripts/Footer.ts @@ -1,7 +1,7 @@ // 格式化时间 -import { fmtDate } from "../utils/index"; +import { fmtDate } from "@/utils/index"; // 页面内容的元数据 -import SITE_CONFIG from "../config"; +import SITE_CONFIG from "@/config"; const { CreateTime } = SITE_CONFIG; // 初始化 网站运行时间 export default () => (document.querySelector("em.web_time")!.textContent = fmtDate(CreateTime)) \ No newline at end of file diff --git a/src/scripts/Friends.ts b/src/scripts/Friends.ts index 0aa8f19..925a1b3 100644 --- a/src/scripts/Friends.ts +++ b/src/scripts/Friends.ts @@ -1,7 +1,7 @@ import vh from 'vh-plugin' -import { fmtDate } from '../utils/index' -import { $GET } from '../utils/index' +import { fmtDate } from '@/utils/index' +import { $GET } from '@/utils/index' const FriendsInit = async (data: any) => { const friendsDOM = document.querySelector('.vh-container>.vh-tools-main>main.friends-main') @@ -18,6 +18,6 @@ const FriendsInit = async (data: any) => { } // 朋友圈 RSS 初始化 -import FRIENDS_DATA from "../page_data/Friends"; +import FRIENDS_DATA from "@/page_data/Friends"; const { api, data } = FRIENDS_DATA; export default () => FriendsInit(api || data); \ No newline at end of file diff --git a/src/scripts/GoogleAd.ts b/src/scripts/GoogleAd.ts index 3d35ae2..8b006d1 100644 --- a/src/scripts/GoogleAd.ts +++ b/src/scripts/GoogleAd.ts @@ -5,7 +5,7 @@ declare global { adsbygoogle: any[]; } } -import SITE_INFO from '../config' +import SITE_INFO from '@/config' const { GoogleAds } = SITE_INFO export default () => { const asideAD: any = document.querySelector('.vh-aside-ad') diff --git a/src/scripts/HanAnalytics.ts b/src/scripts/HanAnalytics.ts index 751db40..6984d36 100644 --- a/src/scripts/HanAnalytics.ts +++ b/src/scripts/HanAnalytics.ts @@ -1,7 +1,7 @@ // Han Analytics 统计 -import SITE_INFO from "../config"; -import { LoadScript } from "../utils/index"; +import SITE_INFO from "@/config"; +import { LoadScript } from "@/utils/index"; export default async () => { const { HanAnalytics } = SITE_INFO; diff --git a/src/scripts/Init.ts b/src/scripts/Init.ts index 31fced5..9f8b9be 100644 --- a/src/scripts/Init.ts +++ b/src/scripts/Init.ts @@ -1,38 +1,38 @@ -import { inRouter, outRouter } from "../utils/updateRouter"; +import { inRouter, outRouter } from "@/utils/updateRouter"; // 初始化文章代码块 -import codeInit from "../scripts/Code"; +import codeInit from "@/scripts/Code"; // 初始化视频播放器 -import videoInit from "../scripts/Video"; +import videoInit from "@/scripts/Video"; // 初始化音乐播放器 -import musicInit from "../scripts/Music"; +import musicInit from "@/scripts/Music"; // 初始化 LivePhoto -import livePhotoInit from './LivePhoto' +import livePhotoInit from '@/scripts/LivePhoto' // 初始化BackTop组件 -import BackTopInitFn from "../scripts/BackTop"; +import BackTopInitFn from "@/scripts/BackTop"; // 搜索 -import { searchFn, vhSearchInit } from "../scripts/Search"; +import { searchFn, vhSearchInit } from "@/scripts/Search"; // 图片懒加载 -import vhLzImgInit from "../scripts/vhLazyImg"; +import vhLzImgInit from "@/scripts/vhLazyImg"; // 顶部导航 Current 状态 -import initLinkCurrent from "../scripts/Header"; +import initLinkCurrent from "@/scripts/Header"; // 底部网站运行时间 -import initWebSiteTime from "../scripts/Footer"; +import initWebSiteTime from "@/scripts/Footer"; // 友情链接初始化 -import initLinks from "../scripts/Links"; +import initLinks from "@/scripts/Links"; // 朋友圈 RSS 初始化 -import initFriends from "../scripts/Friends"; +import initFriends from "@/scripts/Friends"; // 动态说说初始化 -import initTalking from "../scripts/Talking"; +import initTalking from "@/scripts/Talking"; // 文章评论初始化 -import initComment from "../scripts/Comment"; +import initComment from "@/scripts/Comment"; // 移动端侧边栏初始化 -import initMobileSidebar from "../scripts/MobileSidebar"; +import initMobileSidebar from "@/scripts/MobileSidebar"; // Google 广告 -import GoogleAdInit from "../scripts/GoogleAd"; +import GoogleAdInit from "@/scripts/GoogleAd"; // Han Analytics 统计 -import HanAnalyticsInit from "../scripts/HanAnalytics"; +import HanAnalyticsInit from "@/scripts/HanAnalytics"; // SmoothScroll 滚动优化 -import SmoothScroll from "../scripts/Smoothscroll"; +import SmoothScroll from "@/scripts/Smoothscroll"; // ============================================================ diff --git a/src/scripts/Links.ts b/src/scripts/Links.ts index 3a4410c..12aa964 100644 --- a/src/scripts/Links.ts +++ b/src/scripts/Links.ts @@ -1,7 +1,7 @@ import vh from 'vh-plugin' -import { $GET } from '../utils/index' +import { $GET } from '@/utils/index' // 图片懒加载 -import vhLzImgInit from "../scripts/vhLazyImg"; +import vhLzImgInit from "@/scripts/vhLazyImg"; // 渲染 const LinksInit = async (data: any) => { const linksDOM = document.querySelector('.vh-container>.vh-tools-main>main.links-main') @@ -20,6 +20,6 @@ const LinksInit = async (data: any) => { } // 友情链接初始化 -import LINKS_DATA from "../page_data/Link"; +import LINKS_DATA from "@/page_data/Link"; const { api, data } = LINKS_DATA; export default () => LinksInit(api || data) \ No newline at end of file diff --git a/src/scripts/LivePhoto.ts b/src/scripts/LivePhoto.ts index 822fc94..9c5f5a9 100644 --- a/src/scripts/LivePhoto.ts +++ b/src/scripts/LivePhoto.ts @@ -1,5 +1,5 @@ // SmoothScroll 滚动优化 -import { LoadScript } from "../utils/index"; +import { LoadScript } from "@/utils/index"; declare const LivePhotosKit: any; export default async () => { const livePhotoList = document.querySelectorAll('.vh-node.vh-vhLivePhoto'); diff --git a/src/scripts/Music.ts b/src/scripts/Music.ts index 3821b51..2f77050 100644 --- a/src/scripts/Music.ts +++ b/src/scripts/Music.ts @@ -1,6 +1,6 @@ -import SITE_CONFIG from "../config"; +import SITE_CONFIG from "@/config"; const { vhMusicApi } = SITE_CONFIG; -import { $GET } from '../utils/index' +import { $GET } from '@/utils/index' import 'aplayer/dist/APlayer.min.css'; import APlayer from 'aplayer'; diff --git a/src/scripts/Search.ts b/src/scripts/Search.ts index 8d4e42d..0b08b83 100644 --- a/src/scripts/Search.ts +++ b/src/scripts/Search.ts @@ -1,4 +1,4 @@ -import { $GET } from '../utils/index' +import { $GET } from '@/utils/index' // 更新数据 let searchJson: any[] = []; diff --git a/src/scripts/Smoothscroll.ts b/src/scripts/Smoothscroll.ts index 77fbb80..bbff9d3 100644 --- a/src/scripts/Smoothscroll.ts +++ b/src/scripts/Smoothscroll.ts @@ -1,5 +1,5 @@ // SmoothScroll 滚动优化 -import { LoadScript } from "../utils/index"; +import { LoadScript } from "@/utils/index"; declare const SmoothScroll: any; export default async () => { await LoadScript("/assets/js/smoothscroll.min.js"); diff --git a/src/scripts/Talking.ts b/src/scripts/Talking.ts index c77813a..61ddfe3 100644 --- a/src/scripts/Talking.ts +++ b/src/scripts/Talking.ts @@ -1,11 +1,11 @@ import vh from 'vh-plugin' -import { fmtDate } from '../utils/index' -import { $GET } from '../utils/index' +import { fmtDate } from '@/utils/index' +import { $GET } from '@/utils/index' // 图片懒加载 -import vhLzImgInit from "../scripts/vhLazyImg"; +import vhLzImgInit from "@/scripts/vhLazyImg"; // 灯箱JS初始化====== -import "../../public/assets/js/view-image.min.js"; +import "@public/assets/js/view-image.min.js"; declare const ViewImage: any; // 灯箱JS初始化====== @@ -30,6 +30,6 @@ const TalkingInit = async (data: any) => { // 动态说说初始化 -import TALKING_DATA from "../page_data/Talking"; +import TALKING_DATA from "@/page_data/Talking"; const { api, data } = TALKING_DATA; export default () => TalkingInit(api || data); \ No newline at end of file diff --git a/src/scripts/Video.ts b/src/scripts/Video.ts index ae55fd7..ebe0629 100644 --- a/src/scripts/Video.ts +++ b/src/scripts/Video.ts @@ -1,4 +1,4 @@ -import { LoadScript } from "../utils/index"; +import { LoadScript } from "@/utils/index"; // 初始化视频播放器 declare const DPlayer: any; declare const Hls: any; diff --git a/src/styles/Base.less b/src/styles/Base.less index 3772750..578d005 100644 --- a/src/styles/Base.less +++ b/src/styles/Base.less @@ -215,9 +215,9 @@ html.is-animating { z-index: 1; &.vh-article-ad { + margin-bottom: 1rem; box-sizing: border-box; padding: 0.75rem; - margin-top: 1rem; border-radius: 0.5rem; background-color: #fff; box-shadow: 0 3px 8px 6px rgba(7, 17, 27, 0.05); diff --git a/src/styles/components/MainHeader.less b/src/styles/components/MainHeader.less deleted file mode 100644 index 83ee959..0000000 --- a/src/styles/components/MainHeader.less +++ /dev/null @@ -1,18 +0,0 @@ -// main.vh-main { - -// &>header.main-header { -// box-sizing: border-box; -// width: 100%; -// height: 10rem; -// overflow: hidden; -// transition: all 2s ease-in-out; -// } - - -// &.vh-index { -// &>header.main-header { -// height: 20rem; -// transition: all 2s ease-in-out; -// } -// } -// } \ No newline at end of file diff --git a/src/utils/getCover.ts b/src/utils/getCover.ts index a40e035..0eadaff 100644 --- a/src/utils/getCover.ts +++ b/src/utils/getCover.ts @@ -2,7 +2,7 @@ import path from 'path'; import _fs from 'fs'; const fs = _fs.promises; import { fileURLToPath } from 'url'; -import SITE_INFO from '../config'; +import SITE_INFO from '@/config'; // 获取当前模块的目录路径 const __filename = fileURLToPath(import.meta.url); // 当前文件的绝对路径 const __dirname = path.dirname(__filename); // 当前文件所在的目录 diff --git a/src/utils/getPostInfo.ts b/src/utils/getPostInfo.ts index 758a219..ef85503 100644 --- a/src/utils/getPostInfo.ts +++ b/src/utils/getPostInfo.ts @@ -1,6 +1,6 @@ import { getCollection } from "astro:content"; // 获取封面图 -import getCover from "../utils/getCover"; +import getCover from "@/utils/getCover"; const posts = (await getCollection("blog")).sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()); // 获取文章分类 const getCategories = () => { diff --git a/tsconfig.json b/tsconfig.json index 25ab80d..7ffb72d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,22 @@ { "extends": "astro/tsconfigs/strict", + "compilerOptions": { + "strictNullChecks": true, + "jsx": "preserve", + "paths": { + "@/*": [ + "./src/*" + ], + "@public/*": [ + "./public/*" + ], + } + }, "include": [ ".astro/types.d.ts", "**/*" ], "exclude": [ "dist" - ], - "compilerOptions": { - "strictNullChecks": true - } + ] } \ No newline at end of file