Revert reverse refs (#1224)

* Remove reverse internal refs

* Formatting
This commit is contained in:
ekzyis 2024-06-05 08:21:01 -05:00 committed by GitHub
parent 1dcb6461c7
commit 23c51df283
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 2 additions and 32 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]
}
}
}