Skip to content

Commit

Permalink
0.0.18
Browse files Browse the repository at this point in the history
优化 #25: 过滤锚文本用 %
  • Loading branch information
Misuzu2027 committed Nov 16, 2024
1 parent 7f2862d commit 497880d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 27 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "syplugin-backlink-panel",
"author": "Misuzu2027",
"url": "https://github.com/Misuzu2027/syplugin-backlink-panel",
"version": "0.0.17",
"version": "0.0.18",
"minAppVersion": "3.1.4",
"backends": [
"all"
Expand Down
89 changes: 63 additions & 26 deletions src/service/backlink/backlink-data.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
import { sql, getBatchBlockIdIndex, getBacklinkDoc, getBacklink2 } from "@/utils/api";
import { generateGetParentDefBlockArraySql, generateGetBacklinkListItemBlockArraySql, generateGetDefBlockArraySql, generateGetBlockArraySql, generateGetParenListItemtDefBlockArraySql, generateGetHeadlineChildDefBlockArraySql, generateGetBacklinkBlockArraySql, generateGetListItemChildBlockArraySql, generateGetListItemtSubMarkdownArraySql } from "./backlink-sql";
import { IBacklinkFilterPanelData, IBacklinkBlockQueryParams, IBacklinkBlockNode, IBacklinkFilterPanelDataQueryParams, IPanelRenderBacklinkQueryParams, IBacklinkPanelRenderData, ListItemTreeNode } from "@/models/backlink-model";
import { containsAllKeywords, countOccurrences, isStrBlank, isStrNotBlank, longestCommonSubstring, matchKeywords, splitKeywordStringToArray } from "@/utils/string-util";
import { getBacklink2, getBacklinkDoc, getBatchBlockIdIndex, sql } from "@/utils/api";
import {
generateGetBacklinkBlockArraySql,
generateGetBacklinkListItemBlockArraySql,
generateGetBlockArraySql,
generateGetDefBlockArraySql,
generateGetHeadlineChildDefBlockArraySql,
generateGetListItemChildBlockArraySql,
generateGetListItemtSubMarkdownArraySql,
generateGetParenListItemtDefBlockArraySql,
generateGetParentDefBlockArraySql
} from "./backlink-sql";
import {
IBacklinkBlockNode,
IBacklinkBlockQueryParams,
IBacklinkFilterPanelData,
IBacklinkFilterPanelDataQueryParams,
IBacklinkPanelRenderData,
IPanelRenderBacklinkQueryParams,
ListItemTreeNode
} from "@/models/backlink-model";
import {
containsAllKeywords,
countOccurrences,
isStrBlank,
isStrNotBlank,
longestCommonSubstring,
matchKeywords,
splitKeywordStringToArray
} from "@/utils/string-util";
import { intersectionSet, isArrayEmpty, isArrayNotEmpty, isSetEmpty, isSetNotEmpty, paginate } from "@/utils/array-util";
import { DefinitionBlockStatus } from "@/models/backlink-constant";
import { CacheManager } from "@/config/CacheManager";
import { SettingService } from "../setting/SettingService";
import { Lute } from "siyuan";
import { stringToDom } from "@/utils/html-util";
import { getQueryStrByBlock, NewNodeID } from "@/utils/siyuan-util";





export async function getBacklinkPanelRenderData(
backlinkPanelData: IBacklinkFilterPanelData,
queryParams: IPanelRenderBacklinkQueryParams,
Expand Down Expand Up @@ -457,7 +479,8 @@ async function getBacklinkDocByApiOrCache(
keyword = formatBacklinkDocApiKeyword(keyword);
keyword = "";

let backlinks = CacheManager.ins.getBacklinkDocApiData(rootId, defId, refTreeId, keyword);;
let backlinks = CacheManager.ins.getBacklinkDocApiData(rootId, defId, refTreeId, keyword);
;
let result: IBacklinkCacheData = { backlinks: backlinks, usedCache: false };
if (backlinks) {
result.usedCache = true;
Expand Down Expand Up @@ -637,7 +660,8 @@ export async function getBacklinkPanelData(
let focusBlockId = queryParams.focusBlockId;
let queryCurDocDefBlockRange = queryParams.queryCurDocDefBlockRange;

let cacheResult = CacheManager.ins.getBacklinkPanelBaseData(rootId);;
let cacheResult = CacheManager.ins.getBacklinkPanelBaseData(rootId);
;
if (cacheResult) {
cacheResult.userCache = true;
return cacheResult;
Expand Down Expand Up @@ -676,7 +700,6 @@ export async function getBacklinkPanelData(
}



let defBlockIds = getBlockIds(curDocDefBlockArray);
let backlinkBlockQueryParams: IBacklinkBlockQueryParams = {
queryParentDefBlock: queryParams.queryParentDefBlock,
Expand Down Expand Up @@ -707,7 +730,12 @@ export async function getBacklinkPanelData(


let backlinkPanelData: IBacklinkFilterPanelData = await buildBacklinkPanelData({
rootId, curDocDefBlockArray, backlinkBlockArray, headlinkBacklinkChildBlockArray, listItemBacklinkChildBlockArray, backlinkParentBlockArray,
rootId,
curDocDefBlockArray,
backlinkBlockArray,
headlinkBacklinkChildBlockArray,
listItemBacklinkChildBlockArray,
backlinkParentBlockArray,
});

const endTime = performance.now(); // 记录结束时间
Expand Down Expand Up @@ -811,7 +839,7 @@ async function getListItemChildBlockArray(queryParams: IBacklinkBlockQueryParams
let subMarkdownArray: BacklinkChildBlock[] = await sql(getSubMarkdownSql);
subMarkdownArray = subMarkdownArray ? subMarkdownArray : [];
let subMarkdownMap = new Map<string, string>();
let nameMap = new Map<string,string>();
let nameMap = new Map<string, string>();
for (const parentListItemBlock of subMarkdownArray) {
subMarkdownMap.set(parentListItemBlock.parent_id, parentListItemBlock.subMarkdown);
nameMap.set(parentListItemBlock.parent_id, parentListItemBlock.concatName);
Expand Down Expand Up @@ -1177,9 +1205,6 @@ export function getRefBlockId(markdown: string): string[] {
}





async function backlinkBlockNodeArraySort(
backlinkBlockArray: IBacklinkBlockNode[],
blockSortMethod: BlockSortMethod,
Expand All @@ -1197,7 +1222,11 @@ async function backlinkBlockNodeArraySort(
): number {
let aContent = a.documentBlock.content.replace("<mark>", "").replace("</mark>", "");
let bContent = b.documentBlock.content.replace("<mark>", "").replace("</mark>", "");
let result = aContent.localeCompare(bContent, undefined, { sensitivity: 'base', usage: 'sort', numeric: true });
let result = aContent.localeCompare(bContent, undefined, {
sensitivity: 'base',
usage: 'sort',
numeric: true
});
if (result == 0) {
result = Number(b.block.updated) - Number(a.block.updated);
}
Expand All @@ -1211,7 +1240,11 @@ async function backlinkBlockNodeArraySort(
): number {
let aContent = a.documentBlock.content.replace("<mark>", "").replace("</mark>", "");
let bContent = b.documentBlock.content.replace("<mark>", "").replace("</mark>", "");
let result = bContent.localeCompare(aContent, undefined, { sensitivity: 'base', usage: 'sort', numeric: true });
let result = bContent.localeCompare(aContent, undefined, {
sensitivity: 'base',
usage: 'sort',
numeric: true
});
if (result == 0) {
result = Number(b.block.updated) - Number(a.block.updated);
}
Expand Down Expand Up @@ -1302,7 +1335,6 @@ export async function defBlockArrayTypeAndKeywordFilter(
}



async function searchItemSortByContent(blockArray: DefBlock[]) {
let ids = blockArray.map(item => item.id);
let idMap: Map<string, number> = await getBatchBlockIdIndex(ids);
Expand Down Expand Up @@ -1479,7 +1511,11 @@ function getDefBlockSortFun(contentBlockSortMethod: BlockSortMethod) {

let aContent = a.content.replace("<mark>", "").replace("</mark>", "");
let bContent = b.content.replace("<mark>", "").replace("</mark>", "");
let result = aContent.localeCompare(bContent, undefined, { sensitivity: 'base', usage: 'sort', numeric: true });
let result = aContent.localeCompare(bContent, undefined, {
sensitivity: 'base',
usage: 'sort',
numeric: true
});
if (result == 0) {
result = Number(b.updated) - Number(a.updated);
}
Expand All @@ -1498,7 +1534,11 @@ function getDefBlockSortFun(contentBlockSortMethod: BlockSortMethod) {

let aContent = a.content.replace("<mark>", "").replace("</mark>", "");
let bContent = b.content.replace("<mark>", "").replace("</mark>", "");
let result = bContent.localeCompare(aContent, undefined, { sensitivity: 'base', usage: 'sort', numeric: true });
let result = bContent.localeCompare(aContent, undefined, {
sensitivity: 'base',
usage: 'sort',
numeric: true
});
if (result == 0) {
result = Number(b.updated) - Number(a.updated);
}
Expand Down Expand Up @@ -1572,7 +1612,6 @@ function updateStaticAnchorMap(map: Map<string, Set<string>>, markdown: string)
}



function calculateTotalPages(totalItems: number, itemsPerPage: number): number {
if (itemsPerPage <= 0) {
return 0;
Expand Down Expand Up @@ -1634,10 +1673,8 @@ function parseSearchSyntax(query: string): {

for (const term of terms) {
if (
term.startsWith("!-") ||
term.startsWith("!-") ||
term.startsWith("-!") ||
term.startsWith("-!")
term.startsWith("%-") ||
term.startsWith("-%")
) {
// 以 `!-` 开头的排除锚文本
excludeAnchor.push(term.slice(2));
Expand Down

0 comments on commit 497880d

Please sign in to comment.