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

how to open url with templater #47

Open
johnsonsuqs opened this issue Feb 28, 2022 · 11 comments
Open

how to open url with templater #47

johnsonsuqs opened this issue Feb 28, 2022 · 11 comments

Comments

@johnsonsuqs
Copy link

when the file in url is no, the lumberjack of plugin can create new file with templater, ,but advance url only creat a new file without templater , i think your plugin is much better than it maybe I was not be able to find the function, Could you tell how to set it,thanks

@Vinzent03
Copy link
Owner

How does your tried uri look like? How should a template get inserted? Inserts Templater templates on file creation or is that a feature of lumberjack plugin?

@johnsonsuqs
Copy link
Author

thank for your reply.
I have enable folder templaters in templater plugin and bind template and folder ,if the file is noexistence in this folder, I create a new file in obsidian ,the new file will be created with the template I had bond in templater plugin. I find when I append word in the file by url that is noexitense. the url will create a new file. but lumberjack could create the file with template i have bond ,but advance url create the file without template ,so i hope advance url also create a new file with templater........

@Archie-2021
Copy link

I just found out about this issue by trying to use templater with this plugin. And the problem is not just templater per se but because of using % character in the uri. I think it is escape character and after getting encoded it causes an invalid uri.

I am trying to modifythis js bookmarklet to customize it. This one is using the base uri command and don't have any issue with it,

my code is here, if you test it yourself you can see only if you select text that contains % in it it fails to work.

javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), import('https://unpkg.com/@tehshrike/[email protected]'), ]).then(async ([{
    default: Turndown
}, {
    default: Readability
}]) => {

  /* Optional vault name */
  const vault = "vault 01";

  /* Optional folder name such as "Clippings/" */
  const folder = "";
  const fileName = "test";
  const heading = "Done";

  /* Mode? */
  
  const mode = "append";

  /* Optional tags  */
  const tags = "#clippings";

  function getSelectionHtml() {
    var html = "";
    if (typeof window.getSelection != "undefined") {
        var sel = window.getSelection();
        if (sel.rangeCount) {
            var container = document.createElement("div");
            for (var i = 0, len = sel.rangeCount; i < len; ++i) {
                container.appendChild(sel.getRangeAt(i).cloneContents());
            }
            html = container.innerHTML;
        }
    } else if (typeof document.selection != "undefined") {
        if (document.selection.type == "Text") {
            html = document.selection.createRange().htmlText;
        }
    }
    return html;
  }

  const selection = getSelectionHtml();

  const {
      title,
      byline,
      content
  } = new Readability(document.cloneNode(true)).parse();



// 📝 
//  const fileName = getFileName(title);

  if (selection) {
      var markdownify = selection;
  } else {
      var markdownify = content;
  }

  if (vault) {
      var vaultName = '&vault=' + encodeURIComponent(`${vault}`);
  } else {
      var vaultName = '';
  }

  const markdownBody = new Turndown({
      headingStyle: 'atx',
      hr: '---',
      bulletListMarker: '-',
      codeBlockStyle: 'fenced',
      emDelimiter: '*',
  }).turndown(markdownify);



  const fileContent = 
      "\n- [x] "
	  + "**link:** [" + title + "](" + document.URL + ")"
	  + "**Body:** " + markdownBody;


  if (vault) {
      var vaultName = '&vault=' + encodeURIComponent(`${vault}`);
  } else {
      var vaultName = '';
  }
 const outputVar =  
    "obsidian://advanced-uri?vault=" + vaultName
    + "&filepath=" + encodeURIComponent(folder + fileName)
    + "&heading=" + encodeURIComponent(heading)	
    + "&data=" + encodeURIComponent(fileContent)
	+ "&mode=" + mode;
	
	document.location.href = outputVar;

//	copyToClipboard(outputVar);

})

Thanks

@Vinzent03
Copy link
Owner

@Archie-2021 What exactly are you trying to do? Do you want to create a file with this as content?

@Archie-2021
Copy link

@Archie-2021 What exactly are you trying to do? Do you want to create a file with this as content?

i was trying to use this script in browser to create a file with the content of variable filecontent in this code, the issue is that anything string with certain characters if get encoded and passed to this plugin is not going to work,

@Vinzent03
Copy link
Owner

Could you try encoding it twice using encoder like https://www.urlencoder.io/ So that % gets to ...&data=%2525...

@Archie-2021
Copy link

Could you try encoding it twice using encoder like https://www.urlencoder.io/ So that % gets to ...&data=%2525...

It has been a long time and I forgot the details, but I found out there was also some similar issue with core obsidian uri too (altho I got some issue with this one which core had no issue). I don't think anything getting double encoded in the code above as you can see. For now I am by passing the actual website content/ actual text by sending that via clipboard and just using uri for creating the note and formatting, solving my issue temporarily. But I think there is a lot of more debugging needed both for the core uri and this plugin.

Thank you

@Archie-2021
Copy link

Could you try encoding it twice using encoder like https://www.urlencoder.io/ So that % gets to ...&data=%2525...

Ok I had to modify my scripts so I tried it again. There is no way to send <% %> with this plugin, the core obsidian uri can send the same text that doesn't work with this plugin. Whatever happening with encoding % sign should mess with that too. Now I can't use core uri because I have to append to section and it only possible in this plugin...

@Archie-2021
Copy link

sorry to repeating myself, but any update on this issue? i kinda need this feature in my workflow. it is a huge improvment in automation, opens a lot of possibilities. if only this plugin can handle sending %

@Vinzent03
Copy link
Owner

I have no problems appending <% %> using obsidian://advanced-uri?vault=Test&filepath=Test.md&data=%253C%2525%2520%2525%253E&mode=append as a link on Android.

@Archie-2021
Copy link

Archie-2021 commented Jul 11, 2022

I have no problems appending <% %> using obsidian://advanced-uri?vault=Test&filepath=Test.md&data=%253C%2525%2520%2525%253E&mode=append as a link on Android.

i am on windows not android. my script is a modified version of this script (Obsidian Web Clipper Bookmarklet with full Markdown support for images, headings, and code blocks - Share & showcase - Obsidian Forum) which uses Core ObsidianURI). i can send you the script to kindly test it on your end. all the variables are on the top

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

No branches or pull requests

3 participants