Compare commits

..

2 Commits

Author SHA1 Message Date
ekzyis
79ed07ae74
Embed youtube shorts (#1225) 2024-06-05 09:08:27 -05:00
ekzyis
23c51df283
Revert reverse refs (#1224)
* Remove reverse internal refs

* Formatting
2024-06-05 08:21:01 -05:00
4 changed files with 19 additions and 39 deletions

View File

@ -1185,7 +1185,7 @@ export default {
}
const namePattern = /\B@[\w_]+/gi
const refPattern = new RegExp(`(#\\d+|${process.env.NEXT_PUBLIC_URL}/items/\\d+.*)`, 'gi')
const refPattern = new RegExp(`${process.env.NEXT_PUBLIC_URL}/items/\\d+.*`, 'gi')
export const createMentions = async (item, models) => {
// if we miss a mention, in the rare circumstance there's some kind of
@ -1245,8 +1245,6 @@ const createUserMentions = async (item, models) => {
const createItemMentions = async (item, models) => {
const refs = item.text.match(refPattern)?.map(m => {
if (m.startsWith('#')) return Number(m.slice(1))
// is not #<id> syntax but full URL
try {
const { itemId, commentId } = parseInternalLinks(m)
return Number(commentId || itemId)
@ -1261,7 +1259,6 @@ const createItemMentions = async (item, models) => {
id: { in: refs },
// Don't create mentions for your own items
userId: { not: item.userId }
}
})

View File

@ -23,7 +23,6 @@ import { UNKNOWN_LINK_REL } from '@/lib/constants'
import isEqual from 'lodash/isEqual'
import UserPopover from './user-popover'
import ItemPopover from './item-popover'
import ref from '@/lib/remark-ref2link'
export function SearchText ({ text }) {
return (
@ -295,7 +294,7 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, o
},
img: Img
}}
remarkPlugins={[gfm, mention, sub, ref]}
remarkPlugins={[gfm, mention, sub]}
rehypePlugins={[rehypeInlineCodeProperty]}
>
{children}

View File

@ -1,26 +0,0 @@
import { findAndReplace } from 'mdast-util-find-and-replace'
const refRegex = /#(\d+(\/(edit|related|ots))?)/gi
export default function ref (options) {
return function transformer (tree) {
findAndReplace(
tree,
[
[refRegex, replaceRef]
],
{ ignore: ['link', 'linkReference'] }
)
}
function replaceRef (value, itemId, match) {
const node = { type: 'text', value }
return {
type: 'link',
title: null,
url: `/items/${itemId}`,
children: [node]
}
}
}

View File

@ -79,13 +79,23 @@ export function parseEmbedUrl (href) {
try {
const { hostname, pathname, searchParams } = new URL(href)
if (hostname.endsWith('youtube.com') && pathname.includes('/watch')) {
return {
provider: 'youtube',
id: searchParams.get('v'),
meta: {
href,
start: searchParams.get('t')
if (hostname.endsWith('youtube.com')) {
if (pathname.includes('/watch')) {
return {
provider: 'youtube',
id: searchParams.get('v'),
meta: {
href,
start: searchParams.get('t')
}
}
}
if (pathname.includes('/shorts')) {
const id = pathname.split('/').slice(-1).join()
return {
provider: 'youtube',
id
}
}
}