1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Support multiple rel="me"

This commit is contained in:
Chocobozzz 2025-03-27 14:15:33 +01:00
parent 5efbbcbeb1
commit c627e6d834
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 14 additions and 9 deletions

View file

@ -238,11 +238,11 @@ describe('Test <head> HTML tags', function () {
}) })
describe('Mastodon link', function () { describe('Mastodon link', function () {
async function check (path: string, mastoLink: string, exist = true) { async function check (path: string, href: string, exist = true) {
const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 })
const text = res.text const text = res.text
const expected = `<link href="${mastoLink}" rel="me">` const expected = `<link href="${href}" rel="me">`
if (exist) expect(text).to.contain(expected) if (exist) expect(text).to.contain(expected)
else expect(text).to.not.contain(expected) else expect(text).to.not.contain(expected)
@ -250,10 +250,12 @@ describe('Test <head> HTML tags', function () {
it('Should correctly include Mastodon link in account', async function () { it('Should correctly include Mastodon link in account', async function () {
await servers[0].users.updateMe({ await servers[0].users.updateMe({
description: 'hi, please <a href="https://social.example.com/@username" rel="me">Follow me on Mastodon!</a>' description: 'hi, please <a href="https://social.example.com/@username" rel="me">Follow me on Mastodon!</a> and ' +
'<a href="https://social.example.com/@username2" rel="me">Follow me on Mastodon 2!</a>'
}) })
await check('/a/root', 'https://social.example.com/@username') await check('/a/root', 'https://social.example.com/@username')
await check('/a/root', 'https://social.example.com/@username2')
}) })
it('Should correctly include Mastodon link in channel', async function () { it('Should correctly include Mastodon link in channel', async function () {

View file

@ -30,7 +30,7 @@ export type TagsOptions = {
escapedTitle?: string escapedTitle?: string
escapedTruncatedDescription?: string escapedTruncatedDescription?: string
relMe?: string relMe?: string[]
image?: { image?: {
url: string url: string
@ -59,7 +59,6 @@ type HookContext = {
} }
export class TagsHtml { export class TagsHtml {
static addTitleTag (htmlStringPage: string, title?: string) { static addTitleTag (htmlStringPage: string, title?: string) {
let text = title || CONFIG.INSTANCE.NAME let text = title || CONFIG.INSTANCE.NAME
if (title) text += ` - ${CONFIG.INSTANCE.NAME}` if (title) text += ` - ${CONFIG.INSTANCE.NAME}`
@ -81,7 +80,7 @@ export class TagsHtml {
const html = parse(content) const html = parse(content)
return html.querySelector('a[rel=me]')?.getAttribute('href') || undefined return html.querySelectorAll('a[rel=me]').map(e => e.getAttribute('href'))
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -118,7 +117,9 @@ export class TagsHtml {
// OEmbed // OEmbed
for (const oembedLinkTag of oembedLinkTags) { for (const oembedLinkTag of oembedLinkTags) {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
tagsStr += `<link rel="alternate" type="${oembedLinkTag.type}" href="${oembedLinkTag.href}" title="${escapeAttribute(oembedLinkTag.escapedTitle)}" />` tagsStr += `<link rel="alternate" type="${oembedLinkTag.type}" href="${oembedLinkTag.href}" title="${
escapeAttribute(oembedLinkTag.escapedTitle)
}" />`
} }
// Schema.org // Schema.org
@ -126,8 +127,10 @@ export class TagsHtml {
tagsStr += `<script type="application/ld+json">${JSON.stringify(schemaTags)}</script>` tagsStr += `<script type="application/ld+json">${JSON.stringify(schemaTags)}</script>`
} }
if (relMe) { if (Array.isArray(relMe)) {
tagsStr += `<link href="${escapeAttribute(relMe)}" rel="me">` for (const relMeLink of relMe) {
tagsStr += `<link href="${escapeAttribute(relMeLink)}" rel="me">`
}
} }
// SEO, use origin URL // SEO, use origin URL