Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add RSS feed discovery

Chocobozzz21f0fbde0dcc
diff --git a/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts b/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts
index c5558af4c2..b615e63964 100644
--- a/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts
+++ b/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts
@@ -1,16 +1,15 @@
import { Component, OnInit } from '@angular/core'
import { AuthService, ConfirmService, Notifier, ScopedTokensService } from '@app/core'
+import { VideoService } from '@app/shared/shared-main/video/video.service'
import { FeedFormat, ScopedToken } from '@peertube/peertube-models'
import { environment } from '../../../environments/environment'
import { InputTextComponent } from '../../shared/shared-forms/input-text.component'
-import { GlobalIconComponent } from '../../shared/shared-icons/global-icon.component'
-import { VideoService } from '@app/shared/shared-main/video/video.service'
@Component({
selector: 'my-account-applications',
templateUrl: './my-account-applications.component.html',
styleUrls: [ './my-account-applications.component.scss' ],
- imports: [ GlobalIconComponent, InputTextComponent ]
+ imports: [ InputTextComponent ]
})
export class MyAccountApplicationsComponent implements OnInit {
feedUrl: string
diff --git a/client/src/app/+video-channels/video-channels.component.ts b/client/src/app/+video-channels/video-channels.component.ts
index 63d107bb8a..22c7fa646e 100644
--- a/client/src/app/+video-channels/video-channels.component.ts
+++ b/client/src/app/+video-channels/video-channels.component.ts
@@ -1,7 +1,8 @@
import { NgClass, NgIf, NgTemplateOutlet } from '@angular/common'
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, RouterLink, RouterOutlet } from '@angular/router'
-import { AuthService, Hotkey, HotkeysService, MarkdownService, MetaService, RestExtractor, ScreenService } from '@app/core'
+import { AuthService, Hotkey, HotkeysService, MarkdownService, MetaService, RestExtractor, ScreenService, ServerService } from '@app/core'
+import { getOriginUrl } from '@app/helpers'
import { Account } from '@app/shared/shared-main/account/account.model'
import { VideoChannel } from '@app/shared/shared-main/channel/video-channel.model'
import { VideoChannelService } from '@app/shared/shared-main/channel/video-channel.service'
@@ -10,6 +11,7 @@ import { VideoService } from '@app/shared/shared-main/video/video.service'
import { BlocklistService } from '@app/shared/shared-moderation/blocklist.service'
import { SupportModalComponent } from '@app/shared/shared-support-modal/support-modal.component'
import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription/subscribe-button.component'
+import { getChannelRSSFeeds } from '@peertube/peertube-core-utils'
import { HttpStatusCode, UserRight } from '@peertube/peertube-models'
import { Subscription } from 'rxjs'
import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
@@ -63,7 +65,8 @@ export class VideoChannelsComponent implements OnInit, OnDestroy {
private screenService: ScreenService,
private markdown: MarkdownService,
private blocklist: BlocklistService,
- private metaService: MetaService
+ private metaService: MetaService,
+ private server: ServerService
) { }
ngOnInit () {
@@ -79,6 +82,7 @@ export class VideoChannelsComponent implements OnInit, OnDestroy {
)
.subscribe(async videoChannel => {
this.metaService.setTitle(videoChannel.displayName)
+ this.metaService.setRSSFeeds(getChannelRSSFeeds(getOriginUrl(), this.server.getHTMLConfig().instance.name, videoChannel))
this.channelDescriptionHTML = await this.markdown.textMarkdownToHTML({
markdown: videoChannel.description,
@@ -121,6 +125,8 @@ export class VideoChannelsComponent implements OnInit, OnDestroy {
// Unbind hotkeys
if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
+
+ this.metaService.revertMetaTags()
}
isInSmallView () {
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts
index 6f4c3fa65c..5ebea6e4eb 100644
--- a/client/src/app/+videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch.component.ts
@@ -18,7 +18,7 @@ import {
UserService
} from '@app/core'
import { HooksService } from '@app/core/plugins/hooks.service'
-import { isXPercentInViewport, scrollToTop, toBoolean } from '@app/helpers'
+import { getOriginUrl, isXPercentInViewport, scrollToTop, toBoolean } from '@app/helpers'
import { VideoCaptionService } from '@app/shared/shared-main/video-caption/video-caption.service'
import { VideoChapterService } from '@app/shared/shared-main/video/video-chapter.service'
import { VideoDetails } from '@app/shared/shared-main/video/video-details.model'
@@ -29,7 +29,7 @@ import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription/s
import { LiveVideoService } from '@app/shared/shared-video-live/live-video.service'
import { VideoPlaylist } from '@app/shared/shared-video-playlist/video-playlist.model'
import { VideoPlaylistService } from '@app/shared/shared-video-playlist/video-playlist.service'
-import { timeToInt } from '@peertube/peertube-core-utils'
+import { getVideoWatchRSSFeeds, timeToInt } from '@peertube/peertube-core-utils'
import {
HTMLServerConfig,
HttpStatusCode,
@@ -43,11 +43,6 @@ import {
VideoState,
VideoStateType
} from '@peertube/peertube-models'
-import { logger } from '@root-helpers/logger'
-import { isP2PEnabled, videoRequiresFileToken, videoRequiresUserAuth } from '@root-helpers/video'
-import debug from 'debug'
-import { forkJoin, map, Observable, of, Subscription, switchMap } from 'rxjs'
-import { environment } from '../../../environments/environment'
import {
cleanupVideoWatch,
getStoredTheater,
@@ -59,6 +54,11 @@ import {
PlayerMode,
videojs
} from '@peertube/player'
+import { logger } from '@root-helpers/logger'
+import { isP2PEnabled, videoRequiresFileToken, videoRequiresUserAuth } from '@root-helpers/video'
+import debug from 'debug'
+import { forkJoin, map, Observable, of, Subscription, switchMap } from 'rxjs'
+import { environment } from '../../../environments/environment'
import { DateToggleComponent } from '../../shared/shared-main/date/date-toggle.component'
import { PluginPlaceholderComponent } from '../../shared/shared-main/plugins/plugin-placeholder.component'
import { VideoViewsCounterComponent } from '../../shared/shared-video/video-views-counter.component'
@@ -229,6 +229,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
// Unbind hotkeys
this.hotkeysService.remove(this.hotkeys)
+
+ this.metaService.revertMetaTags()
}
getCurrentTime () {
@@ -990,7 +992,11 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
private setMetaTags (video: Video) {
this.metaService.setTitle(video.name)
- this.metaService.setTag('description', video.description)
+ this.metaService.setDescription(video.description)
+
+ this.metaService.setRSSFeeds(
+ getVideoWatchRSSFeeds(getOriginUrl(), this.serverConfig.instance.name, { ...video, privacy: video.privacy.id })
+ )
}
private getUrlOptions (): URLOptions {
diff --git a/client/src/app/core/routing/meta.service.ts b/client/src/app/core/routing/meta.service.ts
index d50f0d65a0..c2cd1205ae 100644
--- a/client/src/app/core/routing/meta.service.ts
+++ b/client/src/app/core/routing/meta.service.ts
@@ -1,5 +1,7 @@
import { Injectable } from '@angular/core'
import { Meta, Title } from '@angular/platform-browser'
+import { getOriginUrl } from '@app/helpers'
+import { getDefaultRSSFeeds } from '@peertube/peertube-core-utils'
import { HTMLServerConfig } from '@peertube/peertube-models'
import { ServerService } from '../server'
@@ -19,6 +21,10 @@ export class MetaService {
this.config = this.server.getHTMLConfig()
}
+ update (meta: MetaSettings) {
+ this.setTitle(meta.title)
+ }
+
setTitle (subTitle?: string) {
let title = ''
if (subTitle) title += `${subTitle} - `
@@ -28,11 +34,30 @@ export class MetaService {
this.titleService.setTitle(title)
}
- setTag (name: string, value: string) {
- this.meta.addTag({ name, content: value })
+ setDescription (description?: string) {
+ this.meta.updateTag({ name: 'description', content: description || this.config.instance.shortDescription })
}
- update (meta: MetaSettings) {
- this.setTitle(meta.title)
+ revertMetaTags () {
+ this.setTitle()
+ this.setDescription()
+
+ this.setRSSFeeds(getDefaultRSSFeeds(getOriginUrl(), this.config.instance.name))
+ }
+
+ setRSSFeeds (rssFeeds: { title: string, url: string }[]) {
+ const head = document.getElementsByTagName('head')[0]
+
+ head.querySelectorAll('link[rel="alternate"]').forEach((el) => head.removeChild(el))
+
+ for (const rssFeed of rssFeeds) {
+ const link = document.createElement('link')
+ link.rel = 'alternate'
+ link.type = 'application/rss+xml'
+ link.title = rssFeed.title
+ link.href = rssFeed.url
+
+ head.appendChild(link)
+ }
}
}
diff --git a/client/src/app/helpers/utils/url.ts b/client/src/app/helpers/utils/url.ts
index 9e7dc3e6fe..85b3d7fea3 100644
--- a/client/src/app/helpers/utils/url.ts
+++ b/client/src/app/helpers/utils/url.ts
@@ -1,6 +1,6 @@
import { environment } from '../../../environments/environment'
-function getAbsoluteAPIUrl () {
+export function getAbsoluteAPIUrl () {
let absoluteAPIUrl = environment.hmr === true
? 'http://localhost:9000'
: environment.apiUrl
@@ -13,11 +13,15 @@ function getAbsoluteAPIUrl () {
return absoluteAPIUrl
}
-function getAPIHost () {
+export function getOriginUrl () {
+ return environment.originServerUrl || window.location.origin
+}
+
+export function getAPIHost () {
return new URL(getAbsoluteAPIUrl()).host
}
-function getAbsoluteEmbedUrl () {
+export function getAbsoluteEmbedUrl () {
let absoluteEmbedUrl = environment.originServerUrl
if (!absoluteEmbedUrl) {
// The Embed is on the same domain
@@ -28,7 +32,7 @@ function getAbsoluteEmbedUrl () {
}
// Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34
-function objectToFormData (obj: any, form?: FormData, namespace?: string) {
+export function objectToFormData (obj: any, form?: FormData, namespace?: string) {
const fd = form || new FormData()
let formKey
@@ -52,11 +56,3 @@ function objectToFormData (obj: any, form?: FormData, namespace?: string) {
return fd
}
-
-export {
- getAbsoluteAPIUrl,
- getAPIHost,
- getAbsoluteEmbedUrl,
-
- objectToFormData
-}
diff --git a/client/src/root-helpers/url.ts b/client/src/root-helpers/url.ts
index b2f0c8b85c..67a5bb158d 100644
--- a/client/src/root-helpers/url.ts
+++ b/client/src/root-helpers/url.ts
@@ -1,16 +1,16 @@
-function getParamToggle (params: URLSearchParams, name: string, defaultValue?: boolean) {
+export function getParamToggle (params: URLSearchParams, name: string, defaultValue?: boolean) {
return params.has(name)
? (params.get(name) === '1' || params.get(name) === 'true')
: defaultValue
}
-function getParamString (params: URLSearchParams, name: string, defaultValue?: string) {
+export function getParamString (params: URLSearchParams, name: string, defaultValue?: string) {
return params.has(name)
? params.get(name)
: defaultValue
}
-function objectToUrlEncoded (obj: any) {
+export function objectToUrlEncoded (obj: any) {
const str: string[] = []
for (const key of Object.keys(obj)) {
str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]))
@@ -18,9 +18,3 @@ function objectToUrlEncoded (obj: any) {
return str.join('&')
}
-
-export {
- getParamToggle,
- getParamString,
- objectToUrlEncoded
-}
diff --git a/packages/core-utils/src/renderer/index.ts b/packages/core-utils/src/renderer/index.ts
index 0dd0a88085..9f0e47f46c 100644
--- a/packages/core-utils/src/renderer/index.ts
+++ b/packages/core-utils/src/renderer/index.ts
@@ -1,2 +1,3 @@
-export * from './markdown.js'
export * from './html.js'
+export * from './markdown.js'
+export * from './rss.js'
diff --git a/packages/core-utils/src/renderer/rss.ts b/packages/core-utils/src/renderer/rss.ts
new file mode 100644
index 0000000000..0148a13e21
--- /dev/null
+++ b/packages/core-utils/src/renderer/rss.ts
@@ -0,0 +1,41 @@
+import { VideoPrivacy, VideoPrivacyType } from '@peertube/peertube-models'
+
+export function getDefaultRSSFeeds (url: string, instanceName: string) {
+ return [
+ {
+ url: `${url}/feeds/videos.xml`,
+ // TODO: translate
+ title: `${instanceName} - Videos feed`
+ }
+ ]
+}
+
+export function getChannelRSSFeeds (url: string, instanceName: string, channel: { name: string, id: number }) {
+ return [
+ {
+ url: `${url}/feeds/podcast/videos.xml?videoChannelId=${channel.id}`,
+ // TODO: translate
+ title: `${channel.name} feed`
+ },
+
+ ...getDefaultRSSFeeds(url, instanceName)
+ ]
+}
+
+export function getVideoWatchRSSFeeds (
+ url: string,
+ instanceName: string,
+ video: { name: string, uuid: string, privacy: VideoPrivacyType }
+) {
+ if (video.privacy !== VideoPrivacy.PUBLIC) return getDefaultRSSFeeds(url, instanceName)
+
+ return [
+ {
+ url: `${url}/feeds/video-comments.xml?videoId=${video.uuid}`,
+ // TODO: translate
+ title: `${video.name} - Comments feed`
+ },
+
+ ...getDefaultRSSFeeds(url, instanceName)
+ ]
+}
diff --git a/packages/tests/src/client/og-twitter-tags.ts b/packages/tests/src/client/head-tags.ts
similarity index 82%
rename from packages/tests/src/client/og-twitter-tags.ts
rename to packages/tests/src/client/head-tags.ts
index 7e263fc0fb..11c11d444a 100644
--- a/packages/tests/src/client/og-twitter-tags.ts
+++ b/packages/tests/src/client/head-tags.ts
@@ -7,7 +7,7 @@ import { getWatchPlaylistBasePaths, getWatchVideoBasePaths, prepareClientTests }
config.truncateThreshold = 0
-describe('Test Open Graph and Twitter cards HTML tags', function () {
+describe('Test <head> HTML tags', function () {
let servers: PeerTubeServer[]
let account: Account
@@ -286,6 +286,66 @@ describe('Test Open Graph and Twitter cards HTML tags', function () {
})
})
+ describe('RSS links', function () {
+
+ async function commonPageTest (path: string) {
+ const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
+ const text = res.text
+
+ const feedUrl = `${servers[0].url}/feeds/videos.xml`
+ // eslint-disable-next-line max-len
+ expect(text).to.contain(`<link rel="alternate" type="application/rss+xml" title="super instance title - Videos feed" href="${feedUrl}" />`)
+ }
+
+ async function channelPageTest (path: string) {
+ await commonPageTest(path)
+
+ const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
+ const text = res.text
+
+ const feedUrl = `${servers[0].url}/feeds/podcast/videos.xml?videoChannelId=${servers[0].store.channel.id}`
+
+ // eslint-disable-next-line max-len
+ expect(text).to.contain(`<link rel="alternate" type="application/rss+xml" title="${servers[0].store.channel.displayName} feed" href="${feedUrl}" />`)
+ }
+
+ async function watchVideoPageTest (path: string) {
+ await commonPageTest(path)
+
+ const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
+ const text = res.text
+
+ const feedUrl = `${servers[0].url}/feeds/video-comments.xml?videoId=${servers[0].store.video.uuid}`
+ expect(text).to.contain(`<link rel="alternate" type="application/rss+xml" title="${videoName} - Comments feed" href="${feedUrl}" />`)
+ }
+
+ it('Should have valid RSS links on the watch video page', async function () {
+ for (const path of getWatchVideoBasePaths()) {
+ await watchVideoPageTest(path + videoIds[0])
+ }
+ })
+
+ it('Should have valid RSS links on the watch playlist page', async function () {
+ for (const path of getWatchPlaylistBasePaths()) {
+ for (const id of playlistIds) {
+ await commonPageTest(path + id)
+ }
+ }
+ })
+
+ it('Should have valid RSS links on the account page', async function () {
+ await commonPageTest('/accounts/' + account.name)
+ await commonPageTest('/a/' + account.name)
+ await commonPageTest('/@' + account.name)
+ })
+
+ it('Should have valid RSS links the channel page', async function () {
+ await channelPageTest('/video-channels/' + servers[0].store.channel.name)
+ await channelPageTest('/c/' + servers[0].store.channel.name)
+ await channelPageTest('/@' + servers[0].store.channel.name)
+ })
+ })
+
after(async function () {
await cleanupTests(servers)
})
diff --git a/packages/tests/src/client/index.ts b/packages/tests/src/client/index.ts
index 075a2803e3..43fbcc2bbc 100644
--- a/packages/tests/src/client/index.ts
+++ b/packages/tests/src/client/index.ts
@@ -1,4 +1,4 @@
export * from './embed-html.js'
export * from './index-html.js'
export * from './oembed.js'
-export * from './og-twitter-tags.js'
+export * from './head-tags.js'
diff --git a/server/core/lib/html/shared/actor-html.ts b/server/core/lib/html/shared/actor-html.ts
index 806260105f..46da6e5ae4 100644
--- a/server/core/lib/html/shared/actor-html.ts
+++ b/server/core/lib/html/shared/actor-html.ts
@@ -1,5 +1,6 @@
-import { escapeHTML, maxBy } from '@peertube/peertube-core-utils'
+import { escapeHTML, getChannelRSSFeeds, getDefaultRSSFeeds, maxBy } from '@peertube/peertube-core-utils'
import { HttpStatusCode } from '@peertube/peertube-models'
+import { WEBSERVER } from '@server/initializers/constants.js'
import { AccountModel } from '@server/models/account/account.js'
import { ActorImageModel } from '@server/models/actor/actor-image.js'
import { VideoChannelModel } from '@server/models/video/video-channel.js'
@@ -7,20 +8,30 @@ import { MAccountHost, MChannelHost } from '@server/types/models/index.js'
import express from 'express'
import { CONFIG } from '../../../initializers/config.js'
import { PageHtml } from './page-html.js'
-import { TagsHtml } from './tags-html.js'
+import { TagsHtml, TagsOptions } from './tags-html.js'
export class ActorHtml {
static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
const accountModelPromise = AccountModel.loadByNameWithHost(nameWithHost)
- return this.getAccountOrChannelHTMLPage(() => accountModelPromise, req, res)
+ return this.getAccountOrChannelHTMLPage({
+ loader: () => accountModelPromise,
+ getRSSFeeds: () => getDefaultRSSFeeds(WEBSERVER.URL, CONFIG.INSTANCE.NAME),
+ req,
+ res
+ })
}
static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
- const videoChannelModelPromise = VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
-
- return this.getAccountOrChannelHTMLPage(() => videoChannelModelPromise, req, res)
+ const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
+
+ return this.getAccountOrChannelHTMLPage({
+ loader: () => Promise.resolve(videoChannel),
+ getRSSFeeds: () => getChannelRSSFeeds(WEBSERVER.URL, CONFIG.INSTANCE.NAME, videoChannel),
+ req,
+ res
+ })
}
static async getActorHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
@@ -29,16 +40,28 @@ export class ActorHtml {
VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
])
- return this.getAccountOrChannelHTMLPage(() => Promise.resolve(account || channel), req, res)
+ return this.getAccountOrChannelHTMLPage({
+ loader: () => Promise.resolve(account || channel),
+
+ getRSSFeeds: () => account
+ ? getDefaultRSSFeeds(WEBSERVER.URL, CONFIG.INSTANCE.NAME)
+ : getChannelRSSFeeds(WEBSERVER.URL, CONFIG.INSTANCE.NAME, channel),
+
+ req,
+ res
+ })
}
// ---------------------------------------------------------------------------
- private static async getAccountOrChannelHTMLPage (
- loader: () => Promise<MAccountHost | MChannelHost>,
- req: express.Request,
+ private static async getAccountOrChannelHTMLPage (options: {
+ loader: () => Promise<MAccountHost | MChannelHost>
+ getRSSFeeds: (entity: MAccountHost | MChannelHost) => TagsOptions['rssFeeds']
+ req: express.Request
res: express.Response
- ) {
+ }) {
+ const { loader, getRSSFeeds, req, res } = options
+
const [ html, entity ] = await Promise.all([
PageHtml.getIndexHTML(req, res),
loader()
@@ -85,7 +108,9 @@ export class ActorHtml {
updatedAt: entity.updatedAt
},
- forbidIndexation: !entity.Actor.isOwned()
+ forbidIndexation: !entity.Actor.isOwned(),
+
+ rssFeeds: getRSSFeeds(entity)
}, {})
return customHTML
diff --git a/server/core/lib/html/shared/common-embed-html.ts b/server/core/lib/html/shared/common-embed-html.ts
deleted file mode 100644
index 565c3ddec5..0000000000
--- a/server/core/lib/html/shared/common-embed-html.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { MVideo } from '@server/types/models/video/video.js'
-import { TagsHtml } from './tags-html.js'
-import { MVideoPlaylist } from '@server/types/models/video/video-playlist.js'
-
-export class CommonEmbedHtml {
-
- static buildEmptyEmbedHTML (options: {
- html: string
- playlist?: MVideoPlaylist
- video?: MVideo
- }) {
- const { html, playlist, video } = options
-
- let htmlResult = TagsHtml.addTitleTag(html)
- htmlResult = TagsHtml.addDescriptionTag(htmlResult)
-
- return TagsHtml.addTags(htmlResult, { forbidIndexation: true }, { playlist, video })
- }
-}
diff --git a/server/core/lib/html/shared/common.ts b/server/core/lib/html/shared/common.ts
new file mode 100644
index 0000000000..507fbaee72
--- /dev/null
+++ b/server/core/lib/html/shared/common.ts
@@ -0,0 +1,16 @@
+import { MVideoPlaylist } from '@server/types/models/video/video-playlist.js'
+import { MVideo } from '@server/types/models/video/video.js'
+import { TagsHtml } from './tags-html.js'
+
+export function buildEmptyEmbedHTML (options: {
+ html: string
+ playlist?: MVideoPlaylist
+ video?: MVideo
+}) {
+ const { html, playlist, video } = options
+
+ let htmlResult = TagsHtml.addTitleTag(html)
+ htmlResult = TagsHtml.addDescriptionTag(htmlResult)
+
+ return TagsHtml.addTags(htmlResult, { forbidIndexation: true }, { playlist, video })
+}
diff --git a/server/core/lib/html/shared/page-html.ts b/server/core/lib/html/shared/page-html.ts
index 8825997514..d9b4cdd178 100644
--- a/server/core/lib/html/shared/page-html.ts
+++ b/server/core/lib/html/shared/page-html.ts
@@ -1,4 +1,11 @@
-import { buildFileLocale, escapeHTML, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '@peertube/peertube-core-utils'
+import {
+ buildFileLocale,
+ escapeHTML,
+ getDefaultLocale,
+ getDefaultRSSFeeds,
+ is18nLocale,
+ POSSIBLE_LOCALES
+} from '@peertube/peertube-core-utils'
import { ActorImageType, HTMLServerConfig } from '@peertube/peertube-models'
import { isTestOrDevInstance, root, sha256 } from '@peertube/peertube-node-utils'
import { CONFIG } from '@server/initializers/config.js'
@@ -52,7 +59,8 @@ export class PageHtml {
ogType: 'website',
twitterCard: 'summary_large_image',
- forbidIndexation: false
+ forbidIndexation: false,
+ rssFeeds: getDefaultRSSFeeds(WEBSERVER.URL, CONFIG.INSTANCE.NAME)
}, {})
return customHTML
diff --git a/server/core/lib/html/shared/playlist-html.ts b/server/core/lib/html/shared/playlist-html.ts
index 803c146dc0..3190ea7521 100644
--- a/server/core/lib/html/shared/playlist-html.ts
+++ b/server/core/lib/html/shared/playlist-html.ts
@@ -1,4 +1,4 @@
-import { addQueryParams, escapeHTML } from '@peertube/peertube-core-utils'
+import { addQueryParams, escapeHTML, getDefaultRSSFeeds } from '@peertube/peertube-core-utils'
import { HttpStatusCode, VideoPlaylistPrivacy } from '@peertube/peertube-models'
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
import { Memoize } from '@server/helpers/memoize.js'
@@ -8,7 +8,7 @@ import express from 'express'
import validator from 'validator'
import { CONFIG } from '../../../initializers/config.js'
import { MEMOIZE_TTL, WEBSERVER } from '../../../initializers/constants.js'
-import { CommonEmbedHtml } from './common-embed-html.js'
+import { buildEmptyEmbedHTML } from './common.js'
import { PageHtml } from './page-html.js'
import { TagsHtml } from './tags-html.js'
@@ -56,7 +56,7 @@ export class PlaylistHtml {
const [ html, playlist ] = await Promise.all([ PageHtml.getEmbedHTML(), playlistPromise ])
if (!playlist || playlist.privacy === VideoPlaylistPrivacy.PRIVATE) {
- return CommonEmbedHtml.buildEmptyEmbedHTML({ html, playlist })
+ return buildEmptyEmbedHTML({ html, playlist })
}
return this.buildPlaylistHTML({
@@ -126,7 +126,9 @@ export class PlaylistHtml {
twitterCard,
embed,
- oembedUrl: this.getOEmbedUrl(playlist, currentQuery)
+ oembedUrl: this.getOEmbedUrl(playlist, currentQuery),
+
+ rssFeeds: getDefaultRSSFeeds(WEBSERVER.URL, CONFIG.INSTANCE.NAME)
}, { playlist })
}
diff --git a/server/core/lib/html/shared/tags-html.ts b/server/core/lib/html/shared/tags-html.ts
index cb3e7dd2db..74a8cc7b01 100644
--- a/server/core/lib/html/shared/tags-html.ts
+++ b/server/core/lib/html/shared/tags-html.ts
@@ -7,7 +7,7 @@ import { CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, WEBSERVER } from '../../../initia
import { MVideo, MVideoPlaylist } from '../../../types/models/index.js'
import { Hooks } from '../../plugins/hooks.js'
-type Tags = {
+export type TagsOptions = {
forbidIndexation: boolean
url?: string
@@ -46,6 +46,11 @@ type Tags = {
}
oembedUrl?: string
+
+ rssFeeds?: {
+ title: string
+ url: string
+ }[]
}
type HookContext = {
@@ -81,7 +86,7 @@ export class TagsHtml {
// ---------------------------------------------------------------------------
- static async addTags (htmlStringPage: string, tagsValues: Tags, context: HookContext) {
+ static async addTags (htmlStringPage: string, tagsValues: TagsOptions, context: HookContext) {
const metaTags = {
...this.generateOpenGraphMetaTagsOptions(tagsValues),
...this.generateStandardMetaTagsOptions(tagsValues),
@@ -89,7 +94,7 @@ export class TagsHtml {
}
const schemaTags = await this.generateSchemaTagsOptions(tagsValues, context)
- const { url, escapedTitle, oembedUrl, forbidIndexation, relMe } = tagsValues
+ const { url, escapedTitle, oembedUrl, forbidIndexation, relMe, rssFeeds } = tagsValues
const oembedLinkTags: { type: string, href: string, escapedTitle: string }[] = []
@@ -134,12 +139,16 @@ export class TagsHtml {
tagsStr += `<meta name="robots" content="noindex" />`
}
+ for (const rssLink of (rssFeeds || [])) {
+ tagsStr += `<link rel="alternate" type="application/rss+xml" title="${escapeAttribute(rssLink.title)}" href="${rssLink.url}" />`
+ }
+
return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.META_TAGS, tagsStr)
}
// ---------------------------------------------------------------------------
- static generateOpenGraphMetaTagsOptions (tags: Tags) {
+ static generateOpenGraphMetaTagsOptions (tags: TagsOptions) {
if (!tags.ogType) return {}
const metaTags = {
@@ -171,7 +180,7 @@ export class TagsHtml {
return metaTags
}
- static generateStandardMetaTagsOptions (tags: Tags) {
+ static generateStandardMetaTagsOptions (tags: TagsOptions) {
return {
name: tags.escapedTitle,
description: tags.escapedTruncatedDescription,
@@ -179,7 +188,7 @@ export class TagsHtml {
}
}
- static generateTwitterCardMetaTagsOptions (tags: Tags) {
+ static generateTwitterCardMetaTagsOptions (tags: TagsOptions) {
if (!tags.twitterCard) return {}
const metaTags = {
@@ -207,7 +216,7 @@ export class TagsHtml {
return metaTags
}
- static generateSchemaTagsOptions (tags: Tags, context: HookContext) {
+ static generateSchemaTagsOptions (tags: TagsOptions, context: HookContext) {
if (!tags.schemaType) return
if (tags.schemaType === 'ProfilePage') {
diff --git a/server/core/lib/html/shared/video-html.ts b/server/core/lib/html/shared/video-html.ts
index d6b35a98c5..07145f2b43 100644
--- a/server/core/lib/html/shared/video-html.ts
+++ b/server/core/lib/html/shared/video-html.ts
@@ -1,4 +1,4 @@
-import { addQueryParams, escapeHTML } from '@peertube/peertube-core-utils'
+import { addQueryParams, escapeHTML, getVideoWatchRSSFeeds } from '@peertube/peertube-core-utils'
import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
import { Memoize } from '@server/helpers/memoize.js'
@@ -10,7 +10,7 @@ import { VideoModel } from '../../../models/video/video.js'
import { MVideo, MVideoThumbnail, MVideoThumbnailBlacklist } from '../../../types/models/index.js'
import { getActivityStreamDuration } from '../../activitypub/activity.js'
import { isVideoInPrivateDirectory } from '../../video-privacy.js'
-import { CommonEmbedHtml } from './common-embed-html.js'
+import { buildEmptyEmbedHTML } from './common.js'
import { PageHtml } from './page-html.js'
import { TagsHtml } from './tags-html.js'
@@ -57,7 +57,7 @@ export class VideoHtml {
const [ html, video ] = await Promise.all([ PageHtml.getEmbedHTML(), videoPromise ])
if (!video || isVideoInPrivateDirectory(video.privacy) || video.VideoBlacklist) {
- return CommonEmbedHtml.buildEmptyEmbedHTML({ html, video })
+ return buildEmptyEmbedHTML({ html, video })
}
return this.buildVideoHTML({
@@ -131,7 +131,9 @@ export class VideoHtml {
ogType,
twitterCard,
- schemaType
+ schemaType,
+
+ rssFeeds: getVideoWatchRSSFeeds(WEBSERVER.URL, CONFIG.INSTANCE.NAME, video)
}, { video })
}