Creating a new excerpt

I've come up with several ways to create a new excerpt. Check them out below.

Creating via nodejs

Here is the flow:

  1. I find and copy an excerpt in Google Chrome
  2. I then run the script below from terminal
  3. The script uses AppleScript to get the title and URL of the active tab in Chrome
  4. The script creates a markdown file with this information and writes it to the filesystem
  5. The new markdown file is opened in vscode
import { writeFile } from "fs/promises";
import { join } from "path";
import { execa } from "execa";
import clipboard from "clipboardy";

const today = new Date().toISOString().slice(0, 16).replace(":", "");

function getChromeScriptFor(type) {
  return `tell application "Google Chrome" to return ${type} of active tab of front window`;
}

const { stdout: title } = await execa("osascript", [
  `-e ${getChromeScriptFor("title")}`,
]);

let md = `---
title: ${title}
tags:
date: ${new Date().toISOString()}
---`;

const quote = await clipboard.read();
if (quote) {
  md += "\n";
  md += `> ${quote}`;
}

const { stdout: url } = await execa("osascript", [
  `-e ${getChromeScriptFor("URL")}`,
]);

if (url) {
  md += ` — ${url}`;
}

const filePath = join(
  process.env.HOME,
  `projects/excerpts/excerpts/${today}.md`
);

await writeFile(filePath, md, "utf-8");

await execa("code", [filePath]);

Creating via a chrome extension

I created a simple chrome extension which grabs the URL, title and selected text from the active tab. It then takes these values and appends them to a github URL for creating a new file.

You can see the code for the extension here.

I plan to write about this more later, maybe.


Creating via a bookmarklet

I had forgotten about bookmarklets until reading a post by Dave Rupert.

I created one below that I can just drag to my bookmarks bar. It does the same thing as the Chrome extension above. The nice thing with the bookmarklet is I should be able to use it in Safari and Firefox if I wanted.

Excerpt

github new excerpt example