Skip to content

Commit

Permalink
feat(pageicons): hide title prop
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyurec committed Nov 17, 2022
1 parent 70dc5c7 commit 72c6144
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/modules/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type globalContextType = {
export interface propsObject {
icon?: string;
color?: string;
hidetitle?: boolean;
needStroke?: boolean;
}

Expand Down
6 changes: 6 additions & 0 deletions src/modules/pageIcons/pageIcons.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
line-height: 1em;
width: 1.2em;
}
.awLi-hideTitle.awLi-hasIcon {
font-size: 0;
}
.awLi-hideTitle .awLi-icon {
font-size: initial;
}
.title .awLi-icon {
display: inline-block;
width: 1.4em;
Expand Down
8 changes: 8 additions & 0 deletions src/modules/pageIcons/pageIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ const setIconToLinkItem = async (linkItem: HTMLElement, pageProps: propsObject,
} else {
linkItem.insertAdjacentHTML('afterbegin', `<span class="awLi-icon">${pageIcon}</span>`);
}
linkItem.classList.add('awLi-hasIcon');
if (pageProps['hidetitle'] && linkItem.classList.contains('page-ref') || linkItem.classList.contains('tag')) {
linkItem.classList.add('awLi-hideTitle');
} else {
linkItem.classList.remove('awLi-hideTitle');
}
} else {
linkItem.classList.remove('awLi-hasIcon');
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/modules/pageIcons/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getLinkedPagesNumber = async (title: string): Promise<number> => {
:where
[?b :block/page ?page]
[?b :block/refs ?ref-page]
[?ref-page :block/name "logseq"]
[?ref-page :block/name "${title}"]
]
`;
const linkedPages = await logseq.DB.datascriptQuery(linkedQuery);
Expand Down Expand Up @@ -58,6 +58,9 @@ export const getPageProps = async (title: string): Promise<propsObject> => {
if (queryResultArr[0] && queryResultArr[0][0] && queryResultArr[0][0].color) {
pageProps.color = queryResultArr[0][0].color.replaceAll('"', '');
}
if (queryResultArr[0] && queryResultArr[0][0] && queryResultArr[0][0].hidetitle) {
pageProps.hidetitle = queryResultArr[0][0].hidetitle;
}
}
return pageProps;
}
Expand Down

0 comments on commit 72c6144

Please sign in to comment.