From 009b31f9229334b9e036a4fff3490e50c37fd23e Mon Sep 17 00:00:00 2001 From: DanielXing1103 <112993709+DanielXing1103@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:56:00 -0700 Subject: [PATCH] docs: add "Modifying the Head Element" example (#1226) resolves #1215 by adding example on modifying ``` ``` on index.md --------- Co-authored-by: Asher Gomez --- docs/examples/index.md | 2 ++ docs/examples/modifying-the-head-element.md | 39 +++++++++++++++++++++ docs/toc.json | 6 ++++ 3 files changed, 47 insertions(+) create mode 100644 docs/examples/modifying-the-head-element.md diff --git a/docs/examples/index.md b/docs/examples/index.md index cc01568a..1bf1978e 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -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 like to see here, please open [a GitHub discussion](https://github.com/denoland/fresh/discussions/new?category=ideas). + +- [Modifying the `` Element](modifying-the-head-element) diff --git a/docs/examples/modifying-the-head-element.md b/docs/examples/modifying-the-head-element.md new file mode 100644 index 00000000..5700bd46 --- /dev/null +++ b/docs/examples/modifying-the-head-element.md @@ -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 `` component in `$fresh/runtime.ts` to modify the +`` element. By adding inner components to ``, we add inner +components to the `` element of the web page. Some uses include: + +- Setting the document title using `` +- 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 + + + + +
+

Hello World

+
+ + ); +} +``` diff --git a/docs/toc.json b/docs/toc.json index 5ec37a83..fea1bf9c 100644 --- a/docs/toc.json +++ b/docs/toc.json @@ -36,5 +36,11 @@ }, "integrations": { "title": "Integrations" + }, + "examples": { + "title": "Examples", + "pages": [ + ["modifying-the-head-element", "Modifying the Head Element"] + ] } }