Skip to content

Commit 8dab257

Browse files
authored
feat(docs): add documentation for React Wrap Balancer and robots.txt API endpoint (#476) (#498)
closed: #476
1 parent 584495d commit 8dab257

File tree

1 file changed

+128
-1
lines changed

1 file changed

+128
-1
lines changed

apps/docs/pages/wiki.mdx

+128-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,54 @@ const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content }) => (
116116
export default MarkdownRenderer;
117117
```
118118
119+
## React Wrap Balancer
120+
121+
> [React Wrap Balancer] is a simple React Component that makes your titles more readable in different viewport sizes. It improves the wrapping to avoid situations like single word in the last line, makes the content more "balanced": [^1]
122+
123+
[React Wrap Balancer]: https://react-wrap-balancer.vercel.app/
124+
125+
![Simple React Component That Makes Titles More Readable](https://github.com/shuding/react-wrap-balancer/raw/main/.github/demo.gif)
126+
127+
### Usage
128+
129+
We have to install the package first:
130+
131+
```bash
132+
npm i react-wrap-balancer
133+
```
134+
135+
Then we can use it in our project:
136+
137+
```tsx
138+
import Balancer from 'react-wrap-balancer'
139+
140+
// ...
141+
142+
function Title() {
143+
return (
144+
<h1>
145+
<Balancer>My Awesome Title</Balancer>
146+
</h1>
147+
)
148+
}
149+
```
150+
151+
If we have multiple `<Balancer>` components used, we can wrap them with `<Provider>` to share the re-balance logic:
152+
153+
```tsx
154+
import { Provider } from 'react-wrap-balancer'
155+
156+
// ...
157+
158+
function App() {
159+
return (
160+
<Provider>
161+
<MyApp/>
162+
</Provider>
163+
)
164+
}
165+
```
166+
119167
## Next.js Image Fast Loading
120168
121169
@@ -146,4 +194,83 @@ acceptString("baz");
146194
147195
https://www.threads.net/@jimmy.chiang/post/C_vl632ygU_/?xmt=AQGzwdnxgbmCCfAF8xCgI2zZiemQtJDR7omD6Mb26Ge3CA
148196
149-
https://www.youtube.com/live/8HoOxOd86M4?t=2778&si=P2mxsBXVq8UmrAX_
197+
https://www.youtube.com/live/8HoOxOd86M4?t=2778&si=P2mxsBXVq8UmrAX_
198+
199+
## Robots.txt
200+
201+
```tsx
202+
/**
203+
* https://www.cloudflare.com/zh-tw/learning/bots/what-is-robots-txt/
204+
* https://www.cloudflare.com/robots.txt
205+
* https://github.com/vercel/vercel/blob/3e4223684609dbdb7d9a2b286294fe07941bf0d4/examples/hydrogen-2/app/routes/%5Brobots.txt%5D.tsx#
206+
* https://github.com/vercel/vercel/blob/3e4223684609dbdb7d9a2b286294fe07941bf0d4/packages/cli/test/dev/integration-2.test.ts#
207+
* https://github.com/vercel/vercel/blob/3e4223684609dbdb7d9a2b286294fe07941bf0d4/examples/hydrogen/src/routes/robots.txt.server.ts
208+
* @returns
209+
*/
210+
211+
const robotsTxtContent = `
212+
# ________
213+
# __,_, | |
214+
# [_|_/ | OK |
215+
# // |________|
216+
# _// __ /
217+
# (_|) |@@|
218+
# \\ \\__ \\--/ __
219+
# \\o__|----| | __
220+
# \\ }{ /\\ )_ / _\\
221+
# /\\__\\/ \\__O (__
222+
# (--/\\--) \\__/
223+
# _)( )(_
224+
# \`---''---\`
225+
User-agent: *
226+
Disallow:
227+
`;
228+
```
229+
230+
```ts
231+
/**
232+
* This API endpoint generates a robots.txt file. Use this to control
233+
* access to your resources from SEO crawlers.
234+
* Learn more: https://developers.google.com/search/docs/advanced/robots/create-robots-txt
235+
*/
236+
237+
import type {HydrogenRequest} from '@shopify/hydrogen';
238+
239+
export async function api(request) {
240+
const url = new URL(request.url);
241+
242+
return new Response(robotsTxtData({url: url.origin}), {
243+
headers: {
244+
'content-type': 'text/plain',
245+
// Cache for 24 hours
246+
'cache-control': `max-age=${60 * 60 * 24}`,
247+
},
248+
});
249+
}
250+
251+
function robotsTxtData({url}: {url: string}) {
252+
const sitemapUrl = url ? `${url}/sitemap.xml` : undefined;
253+
254+
return `
255+
User-agent: *
256+
Disallow: /admin
257+
Disallow: /cart
258+
Disallow: /orders
259+
Disallow: /checkouts/
260+
Disallow: /checkout
261+
Disallow: /carts
262+
Disallow: /account
263+
${sitemapUrl ? `Sitemap: ${sitemapUrl}` : ''}
264+
265+
# Google adsbot ignores robots.txt unless specifically named!
266+
User-agent: adsbot-google
267+
Disallow: /checkouts/
268+
Disallow: /checkout
269+
Disallow: /carts
270+
Disallow: /orders
271+
272+
User-agent: Pinterest
273+
Crawl-delay: 1
274+
`.trim();
275+
}
276+
```

0 commit comments

Comments
 (0)