added sorting pages by provided index, fixed overlaping svg
Some checks failed
Release / release (push) Has been cancelled

This commit is contained in:
Kyattsukuro 2025-08-20 15:17:28 +02:00
parent c9c0967bae
commit 1162a6676a
7 changed files with 1810 additions and 5 deletions

1739
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
{
"name": "logseq-plugin-favorite-tree",
"name": "logseq-plugin-favorite-tree-adapting",
"version": "1.1.2",
"main": "dist/index.html",
"logseq": {
"id": "_sethyuan-logseq-favorite-tree",
"id": "_sethyuan-logseq-favorite-tree-adapting",
"icon": "./icon.png"
},
"scripts": {

13
shell.nix Normal file
View File

@ -0,0 +1,13 @@
let
pkgs = import <nixpkgs> {
overlays = [ ];
};
in
pkgs.mkShell {
buildInputs = with pkgs; [
nodejs
];
shellHook = ''
'';
}

View File

@ -11,6 +11,7 @@ export default function FavArrow({
<span
class={cls("kef-ft-fav-arrow", expanded && "kef-ft-fav-arrow-expanded")}
onClick={onToggle}
style={{ marginRight: "0.05rem" }}
>
<svg
version="1.1"

View File

@ -10,6 +10,7 @@ import {
} from "../libs/storage"
import { queryForSubItems } from "../libs/utils"
import FavArrow from "./FavArrow"
import { Fragment } from "preact/compat"
export default function FavList({
items,

View File

@ -86,7 +86,7 @@ export async function queryForSubItems(name: string) {
.concat(dynamic)
.slice(0, logseq.settings?.taggedPageLimit ?? 30)
return result
return (await queryPropertyAndSort(result))
}
export function waitForEl(selector: string, timeout: number) {
@ -204,3 +204,35 @@ function contains(prop: any, val: string) {
const lowerVal = val.toLowerCase()
return prop.some((v) => v.toLowerCase() === lowerVal)
}
export async function queryPropertyAndSort(items: any[]) {
/*
logseq.DB.datascriptQuery(`[:find (pull ?b [*])
:where
[?p :block/original-name "${originalName}"] ; replace with your page name
[?b :block/page ?p]
[?b :block/properties ?prop]
[(get ?prop :index)]]`,).then((res: any) => {
console.log("Index property result:", res)
if (!res || res.length === 0) {
throw new Error(`No index property found for ${originalName}`)
}
hashTable[originalName] = res[0][0].properties.index || -Infinity
}).catch((e) => {
console.log(`Error querying index property:`)
console.error(e)
})
*/
const sortProp = logseq.settings?.sortByProperty ?? "index"
let itemsWithProp = items.filter((item) => item.properties?.[sortProp] != null)
let itemsWithoutProp = items.filter((item) => item.properties?.[sortProp] == null)
itemsWithProp.sort((a: any, b: any) => {
return a.properties[sortProp] - b.properties[sortProp]
})
const sorted_items = [...itemsWithProp, ...itemsWithoutProp]
//console.log("Sorted items by property:", sorted_items)
return sorted_items
}

View File

@ -4,7 +4,7 @@ import { render } from "preact"
import { throttle } from "rambdax"
import FavList from "./comps/FavList"
import { allExpansionKeys, removeExpansionState } from "./libs/storage"
import { hash, queryForSubItems, setLanguage, waitForEl } from "./libs/utils"
import { hash, queryForSubItems, setLanguage, waitForEl, queryPropertyAndSort } from "./libs/utils"
import zhCN from "./translations/zh-CN.json"
const CLEAN_WAIT = 3000
@ -29,6 +29,15 @@ async function main() {
"It controls which property is used to decide a tag's hierarchy.",
),
},
{
key: "sortByProperty",
title: "",
type: "string",
default: "index",
description: t(
"It controls which property is used to sort favorite items.",
),
},
{
key: "filterIcon",
title: "",
@ -94,7 +103,7 @@ async function main() {
await processFavorites(readKeys)
setTimeout(async () => {
const keys = await allExpansionKeys()
const notReadKeys = keys.filter((key) => !readKeys.has(key))
const notReadKeys = keys.filter((key: any) => !readKeys.has(key))
for (const key of notReadKeys) {
await removeExpansionState(key)
}
@ -205,8 +214,18 @@ async function processFavorites(readKeys?: Set<string>) {
const favorites = parent.document.querySelectorAll<HTMLElement>(
`#left-sidebar .favorite-item`,
)
//console.log("Processing favorites...")
//console.log(favorites)
// We do not want, to sort the base level
for (const fav of favorites) {
/*
items: [{displayName: "Eng",
name: "school/eng"
original-name: "School/Eng"
uuid: "68a2f289-0043-4718-be51-7b7687abbc2 }]
*/
const items = await queryForSubItems(fav.dataset.ref!)
//console.log(items)
if (items?.length > 0) {
injectList(fav, items, readKeys)
}