Skip to content

Commit

Permalink
Merge branch 'main' into markdown-perf
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Sep 14, 2023
2 parents 062cbee + 61ac5c9 commit 93f7b53
Show file tree
Hide file tree
Showing 285 changed files with 1,305 additions and 1,946 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-flies-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': major
---

Adds a configuration option `devImageService` to choose which of the built-in image services to use in development. Defaults to `sharp`.
48 changes: 48 additions & 0 deletions .changeset/cyan-penguins-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
'@astrojs/mdx': minor
---

Support the `img` component export for optimized images. This allows you to customize how optimized images are styled and rendered.

When rendering an optimized image, Astro will pass the `ImageMetadata` object to your `img` component as the `src` prop. For unoptimized images (i.e. images using URLs or absolute paths), Astro will continue to pass the `src` as a string.

This example handles both cases and applies custom styling:

```astro
---
// src/components/MyImage.astro
import type { ImageMetadata } from 'astro';
import { Image } from 'astro:assets';
type Props = {
src: string | ImageMetadata;
alt: string;
};
const { src, alt } = Astro.props;
---
{
typeof src === 'string' ? (
<img class="custom-styles" src={src} alt={alt} />
) : (
<Image class="custom-styles" {src} {alt} />
)
}
<style>
.custom-styles {
border: 1px solid red;
}
</style>
```

Now, this components can be applied to the `img` component props object or file export:

```md
import MyImage from '../../components/MyImage.astro';

export const components = { img: MyImage };

# My MDX article
```
5 changes: 5 additions & 0 deletions .changeset/dirty-seahorses-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': minor
---

Add a new `image.endpoint` setting to allow using a custom endpoint in dev and SSR
5 changes: 5 additions & 0 deletions .changeset/five-doors-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': minor
---

Adds support for using AVIF (`.avif`) files with the Image component. Importing an AVIF file will now correctly return the same object shape as other image file types. See the [Image docs](https://docs.astro.build/en/guides/images/#update-existing-img-tags) for more information on the different properties available on the returned object.
5 changes: 5 additions & 0 deletions .changeset/grumpy-seas-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': minor
---

feat(markdown): Add support for `imageReference` paths when collecting images
5 changes: 5 additions & 0 deletions .changeset/long-trees-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': minor
---

Add types for the object syntax for `style` (ex: `style={{color: 'red'}}`)
5 changes: 5 additions & 0 deletions .changeset/sixty-beds-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

bugfix checking media-type in client-side router
5 changes: 5 additions & 0 deletions .changeset/slow-mirrors-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improved error messages around `astro:assets`
5 changes: 5 additions & 0 deletions .changeset/small-apes-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Add `CollectionKey`, `ContentCollectionKey`, and `DataCollectionKey` exports to `astro:content`
5 changes: 5 additions & 0 deletions .changeset/ten-kings-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': minor
---

Improve startup performance by removing dependencies, lazily initializing async contextual values
5 changes: 1 addition & 4 deletions benchmark/packages/timer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"extends": "../../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"allowJs": true,
"module": "ES2022",
"outDir": "./dist",
"target": "ES2022"
"outDir": "./dist"
}
}
3 changes: 0 additions & 3 deletions packages/astro-prism/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"allowJs": true,
"target": "ES2022",
"module": "ES2022",
"outDir": "./dist"
}
}
2 changes: 1 addition & 1 deletion packages/astro-rss/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { z } from 'astro/zod';
import type { RSSOptions } from './index';
import type { RSSOptions } from './index.js';

/** Normalize URL to its canonical form */
export function createCanonicalURL(
Expand Down
6 changes: 1 addition & 5 deletions packages/astro-rss/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"allowJs": true,
"module": "ES2022",
"outDir": "./dist",
"target": "ES2022",
"strictNullChecks": true
"outDir": "./dist"
}
}
4 changes: 2 additions & 2 deletions packages/astro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Having trouble? Get help in the official [Astro Discord](https://astro.build/cha

**New contributors welcome!** Check out our [Contributors Guide](/CONTRIBUTING.md) for help getting started.

Join us on [Discord](https://astro.build/chat) to meet other maintainers. We'll help you get your first contribution in no time!
Join us on [Discord](https://astro.build/chat) to meet other contributors. We'll help you get your first contribution in no time!

## Sponsors

Astro is generously supported by [Netlify](https://www.netlify.com/), [Vercel](https://vercel.com/), and several other amazing organizations [listed here.](https://astro.build/)
Astro is generously supported by [Vercel](https://vercel.com/), [storyblok](https://storyblok.com/), and several other amazing organizations [listed here.](https://opencollective.com/astrodotbuild)

[❤️ Sponsor Astro! ❤️](https://github.com/withastro/.github/blob/main/FUNDING.md)
29 changes: 28 additions & 1 deletion packages/astro/astro-jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,33 @@ declare namespace astroHTML.JSX {
| 'treegrid'
| 'treeitem';

type CssProperty = keyof Omit<
CSSStyleDeclaration,
| 'item'
| 'setProperty'
| 'removeProperty'
| 'getPropertyValue'
| 'getPropertyPriority'
| 'parentRule'
| 'length'
| 'cssFloat'
| 'cssText'
| typeof Symbol.iterator
| number
>;

type KebabCSSDOMProperties = import('./dist/type-utils.js').KebabKeys<DOMCSSProperties>;

type DOMCSSProperties = {
[key in CssProperty]?: string | number | null | undefined;
};
type AllCSSProperties = {
[key: string]: string | number | null | undefined;
};
type StyleObject = import('./dist/type-utils.js').Simplify<
KebabCSSDOMProperties & DOMCSSProperties & AllCSSProperties
>;

interface HTMLAttributes extends AriaAttributes, DOMAttributes, AstroBuiltinAttributes {
// Standard HTML Attributes
accesskey?: string | undefined | null;
Expand Down Expand Up @@ -513,7 +540,7 @@ declare namespace astroHTML.JSX {
lang?: string | undefined | null;
slot?: string | undefined | null;
spellcheck?: 'true' | 'false' | boolean | undefined | null;
style?: string | Record<string, any> | undefined | null;
style?: string | StyleObject | undefined | null;
tabindex?: number | string | undefined | null;
title?: string | undefined | null;
translate?: 'yes' | 'no' | undefined | null;
Expand Down
12 changes: 8 additions & 4 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ declare module 'astro:assets' {
| import('./dist/assets/types.js').ImageTransform
| import('./dist/assets/types.js').UnresolvedImageTransform
) => Promise<import('./dist/assets/types.js').GetImageResult>;
imageConfig: import('./dist/@types/astro').AstroConfig['image'];
imageConfig: import('./dist/@types/astro.js').AstroConfig['image'];
getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService;
Image: typeof import('./components/Image.astro').default;
};
Expand Down Expand Up @@ -108,6 +108,10 @@ declare module '*.svg' {
const metadata: ImageMetadata;
export default metadata;
}
declare module '*.avif' {
const metadata: ImageMetadata;
export default metadata;
}

declare module 'astro:transitions' {
type TransitionModule = typeof import('./dist/transitions/index.js');
Expand All @@ -126,7 +130,7 @@ declare module 'astro:components' {
export * from 'astro/components';
}

type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
type MD = import('./dist/@types/astro.js').MarkdownInstance<Record<string, any>>;
interface ExportedMarkdownModuleEntities {
frontmatter: MD['frontmatter'];
file: MD['file'];
Expand Down Expand Up @@ -231,7 +235,7 @@ declare module '*.mdown' {
}

declare module '*.mdx' {
type MDX = import('./dist/@types/astro').MDXInstance<Record<string, any>>;
type MDX = import('./dist/@types/astro.js').MDXInstance<Record<string, any>>;

export const frontmatter: MDX['frontmatter'];
export const file: MDX['file'];
Expand All @@ -244,7 +248,7 @@ declare module '*.mdx' {
}

declare module 'astro:ssr-manifest' {
export const manifest: import('./dist/@types/astro').SSRManifest;
export const manifest: import('./dist/@types/astro.js').SSRManifest;
}

// Everything below are Vite's types (apart from image types, which are in `client.d.ts`)
Expand Down
30 changes: 15 additions & 15 deletions packages/astro/components/ViewTransitions.astro
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ const { fallback = 'animate' } = Astro.props as Props;
};

async function getHTML(href: string) {
let res;
try {
res = await fetch(href);
const res = await fetch(href);
const html = await res.text();
return {
ok: res.ok,
html,
redirected: res.redirected ? res.url : undefined,
// drop potential charset (+ other name/value pairs) as parser needs the mediaType
mediaType: res.headers.get('content-type')?.replace(/;.*$/, ''),
};
} catch (err) {
return { ok: false };
}
const html = await res.text();
return {
ok: res.ok,
html,
redirected: res.redirected ? res.url : undefined,
contentType: res.headers.get('content-type'),
};
}

function getFallback(): Fallback {
Expand Down Expand Up @@ -126,13 +126,13 @@ const { fallback = 'animate' } = Astro.props as Props;

// A noop element used to prevent styles from being removed
if (import.meta.env.DEV) {
var noopEl: string | undefined = document.createElement('div');
var noopEl = document.createElement('div');
}

async function updateDOM(doc: Document, loc: URL, state?: State, fallback?: Fallback) {
// Check for a head element that should persist, either because it has the data
// attribute or is a link el.
const persistedHeadElement = (el: Element): Element | null => {
const persistedHeadElement = (el: HTMLElement): Element | null => {
const id = el.getAttribute(PERSIST_ATTR);
const newEl = id && doc.head.querySelector(`[${PERSIST_ATTR}="${id}"]`);
if (newEl) {
Expand Down Expand Up @@ -189,7 +189,7 @@ const { fallback = 'animate' } = Astro.props as Props;

// Swap head
for (const el of Array.from(document.head.children)) {
const newEl = persistedHeadElement(el);
const newEl = persistedHeadElement(el as HTMLElement);
// If the element exists in the document already, remove it
// from the new document and leave the current node alone
if (newEl) {
Expand Down Expand Up @@ -290,16 +290,16 @@ const { fallback = 'animate' } = Astro.props as Props;
async function navigate(dir: Direction, loc: URL, state?: State) {
let finished: Promise<void>;
const href = loc.href;
const { html, ok, contentType, redirected } = await getHTML(href);
const { html, ok, mediaType, redirected } = await getHTML(href);
// if there was a redirection, show the final URL in the browser's address bar
redirected && (loc = new URL(redirected));
// If there is a problem fetching the new page, just do an MPA navigation to it.
if (!ok || contentType !== 'text/html') {
if (!ok || !(mediaType === 'text/html' || mediaType === 'application/xhtml+xml')) {
location.href = href;
return;
}

const doc = parser.parseFromString(html, contentType);
const doc = parser.parseFromString(html, mediaType);
if (!doc.querySelector('[name="astro-view-transitions-enabled"]')) {
location.href = href;
return;
Expand Down
7 changes: 6 additions & 1 deletion packages/astro/content-types.template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ declare module 'astro:content' {
export { z } from 'astro/zod';

type Flatten<T> = T extends { [K: string]: infer U } ? U : never;
export type CollectionEntry<C extends keyof AnyEntryMap> = Flatten<AnyEntryMap[C]>;

export type CollectionKey = keyof AnyEntryMap;
export type CollectionEntry<C extends CollectionKey> = Flatten<AnyEntryMap[C]>;

export type ContentCollectionKey = keyof ContentEntryMap;
export type DataCollectionKey = keyof DataEntryMap;

// This needs to be in sync with ImageMetadata
export type ImageFunction = () => import('astro/zod').ZodObject<{
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"p-limit": "^4.0.0",
"path-to-regexp": "^6.2.1",
"preferred-pm": "^3.1.2",
"probe-image-size": "^7.2.3",
"prompts": "^2.4.2",
"rehype": "^12.0.1",
"resolve": "^1.22.4",
Expand Down Expand Up @@ -197,6 +198,7 @@
"@types/js-yaml": "^4.0.5",
"@types/mime": "^3.0.1",
"@types/mocha": "^10.0.1",
"@types/probe-image-size": "^7.2.0",
"@types/prompts": "^2.4.4",
"@types/resolve": "^1.20.2",
"@types/send": "^0.17.1",
Expand Down
Loading

0 comments on commit 93f7b53

Please sign in to comment.