--- import { render } from "astro:content"; import * as path from "node:path"; import Comment from "@components/comment/index.astro"; import Markdown from "@components/common/Markdown.astro"; import EncryptedPost from "@components/features/EncryptedPost.astro"; import KatexManager from "@components/features/KatexManager.astro"; import License from "@components/misc/License.astro"; import I18nKey from "@i18n/i18nKey"; import { i18n } from "@i18n/translation"; import MainGridLayout from "@layouts/MainGridLayout.astro"; import { getRelatedPosts, getSortedPosts } from "@utils/content-utils"; import { getFileDirFromPath, getPostUrlBySlug, removeFileExtension, } from "@utils/url-utils"; import { Icon } from "astro-icon/components"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; import CoverImage from "@/components/common/CoverImage.astro"; import PostMetadata from "@/components/layout/PostMeta.astro"; import RecommendedPost from "@/components/misc/RecommendedPost.astro"; import SharePoster from "@/components/misc/SharePoster.svelte"; import { coverImageConfig } from "@/config/coverImageConfig"; import { licenseConfig } from "@/config/licenseConfig"; import { profileConfig } from "@/config/profileConfig"; import { siteConfig } from "@/config/siteConfig"; import { sponsorConfig } from "@/config/sponsorConfig"; import { formatDateToYYYYMMDD } from "@/utils/date-utils"; import { getApiUrlList, processCoverImageSync } from "@/utils/image-utils"; import { url } from "@/utils/url-utils"; export async function getStaticPaths() { const blogEntries = await getSortedPosts(); return blogEntries.map((entry) => { // 将 id 转换为 slug(移除扩展名)以匹配路由参数 const slug = removeFileExtension(entry.id); return { params: { slug }, props: { entry }, }; }); } const { entry } = Astro.props; const { Content, headings } = await render(entry); const { remarkPluginFrontmatter } = await render(entry); const bannerPostMeta = { title: entry.data.title, published: entry.data.published, updated: entry.data.updated, words: remarkPluginFrontmatter.words, minutes: remarkPluginFrontmatter.minutes, }; // 处理随机图:如果image为"api",则从配置的API获取随机图 const processedImage = processCoverImageSync(entry.data.image, entry.id); const apiUrls = getApiUrlList(entry.data.image, entry.id); let posterCoverUrl = processedImage; if (processedImage) { const isLocal = !( processedImage.startsWith("/") || processedImage.startsWith("http") || processedImage.startsWith("https") || processedImage.startsWith("data:") ); if (isLocal) { const basePath = getFileDirFromPath(entry.filePath || ""); const files = import.meta.glob("../../**", { import: "default", }); let normalizedPath = path .normalize(path.join("../../", basePath, processedImage)) .replace(/\\/g, "/"); const file = files[normalizedPath]; if (file) { const img = await file(); posterCoverUrl = img.src; } } } // 处理头像URL let posterAvatarUrl: string | null = profileConfig.avatar || null; if (posterAvatarUrl) { const isLocalAvatar = !( posterAvatarUrl.startsWith("/") || posterAvatarUrl.startsWith("http") || posterAvatarUrl.startsWith("https") || posterAvatarUrl.startsWith("data:") ); if (isLocalAvatar) { const files = import.meta.glob("../../**", { import: "default", }); const normalizedPath = path .normalize(path.join("../../", posterAvatarUrl)) .replace(/\\/g, "/"); const file = files[normalizedPath]; if (file) { const img = await file(); posterAvatarUrl = img.src; } } } dayjs.extend(utc); const jsonLd = { "@context": "https://schema.org", "@type": "BlogPosting", headline: entry.data.title, description: entry.data.description || entry.data.title, keywords: entry.data.tags, url: Astro.url.href, author: { "@type": "Person", name: profileConfig.name, url: Astro.site, }, publisher: { "@type": "Person", name: profileConfig.name, url: Astro.site, }, datePublished: formatDateToYYYYMMDD(entry.data.published), dateModified: formatDateToYYYYMMDD(entry.data.updated || entry.data.published), ...(processedImage ? { image: new URL(processedImage.startsWith("/") ? processedImage : `/${processedImage}`, Astro.site).href } : {}), inLanguage: entry.data.lang ? entry.data.lang.replace("_", "-") : siteConfig.lang.replace("_", "-"), }; const relatedPosts = await getRelatedPosts(entry, 5); --- {entry.data.comment && !entry.data.password && }