docs: add "Modifying the Head Element" example (#1226)
resolves #1215 by adding example on modifying ``` <Head />``` on index.md --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
co-authored by
Asher Gomez
parent
02dec2f483
commit
009b31f922
@@ -7,3 +7,5 @@ In this chapter of the Fresh documentation, you can find examples of features
|
|||||||
that you may like in your Fresh project. If there's a specific example you'd
|
that you may like in your Fresh project. If there's a specific example you'd
|
||||||
like to see here, please open
|
like to see here, please open
|
||||||
[a GitHub discussion](https://github.com/denoland/fresh/discussions/new?category=ideas).
|
[a GitHub discussion](https://github.com/denoland/fresh/discussions/new?category=ideas).
|
||||||
|
|
||||||
|
- [Modifying the `<head>` Element](modifying-the-head-element)
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
description: |
|
||||||
|
By adding inner components to Fresh's head element, we add inner components to the HTML head element of the web page.
|
||||||
|
---
|
||||||
|
|
||||||
|
We can use the `<Head />` component in `$fresh/runtime.ts` to modify the
|
||||||
|
`<head>` element. By adding inner components to `<Head />`, we add inner
|
||||||
|
components to the `<head>` element of the web page. Some uses include:
|
||||||
|
|
||||||
|
- Setting the document title using `<title>`
|
||||||
|
- Specifying page metadata using `<meta>`
|
||||||
|
- Linking to external resources using `<link>`
|
||||||
|
- Including JavaScript code using `<script>`
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// routes/index.tsx
|
||||||
|
import { Head } from "$fresh/runtime.ts";
|
||||||
|
import Counter from "../islands/Counter.tsx";
|
||||||
|
|
||||||
|
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>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -36,5 +36,11 @@
|
|||||||
},
|
},
|
||||||
"integrations": {
|
"integrations": {
|
||||||
"title": "Integrations"
|
"title": "Integrations"
|
||||||
|
},
|
||||||
|
"examples": {
|
||||||
|
"title": "Examples",
|
||||||
|
"pages": [
|
||||||
|
["modifying-the-head-element", "Modifying the Head Element"]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user