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

Import improvements #82

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

iLiftALot
Copy link

@iLiftALot iLiftALot commented Oct 1, 2024

I had come back to this plugin after a long break of not using it and was pleased to see it had improved. However, I could not get the web-clips to import without using commands directly within the command pallet.

Advanced Clips

I started by fixing a lot of asynchronous functions that were being called without being awaited, potentially messing with the flow of execution. I also changed some of the structure.

Additionally, I added in some extra variables which can be extracted from the constructed link.

These updates are especially convenient for those who do not use daily notes or periodic notes. It now allows me to simply click the button and import the data to my specified "Advanced" setting directory, always within the file which is named after the base URL of the specified website.

Highlights

I also could not get highlights to be included with any web clips. This feature indirectly smoothed out and works well with the advanced imports.

Conclusion

You'll see I also adjusted the structure of the imported data; that was also working very finicky. Everything formats quite nicely in my opinion with my updates, but that's personal preference.

I am now successfully importing data very quickly on both Safari and Chrome on MacOS by simply dragging the bookmark link (from the plugin "Browser" settings tab) over to the Chrome/Safari bookmark area. No special installation is required for Chrome on my end.

Let me know if you have any questions.

Thanks for making this plugin!

@iLiftALot
Copy link
Author

iLiftALot commented Oct 6, 2024

Change Log

Table of Contents

Documentation

  • Code notation has been added to the code
  • Will most likely continue to do so throughout today to increase readability

Readability

  • Multiple changes to the overall structure, but nothing too dramatic
  • Added notation for reference
  • Switched up the flow of some files
  • Broke up various parts of the package code into smaller pieces to improve the readability (I hope)
  • Improved some variable namespaces for more clarity regarding their purpose

Environment/Dependencies

I added the following two development-dependent packages:

  1. obsidian-dev-utils
  2. obsidian-typings

They're very useful packages for development within Obsidian, but definitely not a deal breaker if you don't want to use them.

In the event you'd like to make a merge, let me know if you'd like them taken out.

Additions

  • New parameters

Features

  • Auto-detection for the Admonitions plugin and subsequent integration for formatting (accounts for not having it as well)
  • Added parameters to the constructed url
    • Comment
    • Description
    • Base URI

File-Specific Changes & Optimizations

advancednoteentry.ts

  1. Added getCurrentDateTime
  • Retrieves the current date and time for referencing during formatting
  1. Added getHighlightFormat
  • Determines whether to use regular quote blocks or Admonition code blocks when formatting the highlights
  • Ensures proper folding and organization despite differing headings from the target Obsidian File
  1. Added getFile
  • Obtains or creates the TFile object, otherwise throws an error
  1. Added getReferenceData
  • Does the dirty work for formatting the reference information on import
  • Obtains the proper footnote index as well as coordinates the proper headings
    • E.g., each new day, a new H2 heading should be inserted, then every heading throughout that day will be timestamped H3 headings
  1. Added getEntryWithIndex
  • Acts as the main caller to gather the entry data in final format
  1. Drastically shortened writeToAdvancedNoteStorage to enhance readability
  • I broke this function up quite a bit into the previously mentioned helper functions

index.ts

  1. Greatly reduced the length of code by iterating the heading settings

headingSettings Object Iteration

Object.entries(headingSettings).forEach(([heading, prefix]) => {
		const level = heading.slice(1); // Extract the number from 'h1', 'h2', etc.
		const filter = [`h${level}`] as (keyof HTMLElementTagNameMap)[];
	
		markdownService.addRule(`heading_${level}_update`, {
			filter: filter,
			replacement: function (content: string) {
				return `${prefix} ${content}`;
			},
		});
	});
  1. Added paramters to sendToObsidian and showCommentModal
  • This was done to ensure the highlighted content was being passed
  • Prior to this, the highlighted content would be lost if you attempted to submit comments from the web-clip
  1. Added comment, baseURI, and description parameters to the obsidian-clipper URL within sendToObsidian

Defining Description Parameter

// Attempt to extract description from tag which contains page description on many websites
// Worked for me almost every time, but not 100% 
const description = document.querySelector('meta[name="description"]')?.getAttribute('content') ?? '';
  • This has been working very well for me so far and I'm sure I can implement some more logic to account for the off times where it doesn't

main.ts

  1. Added hasAdmonitions helper function to the global scope
  • This functions helps in create this.hasAdmonitions (within the main ObsidianClipperPlugin class), which is later referenced in advancednoteentry.ts for format determination
  • It utilizes the previously mentioned Obsidian developer packages to simply detect the user's current enabled plugins to determine if Admonitions is configured
  1. Added a constructor to the ObsidianClipperPlugin
  • I was mostly using this for testing/debugging purposes
  • Again, the Obsidian developer packages mentioned prior assist me with retrieval of this plugin's manifest in order to avoid making it a requirement to pass when calling the constructor
  • I believe this is the last instance where those packages are used
  1. Switched the flow of execution/conditional statement logic
  • Just made the logic flow and made sure that:
    1. The advanced note insertion would always occur if enabled
    2. All other options (this.settings.useWeeklyNote, this.settings.useDailyNote, CanvasEntry, and TopicNoteEntry) were logically checked to ensure an error-free and efficient execution


Further updates will be added if necessary, but I should be done today.

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.

1 participant