Compare commits
No commits in common. "79ed07ae741ae0dcaa309cd85930a4626a513ab2" and "1dcb6461c77bc0e5a9f680f78d48850dcaf41afc" have entirely different histories.
79ed07ae74
...
1dcb6461c7
@ -1185,7 +1185,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const namePattern = /\B@[\w_]+/gi
|
const namePattern = /\B@[\w_]+/gi
|
||||||
const refPattern = new RegExp(`${process.env.NEXT_PUBLIC_URL}/items/\\d+.*`, 'gi')
|
const refPattern = new RegExp(`(#\\d+|${process.env.NEXT_PUBLIC_URL}/items/\\d+.*)`, 'gi')
|
||||||
|
|
||||||
export const createMentions = async (item, models) => {
|
export const createMentions = async (item, models) => {
|
||||||
// if we miss a mention, in the rare circumstance there's some kind of
|
// if we miss a mention, in the rare circumstance there's some kind of
|
||||||
@ -1245,6 +1245,8 @@ const createUserMentions = async (item, models) => {
|
|||||||
|
|
||||||
const createItemMentions = async (item, models) => {
|
const createItemMentions = async (item, models) => {
|
||||||
const refs = item.text.match(refPattern)?.map(m => {
|
const refs = item.text.match(refPattern)?.map(m => {
|
||||||
|
if (m.startsWith('#')) return Number(m.slice(1))
|
||||||
|
// is not #<id> syntax but full URL
|
||||||
try {
|
try {
|
||||||
const { itemId, commentId } = parseInternalLinks(m)
|
const { itemId, commentId } = parseInternalLinks(m)
|
||||||
return Number(commentId || itemId)
|
return Number(commentId || itemId)
|
||||||
@ -1259,6 +1261,7 @@ const createItemMentions = async (item, models) => {
|
|||||||
id: { in: refs },
|
id: { in: refs },
|
||||||
// Don't create mentions for your own items
|
// Don't create mentions for your own items
|
||||||
userId: { not: item.userId }
|
userId: { not: item.userId }
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import { UNKNOWN_LINK_REL } from '@/lib/constants'
|
|||||||
import isEqual from 'lodash/isEqual'
|
import isEqual from 'lodash/isEqual'
|
||||||
import UserPopover from './user-popover'
|
import UserPopover from './user-popover'
|
||||||
import ItemPopover from './item-popover'
|
import ItemPopover from './item-popover'
|
||||||
|
import ref from '@/lib/remark-ref2link'
|
||||||
|
|
||||||
export function SearchText ({ text }) {
|
export function SearchText ({ text }) {
|
||||||
return (
|
return (
|
||||||
@ -294,7 +295,7 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, o
|
|||||||
},
|
},
|
||||||
img: Img
|
img: Img
|
||||||
}}
|
}}
|
||||||
remarkPlugins={[gfm, mention, sub]}
|
remarkPlugins={[gfm, mention, sub, ref]}
|
||||||
rehypePlugins={[rehypeInlineCodeProperty]}
|
rehypePlugins={[rehypeInlineCodeProperty]}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
26
lib/remark-ref2link.js
Normal file
26
lib/remark-ref2link.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
lib/url.js
24
lib/url.js
@ -79,23 +79,13 @@ export function parseEmbedUrl (href) {
|
|||||||
try {
|
try {
|
||||||
const { hostname, pathname, searchParams } = new URL(href)
|
const { hostname, pathname, searchParams } = new URL(href)
|
||||||
|
|
||||||
if (hostname.endsWith('youtube.com')) {
|
if (hostname.endsWith('youtube.com') && pathname.includes('/watch')) {
|
||||||
if (pathname.includes('/watch')) {
|
return {
|
||||||
return {
|
provider: 'youtube',
|
||||||
provider: 'youtube',
|
id: searchParams.get('v'),
|
||||||
id: searchParams.get('v'),
|
meta: {
|
||||||
meta: {
|
href,
|
||||||
href,
|
start: searchParams.get('t')
|
||||||
start: searchParams.get('t')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pathname.includes('/shorts')) {
|
|
||||||
const id = pathname.split('/').slice(-1).join()
|
|
||||||
return {
|
|
||||||
provider: 'youtube',
|
|
||||||
id
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user