Skip to content

Instantly share code, notes, and snippets.

@evantravers
Created October 22, 2019 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evantravers/40ffcd1597dcaa4d06bbb208cd5c2b68 to your computer and use it in GitHub Desktop.
Save evantravers/40ffcd1597dcaa4d06bbb208cd5c2b68 to your computer and use it in GitHub Desktop.
// 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