summaryrefslogtreecommitdiff
path: root/packages/frontend/src/utility/extract-preview-urls.ts
blob: 264359f1790e17719477d976d1bb0dae8ecdcc4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import type * as Misskey from 'misskey-js';
import type * as mfm from 'mfm-js';
import { extractUrlFromMfm } from '@/utility/extract-url-from-mfm.js';
import { getNoteUrls } from '@/utility/getNoteUrls';

/**
 * Extracts all previewable URLs from a note.
 */
export function extractPreviewUrls(note: Misskey.entities.Note, contents: mfm.MfmNode[]): string[] {
	const links = extractUrlFromMfm(contents);
	if (links.length < 0) return [];

	const self = getNoteUrls(note);
	return links.filter(url => !self.includes(url));
}