Suggested improvement to the "Group by annotation color, customized label" cheat sheet #178
FeralFlora
started this conversation in
Ideas
Replies: 2 comments
-
I have tested this, and it works. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here is the updated template: <% const byColor = Object.groupBy(it, (annot) => annot.colorName);
const label = {
"red": "Important",
"orange": "Question",
"yellow": "Summary",
"gray": "Comment",
"green": "Answer",
"cyan": "Task",
"blue": "Fact",
"navy": "Definition",
"purple": "Quote",
"brown": "Source",
"magenta": "To Do",
};
// Merge colors with customized label with unexpected colors, if any
// Keep the order of the colors from the original color-label map
const colorSet = new Set([...Object.keys(label), ...Object.keys(byColor)]);
for (const color of colorSet) {
if (!(color in byColor)) continue -%>
### <%= label[color] ?? color %>
<%_ for (const annot of byColor[color]) { %>
<%~ include("annotation", annot) %>
<%_ } %>
<% } %> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I suggest changing the for-loop that outputs the headings and associated annotations from this:
to this:
I loop over the colors in
label
rather thanbyColor
, and add a conditional so that colors inbyColor
are output if they are present in label. This way, the color group headings will be output in the same order as set in label. This ensures that literature notes are consistently formatted. Without this, the groups will be in the sequence of colors in the source document, so it will not be consistent.There might need to be some else statement to catch colors that are not in
label
.Beta Was this translation helpful? Give feedback.
All reactions