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
31 changes: 31 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,37 @@ feed.addItem({

`podcast` は RSS 2.0 以外 (ほかのすべての RSS バージョン、Atom、JSON Feed)では無視されます。対応づけられる項目がないためです。`xmlns:itunes` / `xmlns:podcast` を `customNamespaces` に明示した場合は、自動の宣言より常にそちらが優先されます。

### Podcasting 2.0 のその他のタグ

`guid` / `locked` / `funding` / `transcript` / `chapters` のほかに、次の [Podcasting 2.0](https://github.com/Podcastindex-org/podcast-namespace) の要素を扱えます。

| 要素 | フィード (`options.podcast`) | エピソード (`item.podcast`) |
| --- | --- | --- |
| `podcast:person` | `person: [{ name, role?, group?, img?, href? }]` | 同じ |
| `podcast:license` | `license: { identifier, url? }` | 同じ |
| `podcast:location` | `location: { name, geo?, osm? }` | 同じ |
| `podcast:images` | `images: { srcset }` | 同じ |
| `podcast:socialInteract` | `socialInteract: [{ protocol, uri?, accountId?, accountUrl?, priority? }]` | 同じ |
| `podcast:medium` | `medium: 'podcast' \| 'music' \| 'video' \| …` | なし |
| `podcast:trailer` | `trailer: [{ title, url, pubDate, length?, type?, season? }]` | なし |
| `podcast:season` | なし | `podcastSeason: { number, name? }` |
| `podcast:episode` | なし | `podcastEpisode: { number, display? }` |

```ts
feed.addItem({
title: 'Episode 12.5',
link: 'https://example.com/12-5',
podcast: {
person: [{ name: 'Ann Host', role: 'host', img: '/ann.jpg' }],
license: { identifier: 'CC-BY-4.0' },
podcastSeason: { number: 2, name: 'Race to Mars' },
podcastEpisode: { number: 12.5, display: 'Ch.12.5' },
},
})
```

URL (`img`、`href`、ライセンスの `url`、`uri`、`accountUrl`、トレーラーの `url`)は `baseUrl` を基準に絶対 URL になります。`podcastSeason` / `podcastEpisode` を iTunes の `season` / `episode` と分けているのは、Podcasting 2.0 版には名前や表示用ラベルと、小数の番号を持たせられるためです。`podcast:value` (Value4Value)と `podcast:liveItem` は扱いません。必要なら `customXml` を使ってください。

## フィードの発見

フィードを配信するだけでは半分です。*見つけてもらえる*ようにする必要もあります。`hono-feed/discovery` は、ブラウザーやフィードリーダーが探す `<link rel="alternate">` タグと、それに相当する HTTP の `Link` ヘッダーを生成します。`serveFeed` 自身が使うのと同じ MIME タイプの表から作るので、両者がずれることはありません。
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,37 @@ feed.addItem({

`podcast` is ignored outside RSS 2.0 (every other RSS version, Atom, and JSON Feed) — there's no equivalent to map it to. An explicit `customNamespaces` entry for `xmlns:itunes` / `xmlns:podcast` always wins over the automatic declaration.

### More Podcasting 2.0 tags

Beyond `guid` / `locked` / `funding` / `transcript` / `chapters`, these [Podcasting 2.0](https://github.com/Podcastindex-org/podcast-namespace) elements are modeled:

| Element | Feed (`options.podcast`) | Episode (`item.podcast`) |
| --- | --- | --- |
| `podcast:person` | `person: [{ name, role?, group?, img?, href? }]` | same |
| `podcast:license` | `license: { identifier, url? }` | same |
| `podcast:location` | `location: { name, geo?, osm? }` | same |
| `podcast:images` | `images: { srcset }` | same |
| `podcast:socialInteract` | `socialInteract: [{ protocol, uri?, accountId?, accountUrl?, priority? }]` | same |
| `podcast:medium` | `medium: 'podcast' \| 'music' \| 'video' \| …` | — |
| `podcast:trailer` | `trailer: [{ title, url, pubDate, length?, type?, season? }]` | — |
| `podcast:season` | — | `podcastSeason: { number, name? }` |
| `podcast:episode` | — | `podcastEpisode: { number, display? }` |

```ts
feed.addItem({
title: 'Episode 12.5',
link: 'https://example.com/12-5',
podcast: {
person: [{ name: 'Ann Host', role: 'host', img: '/ann.jpg' }],
license: { identifier: 'CC-BY-4.0' },
podcastSeason: { number: 2, name: 'Race to Mars' },
podcastEpisode: { number: 12.5, display: 'Ch.12.5' },
},
})
```

URLs (`img`, `href`, the license `url`, `uri`, `accountUrl`, the trailer `url`) are absolutized against `baseUrl`. `podcastSeason` / `podcastEpisode` are separate from the iTunes `season` / `episode` because the Podcasting 2.0 versions can carry a name or label and a fractional number. `podcast:value` (Value4Value) and `podcast:liveItem` are not modeled; reach for `customXml` if you need them.

## Feed discovery

Serving a feed is half the story — it also has to be *findable*. `hono-feed/discovery` generates the `<link rel="alternate">` tags browsers and feed readers look for, and an HTTP `Link` header equivalent, from the same MIME-type table `serveFeed` itself uses (so they can never drift apart).
Expand Down
62 changes: 62 additions & 0 deletions base/README.base.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,37 @@ feed.addItem({

`podcast` is ignored outside RSS 2.0 (every other RSS version, Atom, and JSON Feed) — there's no equivalent to map it to. An explicit `customNamespaces` entry for `xmlns:itunes` / `xmlns:podcast` always wins over the automatic declaration.

### More Podcasting 2.0 tags

Beyond `guid` / `locked` / `funding` / `transcript` / `chapters`, these [Podcasting 2.0](https://github.com/Podcastindex-org/podcast-namespace) elements are modeled:

| Element | Feed (`options.podcast`) | Episode (`item.podcast`) |
| --- | --- | --- |
| `podcast:person` | `person: [{ name, role?, group?, img?, href? }]` | same |
| `podcast:license` | `license: { identifier, url? }` | same |
| `podcast:location` | `location: { name, geo?, osm? }` | same |
| `podcast:images` | `images: { srcset }` | same |
| `podcast:socialInteract` | `socialInteract: [{ protocol, uri?, accountId?, accountUrl?, priority? }]` | same |
| `podcast:medium` | `medium: 'podcast' \| 'music' \| 'video' \| …` | — |
| `podcast:trailer` | `trailer: [{ title, url, pubDate, length?, type?, season? }]` | — |
| `podcast:season` | — | `podcastSeason: { number, name? }` |
| `podcast:episode` | — | `podcastEpisode: { number, display? }` |

```ts
feed.addItem({
title: 'Episode 12.5',
link: 'https://example.com/12-5',
podcast: {
person: [{ name: 'Ann Host', role: 'host', img: '/ann.jpg' }],
license: { identifier: 'CC-BY-4.0' },
podcastSeason: { number: 2, name: 'Race to Mars' },
podcastEpisode: { number: 12.5, display: 'Ch.12.5' },
},
})
```

URLs (`img`, `href`, the license `url`, `uri`, `accountUrl`, the trailer `url`) are absolutized against `baseUrl`. `podcastSeason` / `podcastEpisode` are separate from the iTunes `season` / `episode` because the Podcasting 2.0 versions can carry a name or label and a fractional number. `podcast:value` (Value4Value) and `podcast:liveItem` are not modeled; reach for `customXml` if you need them.

## Feed discovery

Serving a feed is half the story — it also has to be *findable*. `hono-feed/discovery` generates the `<link rel="alternate">` tags browsers and feed readers look for, and an HTTP `Link` header equivalent, from the same MIME-type table `serveFeed` itself uses (so they can never drift apart).
Expand All @@ -749,6 +780,37 @@ For an HTML `<head>`:

`podcast` は RSS 2.0 以外 (ほかのすべての RSS バージョン、Atom、JSON Feed)では無視されます。対応づけられる項目がないためです。`xmlns:itunes` / `xmlns:podcast` を `customNamespaces` に明示した場合は、自動の宣言より常にそちらが優先されます。

### Podcasting 2.0 のその他のタグ

`guid` / `locked` / `funding` / `transcript` / `chapters` のほかに、次の [Podcasting 2.0](https://github.com/Podcastindex-org/podcast-namespace) の要素を扱えます。

| 要素 | フィード (`options.podcast`) | エピソード (`item.podcast`) |
| --- | --- | --- |
| `podcast:person` | `person: [{ name, role?, group?, img?, href? }]` | 同じ |
| `podcast:license` | `license: { identifier, url? }` | 同じ |
| `podcast:location` | `location: { name, geo?, osm? }` | 同じ |
| `podcast:images` | `images: { srcset }` | 同じ |
| `podcast:socialInteract` | `socialInteract: [{ protocol, uri?, accountId?, accountUrl?, priority? }]` | 同じ |
| `podcast:medium` | `medium: 'podcast' \| 'music' \| 'video' \| …` | なし |
| `podcast:trailer` | `trailer: [{ title, url, pubDate, length?, type?, season? }]` | なし |
| `podcast:season` | なし | `podcastSeason: { number, name? }` |
| `podcast:episode` | なし | `podcastEpisode: { number, display? }` |

```ts
feed.addItem({
title: 'Episode 12.5',
link: 'https://example.com/12-5',
podcast: {
person: [{ name: 'Ann Host', role: 'host', img: '/ann.jpg' }],
license: { identifier: 'CC-BY-4.0' },
podcastSeason: { number: 2, name: 'Race to Mars' },
podcastEpisode: { number: 12.5, display: 'Ch.12.5' },
},
})
```

URL (`img`、`href`、ライセンスの `url`、`uri`、`accountUrl`、トレーラーの `url`)は `baseUrl` を基準に絶対 URL になります。`podcastSeason` / `podcastEpisode` を iTunes の `season` / `episode` と分けているのは、Podcasting 2.0 版には名前や表示用ラベルと、小数の番号を持たせられるためです。`podcast:value` (Value4Value)と `podcast:liveItem` は扱いません。必要なら `customXml` を使ってください。

## フィードの発見

フィードを配信するだけでは半分です。*見つけてもらえる*ようにする必要もあります。`hono-feed/discovery` は、ブラウザーやフィードリーダーが探す `<link rel="alternate">` タグと、それに相当する HTTP の `Link` ヘッダーを生成します。`serveFeed` 自身が使うのと同じ MIME タイプの表から作るので、両者がずれることはありません。
Expand Down
125 changes: 122 additions & 3 deletions src/formats/rss/podcast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import type { Enclosure, FeedItem, FeedOptions, ItemPodcast } from '../../types'
import type {
Enclosure,
FeedItem,
FeedOptions,
ItemPodcast,
PodcastImages,
PodcastLicense,
PodcastLocation,
PodcastPerson,
PodcastSocialInteract,
} from '../../types'
import { rfc822 } from '../../utils/date'
import { firstEnclosure } from '../../utils/enclosure'
import { absolutize } from '../../utils/url'
import { el, type Node, tag } from '../../utils/xml'
Expand All @@ -24,7 +35,18 @@ function hasItunesFeedFields(p: NonNullable<FeedOptions['podcast']>): boolean {
}

function hasPodcastNsFeedFields(p: NonNullable<FeedOptions['podcast']>): boolean {
return p.guid !== undefined || p.locked !== undefined || (p.funding?.length ?? 0) > 0
return (
p.guid !== undefined ||
p.locked !== undefined ||
(p.funding?.length ?? 0) > 0 ||
(p.person?.length ?? 0) > 0 ||
p.license !== undefined ||
p.medium !== undefined ||
p.location !== undefined ||
p.images !== undefined ||
(p.trailer?.length ?? 0) > 0 ||
(p.socialInteract?.length ?? 0) > 0
)
}

function hasItunesItemFields(p: ItemPodcast): boolean {
Expand All @@ -42,7 +64,68 @@ function hasItunesItemFields(p: ItemPodcast): boolean {
}

function hasPodcastNsItemFields(p: ItemPodcast): boolean {
return (p.transcript?.length ?? 0) > 0 || p.chapters !== undefined
return (
(p.transcript?.length ?? 0) > 0 ||
p.chapters !== undefined ||
(p.person?.length ?? 0) > 0 ||
p.license !== undefined ||
p.location !== undefined ||
p.images !== undefined ||
(p.socialInteract?.length ?? 0) > 0 ||
p.podcastSeason !== undefined ||
p.podcastEpisode !== undefined
)
}

// Podcasting 2.0 elements that look the same at feed and item level.
function sharedPodcastNodes(
p: {
person?: PodcastPerson[]
license?: PodcastLicense
location?: PodcastLocation
images?: PodcastImages
socialInteract?: PodcastSocialInteract[]
},
base: string | undefined,
): Node[] {
const nodes: Node[] = []
for (const person of p.person ?? []) {
nodes.push(
el(
'podcast:person',
{
role: person.role,
group: person.group,
img: absolutize(person.img, base),
href: absolutize(person.href, base),
},
person.name,
),
)
}
if (p.license) {
nodes.push(
el('podcast:license', { url: absolutize(p.license.url, base) }, p.license.identifier),
)
}
if (p.location) {
nodes.push(
el('podcast:location', { geo: p.location.geo, osm: p.location.osm }, p.location.name),
)
}
if (p.images) nodes.push(el('podcast:images', { srcset: p.images.srcset }))
for (const social of p.socialInteract ?? []) {
nodes.push(
el('podcast:socialInteract', {
protocol: social.protocol,
uri: absolutize(social.uri, base),
accountId: social.accountId,
accountUrl: absolutize(social.accountUrl, base),
priority: social.priority,
}),
)
}
return nodes
}

/**
Expand Down Expand Up @@ -121,6 +204,23 @@ export function podcastChannelNodes(p: FeedOptions['podcast'], base: string | un
nodes.push(el('podcast:funding', { url: absolutize(funding.url, base) }, funding.text))
}
}
if (p.medium) nodes.push(tag('podcast:medium', p.medium))
for (const trailer of p.trailer ?? []) {
nodes.push(
el(
'podcast:trailer',
{
url: absolutize(trailer.url, base),
pubdate: rfc822(trailer.pubDate),
length: trailer.length,
type: trailer.type,
season: trailer.season,
},
trailer.title,
),
)
}
nodes.push(...sharedPodcastNodes(p, base))
return nodes
}

Expand Down Expand Up @@ -165,5 +265,24 @@ export function podcastItemNodes(
}),
)
}
if (podcast.podcastSeason) {
nodes.push(
el(
'podcast:season',
{ name: podcast.podcastSeason.name },
String(podcast.podcastSeason.number),
),
)
}
if (podcast.podcastEpisode) {
nodes.push(
el(
'podcast:episode',
{ display: podcast.podcastEpisode.display },
String(podcast.podcastEpisode.number),
),
)
}
nodes.push(...sharedPodcastNodes(podcast, base))
return nodes
}
Loading
Loading