-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c94149
commit 548bbce
Showing
19 changed files
with
391 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"title": "root", | ||
"pages": ["index.mdx", "getting-started"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
title: Client setup | ||
order: 2 | ||
--- | ||
|
||
You can inject a tag into the `<head />` by rendering one of the head tag components when necessary. | ||
No special requirements are needed on the client side. | ||
|
||
```js | ||
import { MetaProvider, Title, Link, Meta } from "@solidjs/meta"; | ||
|
||
const App = () => ( | ||
<MetaProvider> | ||
<div class="Home"> | ||
<Title>Title of page</Title> | ||
<Link rel="canonical" href="http://solidjs.com/" /> | ||
<Meta name="example" content="whatever" /> | ||
// ... | ||
</div> | ||
</MetaProvider> | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"title": "Getting Started", | ||
"pages": [ | ||
"installation-and-setup.mdx", | ||
"client-setup.mdx", | ||
"server-setup.mdx" | ||
] | ||
} |
64 changes: 64 additions & 0 deletions
64
src/routes/solid-meta/getting-started/installation-and-setup.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: Install and configure | ||
order: 1 | ||
--- | ||
|
||
<Callout title="Prerequisites"> | ||
If using Solid `v1.0`, use version `0.27.x` or greater. | ||
For earlier versions (eg. `v0.x`), you must use `v0.26.x`. | ||
</Callout> | ||
|
||
## Installation | ||
|
||
To get started, install using your preferred package manager. | ||
|
||
<TabsCodeBlocks> | ||
<div id="npm"> | ||
```bash frame="none" | ||
npm i @solidjs/meta | ||
``` | ||
</div> | ||
|
||
<div id="yarn"> | ||
```bash frame="none" | ||
yarn add @solidjs/meta | ||
``` | ||
</div> | ||
|
||
<div id="pnpm"> | ||
```bash frame="none" | ||
pnpm add @solidjs/meta | ||
``` | ||
</div> | ||
</TabsCodeBlocks> | ||
|
||
## Setup | ||
|
||
1. Wrap your application with [`<MetaProvider />`](/solid-meta/reference/meta/metaprovider) | ||
2. To include head tags within your application, render any of the following: | ||
1. [`<Title />`](/solid-meta/reference/meta/title): Adds the `title` of the page. | ||
2. [`<Meta />`](/solid-meta/reference/meta/meta): Adds extra metadata to the page. | ||
3. [`<Style />`](/solid-meta/reference/meta/style): Adds a `style` element to the page. | ||
4. [`<Link />`](/solid-meta/reference/meta/link): Specifies a relationship between the page and an external resource. | ||
5. [`<Base />`](/solid-meta/reference/meta/base): Specifies the base URL for all relative URLs in the document. | ||
- These components can be used multiple times within the application. | ||
3. If using SolidJS on the server with JSX, no additional configuration is required. | ||
|
||
Here is an example of how your code might look after this setup. | ||
```js | ||
import { MetaProvider, Title, Link, Meta } from "@solidjs/meta"; | ||
|
||
const App = () => ( | ||
<MetaProvider> | ||
<div class="Home"> | ||
<Title>Title of page</Title> | ||
<Link rel="canonical" href="http://solidjs.com/" /> | ||
<Meta name="example" content="whatever" /> | ||
</div> | ||
</MetaProvider> | ||
); | ||
``` | ||
On the server, tags are collected, and then on the client, server-generated tags are replaced with those rendered on the client side. | ||
This process is important for maintaining the expected behavior, such as Single Page Applications (SPAs) when pages load that require changes to the head tags. | ||
|
||
However, you can manage asset insertion using `getAssets` from `solid-js/web`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: Server setup | ||
order: 3 | ||
--- | ||
|
||
For server setup, wrap your application with [`MetaProvider`](/solid-meta/reference/meta/metaprovider) on the server. | ||
This component uses a `tags[]` array to pass down your head tags as part of your server-rendered payload. | ||
Once rendered on the server, the component updates this array to include the tags. | ||
|
||
```js | ||
import { renderToString, getAssets } from "solid-js/web"; | ||
import { MetaProvider } from "@solidjs/meta"; | ||
import App from "./App"; | ||
|
||
// ... within the context of a request ... | ||
const app = renderToString(() => ( | ||
<MetaProvider> | ||
<App /> | ||
</MetaProvider> | ||
)); | ||
|
||
res.send(` | ||
<!doctype html> | ||
<html> | ||
<head> | ||
${getAssets()} | ||
</head> | ||
<body> | ||
<div id="root">${app}</div> | ||
</body> | ||
</html> | ||
`); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: Overview | ||
mainNavExclude: true | ||
--- | ||
|
||
# Overview | ||
|
||
Solid Meta offers asynchronous SSR-ready Document Head management for Solid Applications, based on [React Head](https://github.com/tizmagik/react-head) | ||
|
||
With Solid Meta, you can define `document.head` tags at any level of your component hierarchy. | ||
This helps you to manage tags conveniently, especially when contextual information for specific tags are buried deep within your component hierarchy. | ||
|
||
This library has no dependencies and is designed to seamlessly integrate with asynchronous rendering. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"title": "Reference", | ||
"pages": ["meta"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
title: Base | ||
order: 5 | ||
--- | ||
|
||
`Base` is a component that specifies the base URL for all relative URLs in the document. | ||
This provides a way to define the [`base`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base) element of your document's `head`. | ||
|
||
```tsx twoslash | ||
import { Base } from "@solidjs/meta"; | ||
|
||
<Base target="_blank" href="https://docs.solidjs.com/" />; | ||
``` | ||
|
||
## Usage | ||
|
||
### Adding `base` tag | ||
|
||
```tsx twoslash | ||
import { MetaProvider, Base } from "@solidjs/meta"; | ||
|
||
export default function Root() { | ||
return ( | ||
<MetaProvider> | ||
<Base target="_blank" href="https://docs.solidjs.com/" /> | ||
</MetaProvider> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"title": "Meta Reference", | ||
"pages": [ | ||
"title.mdx", | ||
"link.mdx", | ||
"meta.mdx", | ||
"style.mdx", | ||
"base.mdx", | ||
"metaprovider.mdx" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
title: Link | ||
order: 2 | ||
--- | ||
|
||
The Link component establishes a connection between the page and an external resource. | ||
Commonly, this is used for linking stylesheets and other associations. | ||
|
||
This component renders a [`link`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link) element within the document's `<head>`. | ||
|
||
```tsx twoslash | ||
import { Link } from "@solidjs/meta"; | ||
<Link rel="icon" href="/favicon.ico" />; | ||
``` | ||
|
||
## Usage | ||
|
||
### Adding a favicon | ||
|
||
To add a favicon in an app, `<Link>` can be used to point to the asset: | ||
|
||
```tsx twoslash | ||
import { MetaProvider, Link } from "@solidjs/meta"; | ||
|
||
export default function Root() { | ||
return ( | ||
<MetaProvider> | ||
<Link rel="icon" href="/favicon.ico" /> | ||
</MetaProvider> | ||
); | ||
} | ||
``` | ||
|
||
### Using an emoji as a favicon | ||
|
||
To use an emoji as a favicon, first create a function that returns a data URI containing an SVG image: | ||
|
||
```jsx | ||
const emojiSvg = (emoji) => { | ||
return ( | ||
`data:image/svg+xml` + | ||
`<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>${emoji}</text></svg>` | ||
); | ||
}; | ||
``` | ||
|
||
Following this, include the emoji as an argument within that function in the `href` property of the Link component: | ||
|
||
```jsx | ||
import { MetaProvider, Link } from "@solidjs/meta"; | ||
|
||
export default function Root() { | ||
return ( | ||
<MetaProvider> | ||
<Link rel="icon" href={emojiSvg("😎")} /> | ||
</MetaProvider> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: Meta | ||
order: 3 | ||
--- | ||
|
||
The `<Meta>` component represents metadata that cannot be represented by other HTML elements. | ||
It is a wrapper for the native [`meta`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta) element and has the same properties. | ||
|
||
```tsx twoslash | ||
import { Meta } from "@solidjs/meta"; | ||
|
||
<Meta name="description" content="My site description" />; | ||
``` | ||
|
||
|
||
`Meta` components can be placed in the [`MetaProvider`](/solid-meta/reference/meta/metaprovider) or added throughout the application for additional metadata or override parents. | ||
`Meta` tags are considered the same and will be overridden if `name` attributes match. | ||
## Usage | ||
|
||
### Adding `meta` tag | ||
|
||
```tsx twoslash {6-8} | ||
import { MetaProvider, Meta } from "@solidjs/meta"; | ||
|
||
export default function Root() { | ||
return ( | ||
<MetaProvider> | ||
<Meta charset="utf-8" /> | ||
<Meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<Meta name="description" content="Hacker News Clone built with Solid" /> | ||
</MetaProvider> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: MetaProvider | ||
order: 6 | ||
--- | ||
|
||
`MetaProvider` is a parent component responsible for wrapping all the metadata components. | ||
All components that are contained within this will be added to the application `<head/>` | ||
|
||
```tsx twoslash | ||
import { MetaProvider } from "@solidjs/meta"; | ||
|
||
<MetaProvider>// add meta components</MetaProvider>; | ||
``` |
Oops, something went wrong.