Merge pull request #92 from prototypa/astro2

Minimal changes for migration to Astro v2
This commit is contained in:
prototypa
2023-01-21 18:21:19 -05:00
committed by GitHub
10 changed files with 28 additions and 44 deletions

View File

@ -1,15 +0,0 @@
# https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = false
[{.*,*.md,*.json,*.toml,*.yml,}]
indent_style = space

2
.gitignore vendored
View File

@ -22,4 +22,4 @@ pnpm-debug.log*
package-lock.json package-lock.json
pnpm-lock.yaml pnpm-lock.yaml
src/content/types.generated.d.ts .astro

View File

@ -58,7 +58,6 @@ export default defineConfig({
markdown: { markdown: {
remarkPlugins: [remarkReadingTime], remarkPlugins: [remarkReadingTime],
extendDefaultPlugins: true,
}, },
vite: { vite: {
@ -68,8 +67,4 @@ export default defineConfig({
}, },
}, },
}, },
experimental: {
contentCollections: true,
},
}); });

View File

@ -1,7 +1,7 @@
{ {
"name": "@onwidget/astrowind", "name": "@onwidget/astrowind",
"description": "A template to make your website using Astro + Tailwind CSS.", "description": "A template to make your website using Astro + Tailwind CSS.",
"version": "0.9.7", "version": "0.9.8",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "astro dev", "dev": "astro dev",
@ -14,23 +14,23 @@
"subfont": "subfont -ir --no-fallbacks --silent --root dist" "subfont": "subfont -ir --no-fallbacks --silent --root dist"
}, },
"devDependencies": { "devDependencies": {
"@astrojs/image": "^0.12.1", "@astrojs/image": "^1.0.0-beta.2",
"@astrojs/mdx": "^0.14.0", "@astrojs/mdx": "^1.0.0-beta.2",
"@astrojs/partytown": "^1.0.2", "@astrojs/partytown": "^1.0.3-beta.0",
"@astrojs/rss": "^2.0.0", "@astrojs/rss": "^2.0.0",
"@astrojs/sitemap": "^1.0.0", "@astrojs/sitemap": "^1.0.0",
"@astrojs/tailwind": "^2.1.3", "@astrojs/tailwind": "^3.0.0-beta.1",
"@astrolib/analytics": "^0.3.0", "@astrolib/analytics": "^0.3.0",
"@astrolib/seo": "^0.3.0", "@astrolib/seo": "^0.3.0",
"@fontsource/inter": "^4.5.15", "@fontsource/inter": "^4.5.15",
"@tailwindcss/typography": "^0.5.9", "@tailwindcss/typography": "^0.5.9",
"@typescript-eslint/eslint-plugin": "^5.48.2", "@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2", "@typescript-eslint/parser": "^5.48.2",
"astro": "^1.9.2", "astro": "^2.0.0-beta.3",
"astro-compress": "1.1.27", "astro-compress": "1.1.28",
"astro-icon": "^0.8.0", "astro-icon": "^0.8.0",
"eslint": "^8.32.0", "eslint": "^8.32.0",
"eslint-plugin-astro": "^0.22.0", "eslint-plugin-astro": "^0.23.0",
"eslint-plugin-jsx-a11y": "^6.7.1", "eslint-plugin-jsx-a11y": "^6.7.1",
"limax": "^2.1.0", "limax": "^2.1.0",
"mdast-util-to-string": "^3.1.0", "mdast-util-to-string": "^3.1.0",

View File

@ -1,2 +1,2 @@
/assets/* /_astro/*
Cache-Control: public, max-age=31536000, immutable Cache-Control: public, max-age=31536000, immutable

View File

@ -1,7 +1,7 @@
import { z, defineCollection } from 'astro:content'; import { z, defineCollection } from 'astro:content';
const blog = defineCollection({ const blog = defineCollection({
schema: { schema: z.object({
title: z.string(), title: z.string(),
description: z.string().optional(), description: z.string().optional(),
image: z.string().optional(), image: z.string().optional(),
@ -16,7 +16,7 @@ const blog = defineCollection({
category: z.string().optional(), category: z.string().optional(),
tags: z.array(z.string()).optional(), tags: z.array(z.string()).optional(),
author: z.string().optional(), author: z.string().optional(),
}, }),
slug: ({ defaultSlug, data }) => { slug: ({ defaultSlug, data }) => {
return data.permalink || defaultSlug; return data.permalink || defaultSlug;
}, },

1
src/env.d.ts vendored
View File

@ -1 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="@astrojs/image/client" /> /// <reference types="@astrojs/image/client" />

View File

@ -1,11 +1,11 @@
import { getCollection, getEntry } from 'astro:content'; import { getCollection } from 'astro:content';
import type { CollectionEntry } from 'astro:content'; import type { CollectionEntry } from 'astro:content';
import type { Post } from '~/types'; import type { Post } from '~/types';
import { cleanSlug } from './permalinks'; import { cleanSlug } from './permalinks';
const getNormalizedPost = async (post: CollectionEntry<'blog'>): Promise<Post> => { const getNormalizedPost = async (post: CollectionEntry<'blog'>): Promise<Post> => {
const { id, slug = '', data } = post; const { id, slug = '', data } = post;
const { Content, injectedFrontmatter } = await post.render(); const { Content, remarkPluginFrontmatter } = await post.render();
const { tags = [], category = 'default', author = 'Anonymous', publishDate = new Date(), ...rest } = data; const { tags = [], category = 'default', author = 'Anonymous', publishDate = new Date(), ...rest } = data;
@ -23,7 +23,7 @@ const getNormalizedPost = async (post: CollectionEntry<'blog'>): Promise<Post> =
Content: Content, Content: Content,
// or 'body' in case you consume from API // or 'body' in case you consume from API
readingTime: injectedFrontmatter.readingTime, readingTime: remarkPluginFrontmatter?.readingTime,
}; };
}; };
@ -67,12 +67,14 @@ export const findPostsBySlugs = async (slugs: Array<string>): Promise<Array<Post
export const findPostsByIds = async (ids: Array<string>): Promise<Array<Post>> => { export const findPostsByIds = async (ids: Array<string>): Promise<Array<Post>> => {
if (!Array.isArray(ids)) return []; if (!Array.isArray(ids)) return [];
return await Promise.all( const posts = await fetchPosts();
ids.map(async (id: never) => {
const post = await getEntry('blog', id); return ids.reduce(function (r: Array<Post>, id: string) {
return await getNormalizedPost(post); posts.some(function (post: Post) {
}) return id === post.id && r.push(post);
); });
return r;
}, []);
}; };
/** */ /** */

View File

@ -2,10 +2,11 @@ import getReadingTime from 'reading-time';
import { toString } from 'mdast-util-to-string'; import { toString } from 'mdast-util-to-string';
export function remarkReadingTime() { export function remarkReadingTime() {
return function (tree, { data }) { return function (tree, file) {
const text = toString(tree); const text = toString(tree);
const readingTime = Math.ceil(getReadingTime(text).minutes); const readingTime = Math.ceil(getReadingTime(text).minutes);
data.astro.frontmatter.readingTime = readingTime; const { frontmatter } = file.data.astro;
frontmatter.readingTime = readingTime;
}; };
} }

View File

@ -3,7 +3,7 @@
"trailingSlash": false, "trailingSlash": false,
"headers": [ "headers": [
{ {
"source": "/assets/(.*)", "source": "/_astro/(.*)",
"headers": [ "headers": [
{ {
"key": "Cache-Control", "key": "Cache-Control",