Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
liruifengv authored Aug 2, 2024
2 parents 7d89b6f + 1072521 commit 9b29a63
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/content/docs/en/guides/content-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ Alternatively, you can set this value in your editor settings. For example, to s
```json
{
"json.schemas": [
{
"fileMatch": [
"/src/content/authors/**"
],
"url": "./.astro/collections/authors.schema.json"
}
{
"fileMatch": [
"/src/content/authors/**"
],
"url": "./.astro/collections/authors.schema.json"
}
]
}
```
Expand Down
24 changes: 8 additions & 16 deletions src/content/docs/en/guides/imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ The following file types are supported out-of-the-box by Astro:
- Astro Components (`.astro`)
- Markdown (`.md`, `.markdown`, etc.)
- JavaScript (`.js`, `.mjs`)
- TypeScript (`.ts`, `.tsx`)
- TypeScript (`.ts`)
- NPM Packages
- JSON (`.json`)
- JSX (`.jsx`, `.tsx`)
- CSS (`.css`)
- CSS Modules (`.module.css`)
- Images & Assets (`.svg`, `.jpg`, `.png`, etc.)
Expand All @@ -41,6 +40,13 @@ import { getUser } from './user.js';

JavaScript can be imported using normal ESM `import` & `export` syntax.

:::note[Importing JSX files]

An appropriate [UI framework](/en/guides/framework-components/) ([React](/en/guides/integrations-guide/react/), [Preact](/en/guides/integrations-guide/preact/), or [Solid](/en/guides/integrations-guide/solid-js/)) is required to render JSX/TSX files.
Use `.jsx`/`.tsx` extensions where appropriate, as Astro does not support JSX in `.js`/`.ts` files.

:::

### TypeScript

```js
Expand All @@ -65,20 +71,6 @@ import MyComponent from "./MyComponent"; // MyComponent.tsx
<ReadMore>Read more about [TypeScript support in Astro](/en/guides/typescript/).</ReadMore>


### JSX / TSX

```js
import { MyComponent } from './MyComponent.jsx';
```

Astro includes built-in support for JSX (`*.jsx` and `*.tsx`) files in your project. JSX syntax is automatically transpiled to JavaScript.

While Astro understands JSX syntax out-of-the-box, you will need to include a framework integration to properly render frameworks like React, Preact and Solid. Check out our [Using Integrations](/en/guides/integrations-guide/) guide to learn more.

:::note
**Astro does not support JSX in `.js`/`.ts` files.** JSX will only be handled inside of files that end with the `.jsx` and `.tsx` file extensions.
:::

### NPM Packages

If you've installed an NPM package, you can import it in Astro.
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/en/guides/middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Use `context.rewrite()` inside middleware to display a different page's content
```js title="src/middleware.js"
import { isLoggedIn } from "~/auth.js"
export function onRequest (context, next) {
if (!isLoggedIn(context) {
if (!isLoggedIn(context)) {
// If the user is not logged in, update the Request to render the `/login` route and
// add header to indicate where the user should be sent after a successful login.
// Re-execute middleware.
Expand All @@ -228,7 +228,7 @@ You can also pass the `next()` function an optional URL path parameter to rewrit
```js title="src/middleware.js"
import { isLoggedIn } from "~/auth.js"
export function onRequest (context, next) {
if (!isLoggedIn(context) {
if (!isLoggedIn(context)) {
// If the user is not logged in, update the Request to render the `/login` route and
// add header to indicate where the user should be sent after a successful login.
// Return a new `context` to any following middlewares.
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/en/guides/routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ A rewrite allows you serve a different route without redirecting the browser to
For content that has permanently moved, or to direct your user to a different page with a new URL (e.g. a user dashboard after logging in), use a [redirect](#redirects) instead.
:::

Rewrites can be useful for showing the same content at multiple paths (e.g. `/products/shoes/men/` and `/products/men/shoes`/) without needing to maintain two different source files.
Rewrites can be useful for showing the same content at multiple paths (e.g. `/products/shoes/men/` and `/products/men/shoes/`) without needing to maintain two different source files.

Rewrites are also useful for SEO purposes and user experience. They allow you to display content that otherwise would require redirecting your visitor to a different page or would return a 404 status. One common use of rewrites is to show the same localized content for different variants of a language.

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/fr/basics/astro-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const myFavoritePokemon = [/* ... */];
const { title } = Astro.props;
---
<!-- les commentaires HTML sont supportés ! -->
{/* La syntaxe des commentaires JavaScipt est aussi valide ! */}
{/* La syntaxe des commentaires JavaScript est aussi valide ! */}
<Banner />
<h1>Hello, world!</h1>
Expand Down

0 comments on commit 9b29a63

Please sign in to comment.