Skip to content
Donghai's Blog
Go back

如何配置AstroPaper主题(译)

原文章:How to configure AstroPaper theme

AstroPaper是一个高度可定制的Astro博客主题。使用AstroPaper,你可以根据个人品味自定义一切。本文将解释如何在配置文件中轻松进行一些自定义。

Table of contents

Open Table of contents

配置SITE

重要的配置项位于 src/config.ts 文件中。在该文件中,你会看到 SITE 对象,在这里你可以指定你网站的主要配置。

在开发过程中,SITE.website 可以留空。但是在生产模式下,你应该在 SITE.website 选项中指定你的部署网址,因为这将用于规范URL、社交卡片URL等,这些对SEO很重要。

export const SITE = {
  website: "https://astro-paper.pages.dev/", // 将此替换为你的部署域名
  author: "Sat Naing",
  profile: "https://satnaing.dev/",
  desc: "一个简约、响应式且对SEO友好的Astro博客主题。",
  title: "AstroPaper",
  ogImage: "astropaper-og.jpg",
  lightAndDarkMode: true,
  postPerIndex: 4,
  postPerPage: 4,
  scheduledPostMargin: 15 * 60 * 1000, // 15分钟
  showArchives: true,
  showBackButton: true, // 在文章详情中显示返回按钮
  editPost: {
    enabled: true,
    text: "Suggest Changes",
    url: "https://github.com/satnaing/astro-paper/edit/main/",
  },
  dynamicOgImage: true, // 启用自动动态og-image生成
  dir: "ltr", // "rtl" | "auto"
  lang: "en", // html语言代码。留空则默认是"en"
  timezone: "Asia/Bangkok", // 默认全球时区(IANA格式)
} as const;
src/config.ts

以下是SITE配置选项:

选项 描述
website 部署的网站URL
author 你的名字
profile 你的个人/作品集网站URL,用于优化SEO。如果没有,请设置为 null 或空字符串 ""
desc 你的网站描述。对SEO和社交媒体分享非常有用
title 你的网站名称
ogImage 网站的默认OG图片。对社交媒体分享非常有用。OG图片可以是外部图片URL,也可以放置在 /public 目录下
lightAndDarkMode 启用或禁用网站的明亮与黑暗模式。如果禁用,将使用主要配色方案,此选项默认启用
postPerIndex 在主页的“最近”部分显示的帖子数量
postPerPage 你可以指定每个帖子页面将显示多少个帖子。(例如:如果你将 SITE.postPerPage 设置为3,则每页只显示3个帖子)
scheduledPostMargin 在生产模式下,未来 pubDatetime 的帖子将不可见。然而,如果帖子的 pubDatetime 在接下来的15分钟内,它将可见。如果你不喜欢默认的15分钟间隔,可以设置 scheduledPostMargin
showArchives 确定是否在网站上显示 Archives 菜单(位于 AboutSearch 菜单之间)及其对应页面。此选项默认设置为 true
showBackButton 确定是否在每个博客帖子中显示返回按钮
editPost 此选项允许用户通过在博客帖子标题下提供编辑链接来建议更改。通过将 SITE.editPost.enabled 设置为 false 可以禁用此功能
dynamicOgImage 此选项控制是否在博客帖子前言中未指定 ogImage生成动态og-image。如果你有很多博客帖子,可能希望禁用此功能。有关更多详细信息,请查看权衡
dir 指定整个博客的文本方向,用作 <html dir="ltr"> 中的 HTML dir属性。支持的值:ltr | rtl | auto
lang 用作 <html lang="en"> 中的HTML ISO语言代码。默认是 en
timezone 此选项允许你使用IANA格式指定时区。设置此项可以确保你的本地和已部署网站之间的时间戳一致,消除时间差异

更新布局宽度

整个博客的默认 max-width768px (max-w-3xl)。如果你想更改它,可以轻松地在 global.css 中更新 max-w-app,例如:

@utility max-w-app {
  @apply max-w-3xl;
  @apply max-w-4xl xl:max-w-5xl;
}src/styles/global.css

你可以在Tailwind CSS文档中探索更多的 max-width 值。

配置徽标或标题

在 AstroPaper v5 之前,你可以在 src/config.ts 文件中的 LOGO_IMAGE 对象中更新你的网站名称/徽标。然而,在 AstroPaper v5 中,此选项已被移除,取而代之的是Astro内置的SVG和图像组件

An arrow pointing at the website logo

你可以选择以下3种选项:

选项1:SITE标题文本

这是最简单的选项。你只需在 src/config.ts 文件中更新 SITE.title

选项2:Astro的SVG组件

如果你想使用SVG徽标,可以选择此选项。

这种方法的最佳之处在于,你可以根据需要自定义SVG样式。在上面的示例中,你可以看到如何在黑暗模式下反转SVG徽标的颜色

选项3: Astro的图像组件

如果你的徽标是图像但不是SVG,可以使用Astro的图像组件。

With this approach, you can still adjust your image’s appearance using CSS classes. However, this might not always fit what you want. If you need to display different logo images based on light or dark mode, check how light/dark icons are handled inside the Header.astro component.

通过这种方法,你仍然可以使用CSS类调整图像的外观。然而,这可能并不总是符合你的需求。如果你需要根据光明或黑暗模式显示不同的徽标图像,请查看 Header.astro 组件中如何处理光明/黑暗图标。

配置社交链接

An arrow pointing at social link icons

你可以在 constants.ts 文件中的 SOCIALS 对象中配置社交链接

export const SOCIALS = [
  {
    name: "GitHub",
    href: "https://github.com/satnaing/astro-paper",
    linkTitle: ` ${SITE.title} on GitHub`,
    icon: IconGitHub,
  },
  {
    name: "X",
    href: "https://x.com/username",
    linkTitle: `${SITE.title} on X`,
    icon: IconBrandX,
  },
  {
    name: "LinkedIn",
    href: "https://www.linkedin.com/in/username/",
    linkTitle: `${SITE.title} on LinkedIn`,
    icon: IconLinkedin,
  },
  {
    name: "Mail",
    href: "mailto:yourmail@gmail.com",
    linkTitle: `Send an email to ${SITE.title}`,
    icon: IconMail,
  },
] as const;src/constants.ts

配置分享链接

你可以在 constants.ts 文件中的 SHARE_LINKS 对象中配置分享链接。

An arrow pointing at share link icons

总结

这是关于如何自定义此主题的简要说明。如果你了解一些编码,可以进行更多自定义。有关样式自定义,请阅读这篇文章。感谢你的阅读。✌🏻


Share this post on:

Previous Post
在AstroPaper主题中添加新帖子(译)
Next Post
使用 ClientSecret 授权方式 在 .NET 控制台应用中连接 Dynamics 365
BlogsClub Meo Forever Blog