Handle /notes/ url too

This commit is contained in:
Lim Chee Aun 2023-04-03 10:05:57 +08:00
parent 3b100ad30f
commit 04b4101e55

View file

@ -955,14 +955,19 @@ function SubComments({
); );
} }
const statusRegex = /\/@([^@\/]+)@?([^\/]+)?\/([^\/]+)\/?$/i;
const statusNoteRegex = /\/notes\/([^\/]+)\/?$/i;
function getInstanceStatusURL(url) { function getInstanceStatusURL(url) {
// Regex /:username/:id, where username = @username or @username@domain, id = anything // Regex /:username/:id, where username = @username or @username@domain, id = anything
const statusRegex = /\/@([^@\/]+)@?([^\/]+)?\/([^\/]+)\/?$/i;
const { hostname, pathname } = new URL(url); const { hostname, pathname } = new URL(url);
const [, username, domain, id] = pathname.match(statusRegex) || []; const [, username, domain, id] = pathname.match(statusRegex) || [];
if (id) { if (id) {
return `/${hostname}/s/${id}`; return `/${hostname}/s/${id}`;
} }
const [, noteId] = pathname.match(statusNoteRegex) || [];
if (noteId) {
return `/${hostname}/s/${noteId}`;
}
} }
export default StatusPage; export default StatusPage;