mirror of
https://github.com/docmost/docmost.git
synced 2026-05-15 13:14:11 +08:00
feat: refactor link menu (#2025)
* link markview - WIP * WIP * feat: refactor links * cleanup
This commit is contained in:
+1
-1
Submodule apps/server/src/ee updated: 52ac3a79de...bc4255a585
@@ -291,6 +291,7 @@ export class ExportService {
|
||||
prosemirrorJson,
|
||||
slugIdToPath,
|
||||
currentPagePath,
|
||||
baseUrl,
|
||||
);
|
||||
|
||||
if (includeAttachments) {
|
||||
|
||||
@@ -62,6 +62,7 @@ export function replaceInternalLinks(
|
||||
prosemirrorJson: any,
|
||||
slugIdToPath: Record<string, string>,
|
||||
currentPagePath: string,
|
||||
baseUrl?: string,
|
||||
) {
|
||||
const doc = jsonToNode(prosemirrorJson);
|
||||
|
||||
@@ -76,6 +77,10 @@ export function replaceInternalLinks(
|
||||
const localPath = slugIdToPath[slugId];
|
||||
|
||||
if (!localPath) {
|
||||
if (baseUrl && mark.attrs.href.startsWith('/')) {
|
||||
//@ts-expect-error
|
||||
mark.attrs.href = `${baseUrl}${mark.attrs.href}`;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user