Skip to content

Commit 09e827c

Browse files
committed
Migrate to astro v2
1 parent b575a89 commit 09e827c

File tree

9 files changed

+28
-29
lines changed

9 files changed

+28
-29
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ pnpm-debug.log*
2222
package-lock.json
2323
pnpm-lock.yaml
2424

25-
src/content/types.generated.d.ts
25+
.astro

astro.config.mjs

-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export default defineConfig({
5858

5959
markdown: {
6060
remarkPlugins: [remarkReadingTime],
61-
extendDefaultPlugins: true,
6261
},
6362

6463
vite: {
@@ -68,8 +67,4 @@ export default defineConfig({
6867
},
6968
},
7069
},
71-
72-
experimental: {
73-
contentCollections: true,
74-
},
7570
});

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@onwidget/astrowind",
33
"description": "A template to make your website using Astro + Tailwind CSS.",
4-
"version": "0.9.7",
4+
"version": "0.9.8",
55
"private": true,
66
"scripts": {
77
"dev": "astro dev",
@@ -14,23 +14,23 @@
1414
"subfont": "subfont -ir --no-fallbacks --silent --root dist"
1515
},
1616
"devDependencies": {
17-
"@astrojs/image": "^0.12.1",
18-
"@astrojs/mdx": "^0.14.0",
19-
"@astrojs/partytown": "^1.0.2",
17+
"@astrojs/image": "^1.0.0-beta.2",
18+
"@astrojs/mdx": "^1.0.0-beta.2",
19+
"@astrojs/partytown": "^1.0.3-beta.0",
2020
"@astrojs/rss": "^2.0.0",
2121
"@astrojs/sitemap": "^1.0.0",
22-
"@astrojs/tailwind": "^2.1.3",
22+
"@astrojs/tailwind": "^3.0.0-beta.1",
2323
"@astrolib/analytics": "^0.3.0",
2424
"@astrolib/seo": "^0.3.0",
2525
"@fontsource/inter": "^4.5.15",
2626
"@tailwindcss/typography": "^0.5.9",
2727
"@typescript-eslint/eslint-plugin": "^5.48.2",
2828
"@typescript-eslint/parser": "^5.48.2",
29-
"astro": "^1.9.2",
30-
"astro-compress": "1.1.27",
29+
"astro": "^2.0.0-beta.3",
30+
"astro-compress": "1.1.28",
3131
"astro-icon": "^0.8.0",
3232
"eslint": "^8.32.0",
33-
"eslint-plugin-astro": "^0.22.0",
33+
"eslint-plugin-astro": "^0.23.0",
3434
"eslint-plugin-jsx-a11y": "^6.7.1",
3535
"limax": "^2.1.0",
3636
"mdast-util-to-string": "^3.1.0",

public/_headers

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/assets/*
1+
/_astro/*
22
Cache-Control: public, max-age=31536000, immutable

src/content/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z, defineCollection } from 'astro:content';
22

33
const blog = defineCollection({
4-
schema: {
4+
schema: z.object({
55
title: z.string(),
66
description: z.string().optional(),
77
image: z.string().optional(),
@@ -16,7 +16,7 @@ const blog = defineCollection({
1616
category: z.string().optional(),
1717
tags: z.array(z.string()).optional(),
1818
author: z.string().optional(),
19-
},
19+
}),
2020
slug: ({ defaultSlug, data }) => {
2121
return data.permalink || defaultSlug;
2222
},

src/env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/// <reference path="../.astro/types.d.ts" />
12
/// <reference types="@astrojs/image/client" />

src/utils/blog.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { getCollection, getEntry } from 'astro:content';
1+
import { getCollection } from 'astro:content';
22
import type { CollectionEntry } from 'astro:content';
33
import type { Post } from '~/types';
44
import { cleanSlug } from './permalinks';
55

66
const getNormalizedPost = async (post: CollectionEntry<'blog'>): Promise<Post> => {
77
const { id, slug = '', data } = post;
8-
const { Content, injectedFrontmatter } = await post.render();
8+
const { Content, remarkPluginFrontmatter } = await post.render();
99

1010
const { tags = [], category = 'default', author = 'Anonymous', publishDate = new Date(), ...rest } = data;
1111

@@ -23,7 +23,7 @@ const getNormalizedPost = async (post: CollectionEntry<'blog'>): Promise<Post> =
2323
Content: Content,
2424
// or 'body' in case you consume from API
2525

26-
readingTime: injectedFrontmatter.readingTime,
26+
readingTime: remarkPluginFrontmatter?.readingTime,
2727
};
2828
};
2929

@@ -67,12 +67,14 @@ export const findPostsBySlugs = async (slugs: Array<string>): Promise<Array<Post
6767
export const findPostsByIds = async (ids: Array<string>): Promise<Array<Post>> => {
6868
if (!Array.isArray(ids)) return [];
6969

70-
return await Promise.all(
71-
ids.map(async (id: never) => {
72-
const post = await getEntry('blog', id);
73-
return await getNormalizedPost(post);
74-
})
75-
);
70+
const posts = await fetchPosts();
71+
72+
return ids.reduce(function (r: Array<Post>, id: string) {
73+
posts.some(function (post: Post) {
74+
return id === post.id && r.push(post);
75+
});
76+
return r;
77+
}, []);
7678
};
7779

7880
/** */

src/utils/frontmatter.mjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import getReadingTime from 'reading-time';
22
import { toString } from 'mdast-util-to-string';
33

44
export function remarkReadingTime() {
5-
return function (tree, { data }) {
5+
return function (tree, file) {
66
const text = toString(tree);
77
const readingTime = Math.ceil(getReadingTime(text).minutes);
88

9-
data.astro.frontmatter.readingTime = readingTime;
9+
const { frontmatter } = file.data.astro;
10+
frontmatter.readingTime = readingTime;
1011
};
1112
}

vercel.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"trailingSlash": false,
44
"headers": [
55
{
6-
"source": "/assets/(.*)",
6+
"source": "/_astro/(.*)",
77
"headers": [
88
{
99
"key": "Cache-Control",

0 commit comments

Comments
 (0)