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

Add option to create new note and automatically link it in daily note #52

Open
sundarvisweswaran opened this issue Sep 20, 2024 · 2 comments

Comments

@sundarvisweswaran
Copy link

Current Behavior:

Currently, when using Quick Add to clip content, users have three options:
Add to Daily note
Add to Existing Note
Create new note

Desired Behavior:
Add a fourth option: 4. Create new note and add link in daily note

This new option would:

Create a new note with the clipped content
Automatically add a link to this newly created note in the current daily note

Use Case:
This feature would streamline the workflow for users who want to create separate notes for clipped content and maintain a record of when they clipped that content in their daily notes through backlinks. It combines the benefits of creating a new note with the organizational advantage of linking it to a daily note.

@writtenfool
Copy link

I did this to the template in the extension by adding a property called daily_note_date with the value [[{{date|date:YYYY-MM-DD}}]]. It automagically shows up in the linked mentions at the bottom of my daily note.

@kepano kepano added the enhancement New feature or request label Sep 21, 2024
@haykkh
Copy link

haykkh commented Oct 14, 2024

I wrote a templater script to take some content and add it to today’s daily:

// clipToDailyNote.js

/**
  * Finds the daily note for today
  * @param {import("obsidian").TFile} tp - The templater object
  * @returns {Promise<import("obsidian").TFile>} - The daily note for today
  */
const findTodaysFile = async (tp) => {
  const dateString = tp.date.now("YYYY-MM-DD ddd");
  const fileName = `journals/days/${dateString}.md`;
  const fileExists = await tp.file.exists(fileName);

  if (fileExists) {
    return tp.file.find_tfile(fileName);
  }
};

/**
 * Adds content to a tfile
 * @param {TFile} file - The tfile to add content to
 * @param {string} content - The content to add to the tfile
 */
const addContentToTFile = async (file, content) => {
  file.vault.append(file, content);
};

/**
 * Adds content to the daily note for today
 * @param {import("obsidian").TFile} tp - The templater object
 * @param {string} content - The content to add to the daily note
 */
const clipToDailyNote = async (tp, content) => {
  const tFile = await findTodaysFile(tp);
  if (tFile) {
    addContentToTFile(tFile, content);
  }
};

module.exports = clipToDailyNote;

Setting up Templater in obsidian settings:

  • Enable Trigger Templater on new file creation
  • Set up User script functions
    • You should be able to see your exported clipToDailyNote function above under Detected N User Script(s)

Then use it in your web-clipper template’s Note content:

// clips into your daily:
// - **15:31** [[Cool article on the web]]

<%*
await tp.user.clipToDailyNote(tp, "\n- **" + tp.date.now("HH:mm") + "** [[" + tp.file.title + "]]")
_%>

{{content}}

Screenshot 2024-10-14 at 17 27 06

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

No branches or pull requests

4 participants