Revert reverse refs (#1224)
* Remove reverse internal refs * Formatting
This commit is contained in:
		
							parent
							
								
									1dcb6461c7
								
							
						
					
					
						commit
						23c51df283
					
				@ -1185,7 +1185,7 @@ export default {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const namePattern = /\B@[\w_]+/gi
 | 
					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) => {
 | 
					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,8 +1245,6 @@ 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)
 | 
				
			||||||
@ -1261,7 +1259,6 @@ 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,7 +23,6 @@ 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 (
 | 
				
			||||||
@ -295,7 +294,7 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, o
 | 
				
			|||||||
          },
 | 
					          },
 | 
				
			||||||
          img: Img
 | 
					          img: Img
 | 
				
			||||||
        }}
 | 
					        }}
 | 
				
			||||||
        remarkPlugins={[gfm, mention, sub, ref]}
 | 
					        remarkPlugins={[gfm, mention, sub]}
 | 
				
			||||||
        rehypePlugins={[rehypeInlineCodeProperty]}
 | 
					        rehypePlugins={[rehypeInlineCodeProperty]}
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        {children}
 | 
					        {children}
 | 
				
			||||||
 | 
				
			|||||||
@ -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]
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user