Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

clemens-holleis
Copy link

@clemens-holleis clemens-holleis commented Aug 2, 2024

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

https://www.youtube.com/watch?v=uLMD_u41GlA
https://www.tiktok.com/@toontimemadness/video/7346280539004931334

How has this been tested?

manual testing in obsidian with a local build of the addon.

Test data

Valid data for batch processing

https://www.youtube.com/watch?v=uLMD_u41GlA
https://www.tiktok.com/@toontimemadness/video/7346280539004931334


https://www.youtube.com/watch?v=uLMD_u41GlA

https://www.tiktok.com/@toontimemadness/video/7346280539004931334


Invalid data

# some heading to indicate "this is a single note of urls"
https://www.youtube.com/watch?v=uLMD_u41GlA
https://www.tiktok.com/@toontimemadness/video/7346280539004931334
https://www.youtube.com/watch?v=uLMD_u41GlA
other random non-url data

Non batch behaviour

  1. Batch processing disabled
  2. all data sets end up as snippet notes

batch behaviour

  1. Batch processing enabled
  2. valid data end up in two individual notes
  3. invalid data will result in snippet note again

Types of changes

Changes visible to users:

  • New feature Batch processing of URLs (disabled by default in settings)

Internal changes:

  • Refactor re-used isValidUrl from fileutils.ts in Parser.ts to eliminate code duplication
  • fix isValidUrl gave false positives for multi line input eg some-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

  • My code follows the code style of this project and passes npm run lint.
  • My change requires an update of README.md
  • I have updated the README.md

@clemens-holleis clemens-holleis changed the title Feat/batch creation feat: batch creation Aug 2, 2024
@clemens-holleis clemens-holleis marked this pull request as ready for review August 5, 2024 05:27
@clemens-holleis clemens-holleis changed the title feat: batch creation feat: batch creation of notes from line separated url list Aug 5, 2024
@clemens-holleis clemens-holleis marked this pull request as draft August 5, 2024 08:25
@clemens-holleis clemens-holleis marked this pull request as ready for review August 5, 2024 08:26
Copy link
Collaborator

@adamluckdev adamluckdev left a 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.

@@ -2,6 +2,10 @@ import path from 'path';
import { normalizePath } from 'obsidian';

export function isValidUrl(url: string): boolean {
url = url.trim();
Copy link
Collaborator

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';
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants