Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): backlinks read as quick search results

Elian Doranba45a4ff8beb
diff --git a/apps/client/src/widgets/Backlinks.css b/apps/client/src/widgets/Backlinks.css
index 58a9718203..e944dfd289 100644
--- a/apps/client/src/widgets/Backlinks.css
+++ b/apps/client/src/widgets/Backlinks.css
@@ -1,101 +1,102 @@
+/*
+ * The backlinks of a note, as the sidebar's connections tab and the mobile note menu show them —
+ * read as the quick search reads its results (see quick_search.ts and theme-next/shell.css): the note
+ * named on a line of its own, its excerpt quoted in the block below, and the link the excerpt is
+ * about picked out the way a search picks out its match. Both are already framed by what holds them,
+ * a card or a modal, so the items carry no frame of their own.
+ */
.tn-backlinks-widget .backlinks-items {
list-style-type: none;
margin: 0;
padding: 0;
- position: static;
- width: unset;
> li {
- --border-radius: 8px;
-
- max-width: 600px;
- padding: 10px 20px;
- background: var(--card-background-color);
-
- & + li {
- margin-top: 2px;
- }
+ padding-block: 8px;
&:first-child {
- border-radius: var(--border-radius) var(--border-radius) 0 0;
+ padding-top: 0;
}
+ }
- &:last-child {
- border-radius: 0 0 var(--border-radius) var(--border-radius);
- }
-
- /* Card header */
- & > span:first-child {
- display: block;
-
- > span {
- display: flex;
- flex-wrap: wrap;
- align-items: center;
-
- /* Note path */
- > small {
- flex: 100%;
- order: -1;
- font-size: .65rem;
-
- .note-path {
- padding: 0;
- }
+ /* The note the backlink comes from: its ancestors above it, as the quick search sets its path.
+ The link builder nests the parts in a span of its own (see createLink in services/link.ts). */
+ .backlink-header {
+ display: block;
+
+ > span {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+
+ /* The path comes after the note in the markup, and reads before it. */
+ > small {
+ flex: 100%;
+ order: -1;
+ opacity: .5;
+ font-size: .75em;
+
+ .note-path {
+ padding: 0;
}
+ }
- /* Note icon */
- > .tn-icon {
- color: var(--menu-item-icon-color);
- }
+ > .tn-icon {
+ color: var(--menu-item-icon-color);
+ }
- /* Note title */
- > a {
- margin-inline-start: 4px;
- color: currentColor;
- font-weight: 500;
- }
+ > a {
+ margin-inline-start: 4px;
+ color: currentColor;
+ font-weight: 500;
}
}
+ }
- /* Card content - excerpt */
- .backlink-excerpt {
- all: unset; /* TODO: Remove after disposing the old style from FloatingButtons.css */
- display: block;
-
- margin: 8px 0;
- border-radius: 4px;
- background: var(--quick-search-result-content-background);
- padding: 8px;
- font-size: .75rem;
+ /* What the note says around the link, in the block the search snippets are set in. */
+ .backlink-excerpt {
+ margin-top: 8px;
+ border-radius: 4px;
+ /* The colour the theme gives a search snippet, falling back — as the quick search does — to
+ what every theme defines, since only theme-next names one of its own. */
+ background: var(--quick-search-result-content-background, var(--accented-background-color));
+ padding: 8px;
+ font-size: .85em;
+
+ p {
+ margin: 0;
+ }
- a {
- background: transparent;
- color: var(--quick-search-result-highlight-color);
- text-decoration: underline;
- }
+ /* An excerpt is a slice of a note, headings and all, and a heading is sized for a page it
+ titles — in `rem` at that (Bootstrap's), so it ignores the size of the excerpt around it
+ entirely. Brought back to that size, with a step between the levels and the weight the
+ theme takes off a page's headings, so they still read as headings at nearly the text's size. */
+ h1, h2, h3, h4, h5, h6 {
+ margin: .4em 0 .15em;
+ font-weight: 600;
- p {
- margin: 0;
+ &:first-child {
+ margin-top: 0;
}
+ }
- /* An excerpt is a slice of a note, headings and all, and a heading is sized for a page it
- titles — in `rem` at that (Bootstrap's), so it ignores the size of the excerpt around it
- entirely. Brought back to that size, with a step between the levels and the weight the
- theme takes off a page's headings, so they still read as headings at nearly the text's size. */
- h1, h2, h3, h4, h5, h6 {
- margin: .4em 0 .15em;
- font-weight: 600;
-
- &:first-child {
- margin-top: 0;
- }
- }
+ h1 { font-size: 1.15em; }
+ h2 { font-size: 1.1em; }
+ h3 { font-size: 1.05em; }
+ h4, h5, h6 { font-size: 1em; }
- h1 { font-size: 1.15em; }
- h2 { font-size: 1.1em; }
- h3 { font-size: 1.05em; }
- h4, h5, h6 { font-size: 1em; }
+ /* Only the link the excerpt is quoted for is picked out — the others are links like any
+ other in a note, and colouring them all says nothing about which one is the backlink. */
+ .backlink-link {
+ color: var(--quick-search-result-highlight-color, var(--admonition-warning-accent-color));
+ font-weight: 600;
}
}
+
+ /* A backlink that is a relation rather than a link in the text names the relation instead, as
+ quietly as the quick search names the attributes it matched. */
+ .backlink-relation {
+ margin: 4px 0 0;
+ opacity: .5;
+ font-size: .85em;
+ }
}
diff --git a/apps/client/src/widgets/FloatingButtons.css b/apps/client/src/widgets/FloatingButtons.css
index b61df46daf..15c63814af 100644
--- a/apps/client/src/widgets/FloatingButtons.css
+++ b/apps/client/src/widgets/FloatingButtons.css
@@ -116,47 +116,51 @@
/* #endregion */
/* #region Backlinks */
+/* The floating button's popup, and its alone: the list within it is the same markup the sidebar's
+ backlinks and the mobile modal show (see Backlinks.css), which frame it their own way — so nothing
+ here is left loose to reach them. */
.backlinks-widget {
position: relative;
-}
-
-.backlinks-ticker {
- border-radius: 10px;
- border-color: var(--main-border-color);
- background-color: var(--more-accented-background-color);
- padding: 4px 10px 4px 10px;
- opacity: 90%;
- display: flex;
- justify-content: space-between;
- align-items: center;
-}
-
-.backlinks-count {
- cursor: pointer;
-}
-
-.backlinks-items {
- z-index: 10;
- position: absolute;
- top: 50px;
- inset-inline-end: 10px;
- width: 400px;
- border-radius: 10px;
- background-color: var(--accented-background-color);
- color: var(--main-text-color);
- padding: 20px;
- overflow-y: auto;
-}
-
-.backlink-excerpt {
- border-inline-start: 2px solid var(--main-border-color);
- padding-inline-start: 10px;
- opacity: 80%;
- font-size: 90%;
-}
-.backlink-excerpt .backlink-link { /* the actual backlink */
- font-weight: bold;
- background-color: yellow;
+ .backlinks-ticker {
+ border-radius: 10px;
+ border-color: var(--main-border-color);
+ background-color: var(--more-accented-background-color);
+ padding: 4px 10px 4px 10px;
+ opacity: 90%;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
+ .backlinks-count {
+ cursor: pointer;
+ }
+
+ .backlinks-items {
+ z-index: 10;
+ position: absolute;
+ top: 50px;
+ inset-inline-end: 10px;
+ width: 400px;
+ border-radius: 10px;
+ background-color: var(--accented-background-color);
+ color: var(--main-text-color);
+ padding: 20px;
+ overflow-y: auto;
+ }
+
+ .backlink-excerpt {
+ border-inline-start: 2px solid var(--main-border-color);
+ padding-inline-start: 10px;
+ opacity: 80%;
+ font-size: 90%;
+
+ /* The link the excerpt is quoted for. */
+ .backlink-link {
+ font-weight: bold;
+ background-color: yellow;
+ }
+ }
}
/* #endregion */
diff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
index 4db4859a37..899c30392d 100644
--- a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
+++ b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
@@ -436,19 +436,24 @@ export function BacklinksList({ note }: { note: FNote }) {
if (needsRefresh(note, loadResults)) refresh();
});
- return backlinks.map(backlink => (
- <li>
+ // Keyed by position: one source note takes a row per relation it points with, so a note ID names
+ // no single row, and the whole list is rebuilt at once anyway.
+ return backlinks.map((backlink, index) => (
+ <li key={index}>
+ {/* Named so that the styling has something to hang off other than the position of the
+ link within the item (see Backlinks.css). */}
<NoteLink
notePath={backlink.noteId}
+ containerClassName="backlink-header"
showNotePath showNoteIcon
noPreview
/>
{"relationName" in backlink ? (
- <p>{backlink.relationName}</p>
+ <p className="backlink-relation">{backlink.relationName}</p>
) : (
- backlink.excerpts.map(excerpt => (
- <RawHtml html={excerpt} />
+ backlink.excerpts.map((excerpt, excerptIndex) => (
+ <RawHtml key={excerptIndex} html={excerpt} />
))
)}
</li>