Skip to content

Commit

Permalink
Adding notational velocity and renaming nvultra options
Browse files Browse the repository at this point in the history
- BREAKING: Moved the new --nv-add/url options to --nvu-add/url
- NEW: Generate nvALT urls and notes with --nv-url and --nv-add
  • Loading branch information
ttscoff committed Aug 31, 2022
1 parent 716e81c commit b66e1a8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,15 @@ Comments can often be fruitful (and important) to an answer, but they also get m

Lastly, sometimes there's more than one good answer worth saving, but a bunch of zero-vote errors in judgement you don't need in your notes. Use `--min-upvotes X` to filter answers by a minimum number of upvotes. For example, `--min-upvotes 60` would easily weed out the less-desirable answers on an older question. Filtering by upvotes does not affect the accepted answer, if that exists it's included no matter how many upvotes is has (or doesn't have).

#### nvUltra Options

If you're running nvUltra, you can output clipped web pages directly to a notebook.

`--nv-url` will generate a x-nvultra://make url that, when opened, will add the markdown version of the web page as a note, titled with the page title. This flag simply outputs the url (or copies it with `--copy`) and can be used as part of another script that handles the link.

`--nv-add` will immediately open the url and add your note to nvUltra.

You can include a `--nv-notebook PATH` option to specify which notebook the note gets added to. If this is left out, the note will be added to the frontmost open notebook in nvUltra.

[Here's a Shortcut](https://github.com/ttscoff/gather-cli/raw/main/extras/Gather%20to%20nvUltra.shortcut) that accepts text or URLs and runs `gather --nv-add` on them. I trigger it with LaunchBar to send the current page from my browser straight to nvUltra.

62 changes: 43 additions & 19 deletions Sources/gather/gather.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,28 @@ func createNvUltraURL(markdown: String?, title: String?, notebook: String?) -> S
return components.string ?? ""
}

func createNvURL(markdown: String?, title: String?) -> String {
var note_title = ""

if title == nil {
note_title = "\(iso_datetime()) Clipped Note"
} else {
note_title = title!
}

var components = URLComponents()
components.scheme = "nv"
components.host = "make"
components.path = "/"

components.queryItems = [
URLQueryItem(name: "txt", value: markdown),
URLQueryItem(name: "title", value: note_title),
]

return components.string ?? ""
}

func readFromClipboard(html: Bool = false) -> String? {
let pasteboard = NSPasteboard.general
var output: String?
Expand Down Expand Up @@ -325,14 +347,20 @@ struct Gather: ParsableCommand {
// @Option(name: .shortAndLong, help: "Wrap width (0 for no wrap)")
// var wrap: Int = 0

@Flag(help: "Output as an nvUltra URL")
@Flag(help: "Output as an Notational Velocity/nvALT URL")
var nvUrl = false

@Flag(help: "Add output to nvUltra immediately")
@Flag(help: "Add output to Notational Velocity/nvALT immediately")
var nvAdd = false

@Flag(help: "Output as an nvUltra URL")
var nvuUrl = false

@Flag(help: "Add output to nvUltra immediately")
var nvuAdd = false

@Option(help: "Specify an nvUltra notebook for the 'make' URL")
var nvNotebook: String = ""
var nvuNotebook: String = ""

@Flag(name: .shortAndLong, help: "Display current version number")
var version = false
Expand Down Expand Up @@ -418,22 +446,8 @@ struct Gather: ParsableCommand {

if input != nil {
(title, markdown) = markdownify_input(html: input, read: readability)
// if onlyOutputTitle {
// if let title = get_title(html: input, url: nil) {
// output = title.trimmingCharacters(in: .whitespacesAndNewlines)
// }
// } else {
// output = markdownify_input(html: input, read: readability).trimmingCharacters(in: .whitespacesAndNewlines)
// }
} else if url != "" {
(title, markdown) = markdownify(url: url, read: readability)
// if onlyOutputTitle {
// if let title = get_title(html: nil, url: url) {
// output = title.trimmingCharacters(in: .whitespacesAndNewlines)
// }
// } else {
// output = markdownify(url: url, read: readability).trimmingCharacters(in: .whitespacesAndNewlines)
// }
} else {
throw CleanExit.helpRequest()
}
Expand All @@ -445,16 +459,26 @@ struct Gather: ParsableCommand {
}

if output != nil {
if nvUrl || nvAdd {
if nvuUrl || nvuAdd {
output = createNvUltraURL(markdown: markdown, title: title, notebook: nvNotebook)

if nvAdd {
if nvuAdd {
let url = URL(string: output!)!
if NSWorkspace.shared.open(url) {
throw CleanExit.message("Added to nvUltra")
}
throw ValidationError("Error adding to nvUltra")
}
} else if nvUrl || nvAdd {
output = createNvURL(markdown: markdown, title: title)

if nvAdd {
let url = URL(string: output!)!
if NSWorkspace.shared.open(url) {
throw CleanExit.message("Added to NV/nvALT")
}
throw ValidationError("Error adding to NV/nvALT")
}
}

if copy {
Expand Down
Binary file modified buildnotes.md.secret
Binary file not shown.
Binary file modified extras/Gather to nvUltra.shortcut
Binary file not shown.
16 changes: 15 additions & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--GITHUB-->![Howzit banner image](https://cdn3.brettterpstra.com/uploads/2022/08/gatherheader-rb.webp)<!--END GITHUB-->
<!--JEKYLL{% img aligncenter 800 220 /uploads/2022/08/gatherheader-rb.jpg "Howzit banner image" %}-->

Current version: <!--VER-->2.0.27<!--END VER-->
Current version: <!--VER-->2.0.28<!--END VER-->

This project is the successor to read2text, which was a Python based tool that used Arc90 Readability and html2text to convert web URLs to Markdown documents, ready to store in your notes. It takes its name from another of my similar projects that I've since retired. It was this, but with a GUI, and this is infinitely more scriptable and is designed to nestle into your favorite tools and projects.

Expand Down Expand Up @@ -117,5 +117,19 @@ Comments can often be fruitful (and important) to an answer, but they also get m

Lastly, sometimes there's more than one good answer worth saving, but a bunch of zero-vote errors in judgement you don't need in your notes. Use `--min-upvotes X` to filter answers by a minimum number of upvotes. For example, `--min-upvotes 60` would easily weed out the less-desirable answers on an older question. Filtering by upvotes does not affect the accepted answer, if that exists it's included no matter how many upvotes is has (or doesn't have).

#### nvUltra/nvALT Options

If you're running nvUltra, you can output clipped web pages directly to a notebook.

`--nvu-url` will generate a x-nvultra://make url that, when opened, will add the markdown version of the web page as a note, titled with the page title. This flag simply outputs the url (or copies it with `--copy`) and can be used as part of another script that handles the link.

`--nvu-add` will immediately open the url and add your note to nvUltra.

You can include a `--nvu-notebook PATH` option to specify which notebook the note gets added to. If this is left out, the note will be added to the frontmost open notebook in nvUltra.

[Here's a Shortcut](https://github.com/ttscoff/gather-cli/raw/main/extras/Gather%20to%20nvUltra.shortcut) that accepts text or URLs and runs `gather --nv-add` on them. I trigger it with LaunchBar to send the current page from my browser straight to nvUltra.

The `url` and `add` options work with just `--nv` instead of `--nvu` to generate an `nv://` url that will work with Notational Velocity or nvALT.

<!--END README-->

0 comments on commit b66e1a8

Please sign in to comment.