Skip to content

Commit

Permalink
refactor: 重构全局配置文件,以适应未来计划
Browse files Browse the repository at this point in the history
  • Loading branch information
Tikas committed Jul 24, 2024
1 parent 0465b0b commit eef5307
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 103 deletions.
2 changes: 1 addition & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from "astro/config";
import { rehypeAccessibleEmojis } from "rehype-accessible-emojis";
import { SITE } from "./src/content/custom";
import { SITE } from "./src/content/site.config";
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";

Expand Down
4 changes: 2 additions & 2 deletions src/example_content/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCollection, z } from "astro:content";
import { CONFIG } from "@/content/custom";
import { CONFIG } from "@/content/site.config";

const DEFAULT_AUTHOR = CONFIG.AUTHOR !== undefined && CONFIG.AUTHOR;
const DEFAULT_AUTHOR = CONFIG.DEFAULT_AUTHOR !== undefined && CONFIG.DEFAULT_AUTHOR;

const blogCollection = defineCollection({
type: "content",
Expand Down
89 changes: 0 additions & 89 deletions src/example_content/custom.ts

This file was deleted.

69 changes: 69 additions & 0 deletions src/example_content/site.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 引入类型声明
// Introduce type declaration
import type { Config, Metadata } from "@/content/types";

// 在这里设置你的网站地址,请以 "http://" 或者 "https://" 开头
// Set your website address here, please start with "http://" or "https://"
// 如果暂时不想设置,请保持默认值:"http://example.com"
// If you do not want to set it yet, please keep the default value: "http://example.com"
export const SITE: string = "http://example.com";

// 网站相关信息
// Website related information
export const CONFIG: Config = {
// 全站文本内容书写方向:
// ltr = 从左到右,默认值,用于从左向右书写的语言(比如英语、中文等)
// rtl = 从右到左,用于从右向左书写的语言(比如阿拉伯语)
// The writing direction of the text content of the whole site:
// ltr = left to right, default value, used for languages ​​written from left to right (such as English, Chinese, etc.)
// rtl = right-to-left, for languages ​​written from right to left (such as Arabic)
DIR: "ltr",

// 设置网站的默认图标
// Set the default icon for the website
FAVICON: "favicon.ico",

// 设置网站的默认语言
// Set the default language for your website, for example "en"
DEFAULT_LOCALE: "zh-cn",

// 网站标题。显示在浏览器标签页和社交媒体分享中。
// Website title. Displayed in browser tab and social media shares.
DEFAULT_TITLE: "Volantis GO",

// 网站简短描述。用于搜索引擎优化和社交媒体分享。
// Short website description. Used for SEO and social media shares.
DEFAULT_DESCRIPTION: "A content site built with Astro",

// 默认作者名称。用于文章元数据和作者页面。
// Default author name. Used for article metadata and author pages.
DEFAULT_AUTHOR: "Admin",

// 是否在页面标题后添加网站标题。仅当标题字数较少时添加,例如 "页面标题 | 网站标题"。
// Append website title to page titles. Only applied when the title is short, e.g., "Page Title | Website Title".
ADD_TITLE: true,

// 标题分隔符。仅当 ADD_TITLE 为 true 时生效。 true 使用 "|",false 使用 "-"。
// Title delimiter. Only takes effect when ADD_TITLE is true. True for "|", false for "-".
DELIMITER: false,

// 是否启用页面切换动画。
// Enable page transition animations.
VIEW_TRANSITIONS: true,

// 是否启用较小字体大小 (true = 14px, false = 16px).
// Whether to use smaller font size (true = 14px, false = 16px).
USE_SMALLER_FONT: false,
};

// 网站首页的页面信息
// Page information on the homepage of the website
export const HOME: Metadata = {
// 网站首页标题,用于浏览器标签页和社交媒体分享。
// Homepage title, displayed in browser tab and social media shares.
DEFAULT_TITLE: "Home",

// 网站首页简短描述,用于搜索引擎优化和社交媒体分享。
// Short homepage description, used for SEO and social media shares.
DEFAULT_DESCRIPTION: "Welcome to Volantis GO",
};
File renamed without changes.
10 changes: 5 additions & 5 deletions src/layouts/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import "@/styles/base.css";
import "@/styles/global.css";
import "@/content/custom.css";
import { CONFIG } from "@/content/custom";
import { CONFIG } from "@/content/site.config";
import { ViewTransitions } from "astro:transitions";
type Props = {
Expand All @@ -20,16 +20,16 @@ type Props = {
const { description, pageType } = Astro.props;
const favicon = CONFIG.FAVICON ? CONFIG.FAVICON : "favicon.ico";
const author = Astro.props.author || CONFIG.AUTHOR || "";
const author = Astro.props.author || CONFIG.DEFAULT_AUTHOR || "";
const joinDelimiter = CONFIG.DELIMITER ? ` | ` : ` - `;
// 如果标题过长,就仅使用页面标题,否则,标题会包含站点名称(仅在 custom 里开启添加标题)
// If the title is too long, just use the page title, otherwise the title will include the site name (Only enable adding title in custom)
const title = Astro.props.title
? Astro.props.title.length + CONFIG.TITLE.length + 3 <= 55 && CONFIG.ADD_TITLE
? [Astro.props.title, CONFIG.TITLE].join(joinDelimiter)
? Astro.props.title.length + CONFIG.DEFAULT_TITLE.length + 3 <= 55 && CONFIG.ADD_TITLE
? [Astro.props.title, CONFIG.DEFAULT_TITLE].join(joinDelimiter)
: Astro.props.title
: CONFIG.TITLE;
: CONFIG.DEFAULT_TITLE;
// 如果没有图片则使用网站图标
// If there is no image, use a favicon
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { CONFIG } from "@/content/custom";
import { CONFIG } from "@/content/site.config";
import BaseHead from "@/layouts/BaseHead.astro";
import Header from "@/layouts/components/Header.astro";
Expand All @@ -17,10 +17,10 @@ type Props = {
};
const {
title = CONFIG.TITLE,
description = CONFIG.DESCRIPTION,
title = CONFIG.DEFAULT_TITLE,
description = CONFIG.DEFAULT_DESCRIPTION,
date,
author = CONFIG.AUTHOR,
author = CONFIG.DEFAULT_AUTHOR,
categories,
tags,
image,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function getStaticPaths() {
type Props = CollectionEntry<"blog">;
const post = Astro.props;
const { Content, headings } = await post.render();
const { Content } = await post.render();
---

<BaseLayout
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import BaseLayout from "@/layouts/BaseLayout.astro";
import { HOME } from "@/content/custom";
import { HOME } from "@/content/site.config";
---

<BaseLayout title={HOME.TITLE} description={HOME.DESCRIPTION} />

0 comments on commit eef5307

Please sign in to comment.