feat: refactor link menu (#2025)

* link markview - WIP

* WIP

* feat: refactor links

* cleanup
This commit is contained in:
Philip Okugbe
2026-03-15 17:08:59 +00:00
committed by GitHub
parent 97c459be67
commit 89b94e5d19
21 changed files with 944 additions and 219 deletions
@@ -164,6 +164,12 @@ export class FileImportTaskService {
const attachmentCandidates = await buildAttachmentCandidates(extractDir);
const docmostMetadata = await readDocmostMetadata(extractDir);
const space = await this.db
.selectFrom('spaces')
.select(['slug'])
.where('id', '=', fileTask.spaceId)
.executeTakeFirst();
const pagesMap = new Map<string, ImportPageNode>();
for (const absPath of allFiles) {
@@ -458,6 +464,7 @@ export class FileImportTaskService {
creatorId: fileTask.creatorId,
sourcePageId: page.id,
workspaceId: fileTask.workspaceId,
spaceSlug: space?.slug,
});
const pmState = getProsemirrorContent(
@@ -1,9 +1,10 @@
import { getEmbedUrlAndProvider } from '@docmost/editor-ext';
import { Logger } from '@nestjs/common';
import * as path from 'path';
import { v7 } from 'uuid';
import { InsertableBacklink } from '@docmost/db/types/entity.types';
import { Cheerio, CheerioAPI, load } from 'cheerio';
// eslint-disable-next-line @typescript-eslint/no-require-imports
import slugify = require('@sindresorhus/slugify');
// Check if text contains Unicode characters (for emojis/icons)
function isUnicodeCharacter(text: string): boolean {
@@ -22,6 +23,7 @@ export async function formatImportHtml(opts: {
workspaceId: string;
pageDir?: string;
attachmentCandidates?: string[];
spaceSlug?: string;
}): Promise<{
html: string;
backlinks: InsertableBacklink[];
@@ -61,6 +63,7 @@ export async function formatImportHtml(opts: {
creatorId,
sourcePageId,
workspaceId,
opts.spaceSlug,
);
return {
@@ -316,6 +319,7 @@ export async function rewriteInternalLinksToMentionHtml(
creatorId: string,
sourcePageId: string,
workspaceId: string,
spaceSlug?: string,
): Promise<InsertableBacklink[]> {
const normalize = (p: string) => p.replace(/\\/g, '/');
const backlinks: InsertableBacklink[] = [];
@@ -339,19 +343,16 @@ export async function rewriteInternalLinksToMentionHtml(
);
const meta = filePathToPageMetaMap.get(resolved);
if (!meta) return;
const mentionId = v7();
const $mention = $('<span>')
.attr({
'data-type': 'mention',
'data-id': mentionId,
'data-entity-type': 'page',
'data-entity-id': meta.id,
'data-label': meta.title,
'data-slug-id': meta.slugId,
'data-creator-id': creatorId,
})
.text(meta.title);
$a.replaceWith($mention);
const titleSlug = slugify(meta.title?.substring(0, 70) || 'untitled');
const pageSlug = `${titleSlug}-${meta.slugId}`;
const internalHref = spaceSlug
? `/s/${spaceSlug}/p/${pageSlug}`
: `/p/${pageSlug}`;
$a.attr('href', internalHref);
$a.attr('data-internal', 'true');
backlinks.push({ sourcePageId, targetPageId: meta.id, workspaceId });
});