Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,20 @@ app.get('/', (c) =>
// <link rel="alternate" type="application/atom+xml" title="My Blog" href="/feed.atom">
```

`hono/jsx` では、`raw()` を使わずに、`feedLinks()` の結果を `<link>` 要素に変換します。

```tsx
import { feedLinks } from 'hono-feed/discovery'

const FeedLinks = () => (
<>
{feedLinks({ title: 'My Blog', rss: '/feed.rss', atom: '/feed.atom' }).map((l) => (
<link rel={l.rel} type={l.type} href={l.href} title={l.title} />
))}
</>
)
```

`feedLinks(options)` は同じデータを文字列ではなく単純な配列 (`{ rel, type, href, title? }[]`)で返します。JSX など、すでに使っているテンプレートの仕組みで使えます。どちらも `baseUrl` を受け取り、相対のフィード URL を絶対 URL にできます。未指定の場合、href は指定したままになります。相対 URL はブラウザーが現在のページを基準に解決するので、多くの場合はそれで問題ありません。

HTTP ヘッダーで同じことをするには ([RFC 8288](https://www.rfc-editor.org/rfc/rfc8288))、ミドルウェアの `feedLinkHeader` を使います。設定したフォーマットごとに `Link` ヘッダーを 1 つ追加しますが、対象は `Content-Type` が HTML の応答だけです。フィードの応答が自分の別形式を宣伝しても意味がないためです。
Expand Down Expand Up @@ -600,6 +614,16 @@ const results = await notifyHub(
// [{ hub: 'https://pubsubhubbub.appspot.com/', ok: true, status: 204 }]
```

Cloudflare Workers など、レスポンスを返すと処理が打ち切られるランタイムでは、Promise を `waitUntil` に渡してください。渡さないと、ハブに届く前にリクエストが中断されることがあります。

```ts
app.post('/publish', async (c) => {
await savePost(c)
c.executionCtx.waitUntil(notifyHub('https://pubsubhubbub.appspot.com/', 'https://example.com/feed.rss'))
return c.text('ok')
})
```

`notifyHub` は例外を投げません。2xx 以外の応答、ネットワークエラー、中断されたリクエスト (タイムアウトさせたいときは `{ signal }` を渡します)は、すべて拒否(rejection)ではなく結果として報告されます。そのため、到達できないハブが 1 つあっても、公開の流れ全体が失敗することはありません。いずれの場合も、購読者は次のポーリングで更新を受け取れます。

## ページネーション
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,20 @@ app.get('/', (c) =>
// <link rel="alternate" type="application/atom+xml" title="My Blog" href="/feed.atom">
```

With `hono/jsx`, map `feedLinks()` to `<link>` elements instead of reaching for `raw()`:

```tsx
import { feedLinks } from 'hono-feed/discovery'

const FeedLinks = () => (
<>
{feedLinks({ title: 'My Blog', rss: '/feed.rss', atom: '/feed.atom' }).map((l) => (
<link rel={l.rel} type={l.type} href={l.href} title={l.title} />
))}
</>
)
```

`feedLinks(options)` returns the same data as a plain array (`{ rel, type, href, title? }[]`) instead of a string, for JSX or any other templating you already use. Both accept `baseUrl` to absolutize relative feed URLs; left unset, hrefs stay exactly as given (relative, resolved by the browser against the current page — which is usually what you want).

For the HTTP-header equivalent ([RFC 8288](https://www.rfc-editor.org/rfc/rfc8288)), `feedLinkHeader` is middleware that appends one `Link` header per configured format, but only to responses whose `Content-Type` is HTML — a feed response has no use for advertising its own alternates:
Expand Down Expand Up @@ -600,6 +614,16 @@ const results = await notifyHub(
// [{ hub: 'https://pubsubhubbub.appspot.com/', ok: true, status: 204 }]
```

On Cloudflare Workers (and other runtimes that stop work once the response is sent), hand the promise to `waitUntil` so the ping isn't cut off. Without it the request can be cancelled before the hub is reached:

```ts
app.post('/publish', async (c) => {
await savePost(c)
c.executionCtx.waitUntil(notifyHub('https://pubsubhubbub.appspot.com/', 'https://example.com/feed.rss'))
return c.text('ok')
})
```

`notifyHub` never throws — a non-2xx response, a network error, and an aborted request (pass `{ signal }` to time one out) are all reported as a result rather than a rejection, so one unreachable hub can't fail your publish flow. Subscribers still get the update on their next poll either way.

## Pagination
Expand Down
34 changes: 34 additions & 0 deletions base/README.base.md
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,25 @@ app.get('/', (c) =>
// <link rel="alternate" type="application/atom+xml" title="My Blog" href="/feed.atom">
```

:::kiritan{locale=en}
With `hono/jsx`, map `feedLinks()` to `<link>` elements instead of reaching for `raw()`:
:::
:::kiritan{locale=ja}
`hono/jsx` では、`raw()` を使わずに、`feedLinks()` の結果を `<link>` 要素に変換します。
:::

```tsx
import { feedLinks } from 'hono-feed/discovery'

const FeedLinks = () => (
<>
{feedLinks({ title: 'My Blog', rss: '/feed.rss', atom: '/feed.atom' }).map((l) => (
<link rel={l.rel} type={l.type} href={l.href} title={l.title} />
))}
</>
)
```

:::kiritan{locale=en}
`feedLinks(options)` returns the same data as a plain array (`{ rel, type, href, title? }[]`) instead of a string, for JSX or any other templating you already use. Both accept `baseUrl` to absolutize relative feed URLs; left unset, hrefs stay exactly as given (relative, resolved by the browser against the current page — which is usually what you want).

Expand Down Expand Up @@ -877,6 +896,21 @@ const results = await notifyHub(
// [{ hub: 'https://pubsubhubbub.appspot.com/', ok: true, status: 204 }]
```

:::kiritan{locale=en}
On Cloudflare Workers (and other runtimes that stop work once the response is sent), hand the promise to `waitUntil` so the ping isn't cut off. Without it the request can be cancelled before the hub is reached:
:::
:::kiritan{locale=ja}
Cloudflare Workers など、レスポンスを返すと処理が打ち切られるランタイムでは、Promise を `waitUntil` に渡してください。渡さないと、ハブに届く前にリクエストが中断されることがあります。
:::

```ts
app.post('/publish', async (c) => {
await savePost(c)
c.executionCtx.waitUntil(notifyHub('https://pubsubhubbub.appspot.com/', 'https://example.com/feed.rss'))
return c.text('ok')
})
```

:::kiritan{locale=en}
`notifyHub` never throws — a non-2xx response, a network error, and an aborted request (pass `{ signal }` to time one out) are all reported as a result rather than a rejection, so one unreachable hub can't fail your publish flow. Subscribers still get the update on their next poll either way.

Expand Down
Loading