chore: release 1.5.0 (#1899)
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
---
|
||||
description: |
|
||||
Style active links with ease in Fresh
|
||||
---
|
||||
|
||||
When Fresh renders an `<a>`-element, it will automatically add a
|
||||
[data attribute](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes)
|
||||
to the link which can be used for styling purposes. Fresh will add one of the
|
||||
two following attributes:
|
||||
|
||||
- `data-current` - Added to links with an exact path match
|
||||
- `data-ancestor` - Added to links which partially match the current URL
|
||||
|
||||
## Styling with CSS
|
||||
|
||||
`data-*` attributes can be natively styled in CSS via attribute selectors.
|
||||
|
||||
```css
|
||||
/* Give links pointing to the current page a green color */
|
||||
a[data-current] {
|
||||
color: green;
|
||||
}
|
||||
|
||||
/* Color all ancestor links of the current page */
|
||||
a[data-ancestor] {
|
||||
color: peachpuff;
|
||||
}
|
||||
```
|
||||
|
||||
## Tailwind / Twind
|
||||
|
||||
In tailwind or tailwind like styling solutions you can style `data-*`-attributes
|
||||
by prepending the classes with `[data-current]:`
|
||||
|
||||
```tsx
|
||||
function Menu() {
|
||||
return (
|
||||
<a href="/foo" class="[data-current]:text-green-600">
|
||||
link to some page
|
||||
</a>
|
||||
);
|
||||
}
|
||||
```
|
||||
@@ -1,79 +0,0 @@
|
||||
---
|
||||
description: |
|
||||
Add components like <title> or <meta> to a <head> tag using Fresh's <Head> component.
|
||||
---
|
||||
|
||||
We can use the `<Head />` component in `$fresh/runtime.ts` to add elements as
|
||||
children of the `<head>` element. By adding elements as children of Fresh's
|
||||
`<Head />` tag, these automatically get injected into the `<head>` element of
|
||||
the web page. Some uses include:
|
||||
|
||||
- Setting the document title using `<title>`
|
||||
- Specifying page metadata using `<meta>`
|
||||
- Linking to resources like stylesheets using `<link>`
|
||||
- Including third-party JavaScript code using `<script>`
|
||||
|
||||
```tsx routes/index.tsx
|
||||
import { Head } from "$fresh/runtime.ts";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Fresh App</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="This is a brief description of Fresh"
|
||||
/>
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<script src="script.js"></script>
|
||||
</Head>
|
||||
<div class="p-4 mx-auto max-w-screen-md">
|
||||
<h1>Hello World</h1>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Avoiding duplicate tags
|
||||
|
||||
You might end up with duplicate tags, when multiple `<Head />` components are
|
||||
rendered on the same page. This can happen when you render `<Head />` in a route
|
||||
and another `<Head />` in another component for example.
|
||||
|
||||
```tsx
|
||||
// routes/page-a.tsx
|
||||
<Head>
|
||||
<meta name="og:title" content="This is a title" />
|
||||
</Head>
|
||||
|
||||
// components/MyTitle.tsx
|
||||
<Head>
|
||||
<meta name="og:title" content="Other title" />
|
||||
</Head>
|
||||
```
|
||||
|
||||
To ensure that the tag is not duplicated, Fresh supports setting the `key` prop.
|
||||
By giving matching elements the same `key` prop, only the last one will be
|
||||
rendered.
|
||||
|
||||
```diff
|
||||
// routes/page-a.tsx
|
||||
<Head>
|
||||
- <meta name="og:title" content="This is a title" />
|
||||
+ <meta name="og:title" content="This is a title" key="title" />
|
||||
</Head>
|
||||
|
||||
// components/MyTitle.tsx
|
||||
<Head>
|
||||
- <meta name="og:title" content="Other title" />
|
||||
+ <meta name="og:title" content="Other title" key="title" />
|
||||
</Head>
|
||||
```
|
||||
|
||||
The rendered page will only include the `<meta>`-tag with `"Other title"`.
|
||||
|
||||
> [info]: The `<title>`-tag is automatically deduplicated, even without a `key`
|
||||
> prop.
|
||||
Reference in New Issue
Block a user