feat: bump the astro to v5.

This commit is contained in:
Yufan Sheng 2024-12-03 21:33:19 +08:00
parent 3433ed7155
commit 4532101db1
Signed by: syhily
GPG Key ID: DEB186763C308C31
11 changed files with 891 additions and 1658 deletions

View File

@ -196,7 +196,7 @@ to get it worked everywhere.
This weblog is deployed on the [zeabur](https://zeabur.com) platform. This weblog is deployed on the [zeabur](https://zeabur.com) platform.
You can check their documents and get your own weblog to be published without any budget at first. You can check their documents and get your own weblog to be published without any budget at first.
Or you can host on your own machine. Use [Dockerfile](./docs/Dockerfile) to build an image and run it locally. Or you can host on your own machine. Use [Dockerfile](./Dockerfile) to build an image and run it locally.
The comment system is leverage the [Artalk](https://artalk.js.org), a self-hosted comment system. The comment system is leverage the [Artalk](https://artalk.js.org), a self-hosted comment system.
You should host it on your own machine. You should host it on your own machine.
@ -222,8 +222,8 @@ You should host it on your own machine.
The source code of this blog is licensed under the [MIT](LICENSE) license, The source code of this blog is licensed under the [MIT](LICENSE) license,
feel to free to use it without any legal risks. feel to free to use it without any legal risks.
The [content](src/content) of this blog's posts is licensed under the The [content](content) of this blog's posts is licensed under the
[CC BY-NC-SA 4.0](src/content/LICENSE) license. [CC BY-NC-SA 4.0](content/LICENSE) license.
### Logo Fonts License ### Logo Fonts License

View File

@ -1,5 +1,5 @@
import mdx from '@astrojs/mdx'; import mdx from '@astrojs/mdx';
import zeabur from '@zeabur/astro-adapter/serverless'; import node from '@astrojs/node';
import { uploader } from 'astro-uploader'; import { uploader } from 'astro-uploader';
import { defineConfig, envField } from 'astro/config'; import { defineConfig, envField } from 'astro/config';
import rehypeAutolinkHeadings from 'rehype-autolink-headings'; import rehypeAutolinkHeadings from 'rehype-autolink-headings';
@ -22,8 +22,8 @@ export default defineConfig({
service: !options.isProd() ? { entrypoint: './plugins/resize', config: {} } : undefined, service: !options.isProd() ? { entrypoint: './plugins/resize', config: {} } : undefined,
}, },
experimental: { experimental: {
contentLayer: true,
contentIntellisense: true, contentIntellisense: true,
},
env: { env: {
schema: { schema: {
// Postgres Database // Postgres Database
@ -43,7 +43,6 @@ export default defineConfig({
}, },
validateSecrets: true, validateSecrets: true,
}, },
},
integrations: [ integrations: [
mdx({ mdx({
remarkPlugins: [astroImage], remarkPlugins: [astroImage],
@ -68,7 +67,9 @@ export default defineConfig({
}), }),
openGraph(), openGraph(),
], ],
adapter: zeabur(), adapter: node({
mode: 'standalone',
}),
markdown: { markdown: {
gfm: true, gfm: true,
shikiConfig: { shikiConfig: {

2447
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -42,10 +42,10 @@
] ]
}, },
"dependencies": { "dependencies": {
"@astrojs/mdx": "^3.1.9", "@astrojs/mdx": "^4.0.1",
"@astrojs/node": "^9.0.0",
"@astrojs/rss": "^4.0.9", "@astrojs/rss": "^4.0.9",
"@zeabur/astro-adapter": "^1.0.6", "astro": "^5.0.1",
"astro": "^4.16.16",
"drizzle-orm": "^0.36.4", "drizzle-orm": "^0.36.4",
"fuse.js": "^7.0.0", "fuse.js": "^7.0.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",

View File

@ -1,6 +1,7 @@
import { imageMetadata } from '@/helpers/images'; import { imageMetadata } from '@/helpers/images';
import { urlJoin } from '@/helpers/tools'; import { urlJoin } from '@/helpers/tools';
import options from '@/options'; import options from '@/options';
import { glob } from 'astro/loaders';
import { defineCollection, z } from 'astro:content'; import { defineCollection, z } from 'astro:content';
export const defaultCover = '/images/default-cover.jpg'; export const defaultCover = '/images/default-cover.jpg';
@ -48,7 +49,7 @@ const toc = () =>
// Categories Collection // Categories Collection
const categoriesCollection = defineCollection({ const categoriesCollection = defineCollection({
type: 'data', loader: glob({ pattern: '**\/[^_]*.yml', base: './src/content/categories' }),
schema: z.object({ schema: z.object({
name: z.string().max(20), name: z.string().max(20),
slug: slug(), slug: slug(),
@ -59,7 +60,7 @@ const categoriesCollection = defineCollection({
// Friends Collection // Friends Collection
const friendsCollection = defineCollection({ const friendsCollection = defineCollection({
type: 'data', loader: glob({ pattern: '**\/[^_]*.yml', base: './src/content/friends' }),
schema: z.array( schema: z.array(
z z
.object({ .object({
@ -82,7 +83,7 @@ const friendsCollection = defineCollection({
// Posts Collection // Posts Collection
const postsCollection = defineCollection({ const postsCollection = defineCollection({
type: 'content', loader: glob({ pattern: '**\/[^_]*.mdx', base: './src/content/posts' }),
schema: z.object({ schema: z.object({
title: z.string().max(99), title: z.string().max(99),
date: z.date(), date: z.date(),
@ -100,7 +101,7 @@ const postsCollection = defineCollection({
// Pages Collection // Pages Collection
const pagesCollection = defineCollection({ const pagesCollection = defineCollection({
type: 'content', loader: glob({ pattern: '**\/[^_]*.mdx', base: './src/content/pages' }),
schema: z.object({ schema: z.object({
title: z.string().max(99), title: z.string().max(99),
date: z.date(), date: z.date(),
@ -116,7 +117,7 @@ const pagesCollection = defineCollection({
// Tags Collection // Tags Collection
const tagsCollection = defineCollection({ const tagsCollection = defineCollection({
type: 'data', loader: glob({ pattern: '**\/[^_]*.yml', base: './src/content/tags' }),
schema: z.array( schema: z.array(
z.object({ z.object({
name: z.string().max(20), name: z.string().max(20),

View File

@ -1,5 +1,5 @@
import serverRenderer from '@astrojs/mdx/server.js';
import { experimental_AstroContainer as AstroContainer, type ContainerRenderOptions } from 'astro/container'; import { experimental_AstroContainer as AstroContainer, type ContainerRenderOptions } from 'astro/container';
import serverRenderer from 'astro/jsx/server.js';
import type { AstroComponentFactory } from 'astro/runtime/server/index.js'; import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
const container = await AstroContainer.create(); const container = await AstroContainer.create();

View File

@ -1,5 +1,6 @@
import fs from 'node:fs/promises'; import fs from 'node:fs/promises';
import { join } from 'node:path'; import { join } from 'node:path';
import sharp from 'sharp';
import options from '../../options'; import options from '../../options';
import { urlJoin } from './tools'; import { urlJoin } from './tools';
@ -54,8 +55,6 @@ export const blurStyle = (image: Image) => ({
// Copied and modified https://github.com/zce/velite/blob/main/src/assets.ts // Copied and modified https://github.com/zce/velite/blob/main/src/assets.ts
export const imageMetadata = async (publicPath: string): Promise<Image> => { export const imageMetadata = async (publicPath: string): Promise<Image> => {
const { default: sharp } = await import('sharp');
if (!publicPath.startsWith('/')) { if (!publicPath.startsWith('/')) {
throw new Error('We only support image path in "public/images" directory. The path should start with "/images/".'); throw new Error('We only support image path in "public/images" directory. The path should start with "/images/".');
} }

View File

@ -1,6 +1,6 @@
import { defaultCover } from '@/content/config.ts'; import { defaultCover } from '@/content.config';
import options from '@/options'; import options from '@/options';
import { getCollection, getEntry, type Render } from 'astro:content'; import { getCollection, getEntry, render, type RenderResult } from 'astro:content';
import { pinyin } from 'pinyin-pro'; import { pinyin } from 'pinyin-pro';
// Import the collections from the astro content. // Import the collections from the astro content.
@ -19,35 +19,36 @@ export type Friend = (typeof friendsCollection)[number]['data'][number];
export type Page = (typeof pagesCollection)[number]['data'] & { export type Page = (typeof pagesCollection)[number]['data'] & {
slug: string; slug: string;
permalink: string; permalink: string;
render: () => Render['.mdx']; render: () => Promise<RenderResult>;
}; };
export type Post = (typeof postsCollection)[number]['data'] & { export type Post = (typeof postsCollection)[number]['data'] & {
slug: string; slug: string;
permalink: string; permalink: string;
render: () => Render['.mdx']; render: () => Promise<RenderResult>;
raw: () => Promise<string>; raw: () => Promise<string | undefined>;
}; };
export type Tag = (typeof tagsCollection)[number]['data'][number] & { counts: number; permalink: string }; export type Tag = (typeof tagsCollection)[number]['data'][number] & { counts: number; permalink: string };
// Translate the Astro content into the original content for dealing with different configuration types. // Translate the Astro content into the original content for dealing with different configuration types.
export const friends: Friend[] = friendsCollection[0].data; export const friends: Friend[] = friendsCollection.flatMap((friends) => friends.data);
// Override the website for local debugging // Override the website for local debugging
export const pages: Page[] = pagesCollection export const pages: Page[] = pagesCollection
.filter((page) => page.data.published || !options.isProd()) .filter((page) => page.data.published || !options.isProd())
.map((page) => ({ .map((page) => ({
slug: page.slug, slug: page.id,
permalink: `/${page.slug}`, permalink: `/${page.id}`,
render: page.render, render: async () => await render(await getEntry('pages', page.id)),
...page.data, ...page.data,
})); }));
export const posts: Post[] = postsCollection export const posts: Post[] = postsCollection
.filter((post) => post.data.published || !options.isProd()) .filter((post) => post.data.published || !options.isProd())
.map((post) => ({ .map((post) => ({
slug: post.slug, slug: post.id,
permalink: `/posts/${post.slug}`, permalink: `/posts/${post.id}`,
render: post.render, render: async () => await render(await getEntry('posts', post.id)),
raw: async () => { raw: async () => {
const entry = await getEntry('posts', post.slug); const entry = await getEntry('posts', post.id);
return entry.body; return entry.body;
}, },
...post.data, ...post.data,

View File

@ -4,7 +4,7 @@ import Fuse from 'fuse.js';
interface PostItem { interface PostItem {
title: string; title: string;
slug: string; slug: string;
raw: string; raw: string | undefined;
tags: string[]; tags: string[];
} }

View File

@ -1,6 +1,8 @@
{ {
"$schema": "https://json.schemastore.org/tsconfig.json", "$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "astro/tsconfigs/strict", "extends": "astro/tsconfigs/strict",
"include": [".astro/types.d.ts", "**/*"],
"exclude": ["dist"],
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"strict": true, "strict": true,