-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: batch creation of notes from line separated url list #155
base: master
Are you sure you want to change the base?
feat: batch creation of notes from line separated url list #155
Conversation
efd8149
to
bda438a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, but it'll need some adjustments. First of all, this approach brings unnecessary ambiguity to function processClipboard
.
More cleaner solution is to create new command, with new handling function, for batch creation and possibly new setting for delimiter. New line character as default and comma or semicolon as additional supported delimiters.
src/helpers/fileutils.ts
Outdated
@@ -2,6 +2,10 @@ import path from 'path'; | |||
import { normalizePath } from 'obsidian'; | |||
|
|||
export function isValidUrl(url: string): boolean { | |||
url = url.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Input should be sanitized at entry point, not in the function.
.split('\n') | ||
.filter((line) => line.trim().length > 0); | ||
const everyLineIsURL = cleanData.reduce((status: boolean, url: string): boolean => { | ||
return status && url.substring(0, 4) == 'http'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to extend isValidUrl
helper function with optional argument - array of accepted protocol schemas from new string enum.
Description
Motivation and Context
Batch creation of notes from url list. Provide a list of urls where every line is a valid url like below. Each url will be treated individually. So 2 notes will be created
How has this been tested?
manual testing in obsidian with a local build of the addon.
Test data
Valid data for batch processing
Invalid data
Non batch behaviour
batch behaviour
valid data
end up in two individual notesinvalid data
will result in snippet note againTypes of changes
Changes visible to users:
Internal changes:
isValidUrl
fromfileutils.ts
inParser.ts
to eliminate code duplicationisValidUrl
gave false positives for multi line input egsome-string\nhttps://www.youtube.com/watch?v=uLMD_u41GlA
. Fixed that by trimming the string and returning false immediately if there are still line breaks in the string.Checklist
npm run lint
.