Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Pull all lines with "<emoji> :" together, create headers with a "## <emoji>"
// and list the grepped lines after.
// this is the heading the summary will appear under.
// use something uncommon.
var magic_header = "Auto Summary";
var emoji_regex = /(?:- )?(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]).* ?: ?(.*)/g;
var highlights = {};
var content = draft.content;
var match = emoji_regex.exec(content);
var pushNew = function(obj, key, string) {
if (typeof obj[key] === typeof undefined) {
obj[key] = [string];
} else {
obj[key].push(string);
}
}
var automateHighlights = function(highlights) {
var result = "\n\n## " + magic_header + "\n\n";
for (let emoji in highlights) {
if (!emoji.match(/|||/)) {
result = result + "### " + emoji + "\n\n";
for (let index in highlights[emoji]) {
result = result + "- " + highlights[emoji][index] + "\n";
}
result = result + "\n"
}
}
return result;
}
while (match != null) {
pushNew(highlights, match[1], match[2]);
match = emoji_regex.exec(content);
}
if (draft.content.match("## " + magic_header)) {
console.log("already ran!")
}
else {
draft.content = draft.processTemplate("[[title]]")
+ automateHighlights(highlights)
+ draft.processTemplate("[[body]]");
draft.update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment