obsidian-webpage-export icon indicating copy to clipboard operation
obsidian-webpage-export copied to clipboard

Make TOC links relative

Open vgyenge6 opened this issue 1 year ago • 19 comments

if I rename the exported .html file with contained TOC any of the references in the newly renamed file won't work. Perhaps this is also because of this. However, I did not experience this in the earlier version.

vgyenge6 avatar Feb 21 '24 16:02 vgyenge6

@vgyenge6 wait what do you mean when you say you "rename the exported .html file"? If you mean you are actually changing the name of the html after exporting of course this breaks all the links. The links are all based on the name of the file! Instead just rename your markdown file before exporting, or set the title property if you want to have a different name.

KosmosisDire avatar Feb 21 '24 21:02 KosmosisDire

Hi,

@vgyenge6 wait what do you mean when you say you "rename the exported .html file"? If you mean you are actually changing the name of the html after exporting of course this breaks all the links. The links are all based on the name of the file! Instead just rename your markdown file before exporting, or set the title property if you want to have a different name.

@KosmosisDire you are right, but first I would rename the file after export because it may be exported either having a TOC or not at all when exporting depending on where and how I will use the exported html further, and this doesn't regard the original .md file. I do not want to make so much several of md files. I seem to understand your stance about following the vault structure and making a web-site structure similar to the publishing possibility, which surely caused you to change much. But, please consider the individual HTML exports too, because, for example, I do not want a complex site exported based on the vault structure, but I would like to use the exported HTML-s in my WordPress site either having TOC or not and that may happen it is from same original md file.

Thus, I would like to add the following observations.

ver. 1.8.0 The whole HTML structure of the TOC navigation seems slightly changed. e.g. <a class="tree-link" href="MDTest\MD_obs.html#Tags"><div class="tree-item-contents heading-link" heading-name="Tags"><span class="tree-item-title">Tags</span></div></a> If you refer here explicitly to the obsidian folder and file name path if there is any change (e.g. html file name) after export the TOC navigation won't work! Furthermore, if a single exported html file is used on another server (e.g. I'm using the exported file on my WP site uploaded there and showing it in an iframe see. picture 3. ) the explicit file path reference surely won't work. This would be CRUCIAL to change back to the original as it was in the 1.7.3 version!!! (But I may be wrong :) <a class="internal-link tree-item-link" href="#Tags"><span class="tree-item-title"><p>Tags</p></span></a>

See screenshot

TOC_references_doesn't_work_2024-02-22

vgyenge6 avatar Feb 22 '24 09:02 vgyenge6

Yes, I understand why the links break. The reason I have changed it is because it reduces the complexity of the code quite a lot to treat all internal links the same. I will see what I can do to make the outline links relative, but know that this isn't a huge priority since you aren't meant to rename the files in the first place.

You'll have to be patient. I am only one person and this plugin is very large and complex.

KosmosisDire avatar Feb 22 '24 09:02 KosmosisDire

Hi, @KosmosisDire Understand.

but know that this isn't a huge priority since you aren't meant to rename the files in the first place.

Yes, but I think not the file renaming is the main concern here rather from the developer context the links many times must be relative I do not see why the original <a class="internal-link tree-item-link" href="#Tags"> would not remain, but I'm not an obsidian plugin developer, so surely you do know much better than me.

I'm using the exported files on my WP site uploaded there and showing them in an iframe see. picture 3. but, the explicit file path reference surely won't work. All TOC reference links worked well in the case of <a class="internal-link tree-item-link" href="#any">

Thus, My BIG PAIN is, if this navigation structure remains i.e. referring to the original vault md file path in the navigation even relatively referenced (and this does not regard whether I renamed the html files or not), I MUST regress to the previous 1.7.3 version and I lose all of useful and crucial features added to this new version. e.g. admonition icons, (I repaired the html files by hand :(-> and also the embedding what is also crucial to me.

vgyenge6 avatar Feb 22 '24 09:02 vgyenge6

I understand, I will work on fixing it. But again, I am one person and I can't guarentee any kind of speed.

KosmosisDire avatar Feb 22 '24 09:02 KosmosisDire

Hi,

I understand, I will work on fixing it. But again, I am one person and I can't guarentee any kind of speed.

I understand too and do not want to push you, I very much appreciate your huge work done, and you are doing. 🥇

Perhaps, I am one who wants to use the several kinds of inherent clever possibilities of your plugin and test them seriously:)

I mean, I would want to export not only 1. a single individual md->HTML, canvas->HTML files, 2. but some specific files from specific folders selected in bulk and make both navigations in left as pages structure and right as its TOC.

BTW: regarding the TOC navigation I opened a new issue https://github.com/KosmosisDire/obsidian-webpage-export/issues/362#issuecomment-1956452106 where I referred to

embed; other notes works (however there is inconsistency in the main TOC if an embedded note has headings)

So I guess you perhaps need to reconsider the navigation and make links relative in general both in the left sidebar and right as TOC.

vgyenge6 avatar Feb 22 '24 10:02 vgyenge6

The problem with making links relative is that all the links would need to change every time a new file is loaded. Secondly relative links cannot be used as a unique identifier for a file. This is very important that I have a unique identifier (I could use a data attribute for this). But the main thing is just that I like all the links having the same format. I think just for the outline I can make them relative. But there is no way I will make the file tree relative as well.

As for PDF embeddings I think that is a completely different issue. I haven't looked into it though.

KosmosisDire avatar Feb 22 '24 10:02 KosmosisDire

I can't guarentee any kind of speed.

I will be waiting, and sorry I can not help you by any other means (support your work by money or contribute to coding), Anyway, it is a MUST plugin! And if I need to regress to previous version until waiting I will resolve my special problems by hand, as I did already.

THANK FOR YOU MUCH dealing with my issues! And reacting to almost always in return and as quickly as you can! 👍 👍 💯 🥇

vgyenge6 avatar Feb 22 '24 10:02 vgyenge6

The problem with making links relative is that all the links would need to change every time a new file is loaded. Secondly relative links cannot be used as a unique identifier for a file. This is very important that I have a unique identifier (I could use a data attribute for this). But the main thing is just that I like all the links having the same format. I think just for the outline I can make them relative. But there is no way I will make the file tree relative as well.

Okay, I deem to understand your stance I like all the links having the same format but I do not completely understand why you should change <a class="internal-link tree-item-link" href="#any"> in TOC, or (I do not know how that looked like in your previous version in the file tree, because I did not test that then) perhaps this may be because you tried to implement to give an absolute url for a custom public server URL as a base reference. Anyway, what I do not know exactly I do not complain :D

As for PDF embeddings I think that is a completely different issue. I haven't looked into it though.

Okay, I can see this may be a kind of issue because if assets are set to make it offline compatible or not the generated output for this looks <div src="data:pdf/pdf;base64,JVBERi0xLjQK...> or similar, so I can not delve into the pdf file path :(

vgyenge6 avatar Feb 22 '24 11:02 vgyenge6

Hi,

The problem with making links relative is that all the links would need to change every time a new file is loaded. Secondly relative links cannot be used as a unique identifier for a file. This is very important that I have a unique identifier (I could use a data attribute for this). But the main thing is just that I like all the links having the same format. I think just for the outline I can make them relative. But there is no way I will make the file tree relative as well.

I did a little try and it is just a suggestion for a possible resolution

When HTML export mode is selected... change

<!-- <base href="..\..\../">
<!-- <meta id="root-path" root-path="..\..\../"> -->
<base href="">
<meta id="root-path" root-path="">

<meta property="og:url" content="path/filename.html"> I don't know what to do with here the path. I think it is for the graph to work.

Delete from href path\filename.html what precedes #heading and leave only the #heading in all right TOC navigation links.

The navigation on TOC will work both on local folders and uploaded to another server. (custom WP site too) and you need not change your implemented new logic other than <a class="internal-link tree-item-link" href="#any"> was earlier. And it doesn't matter anymore whether the HTML file had been renamed after export.

However, it is a bit time-consuming to do it manually on every exported file. :) :(

Perhaps it also can work for the left-side site navigation, when there are more md files selected and exported together as a site structure.

Try Delete from href path\ what precedes filename.html and leave only the filename.html in left site navigation all inks.

Please consider finding a resolution at least for the TOC as soon as you have time. Much thanks,

vgyenge6 avatar Feb 23 '24 14:02 vgyenge6

some addition : The Document Base URL element - HTML: HyperText Markup Language | MDN

The base URL to be used throughout the document for relative URLs. Absolute and relative URLs are allowed

vgyenge6 avatar Feb 23 '24 14:02 vgyenge6

Yes I understand all of this and I have already stated I will make the TOC links relative. I will look into making the file tree relative as well, but it actually can't simply be solved by using base url. Right now I am using base url! The links would still have to change each time a new document was loaded because the relative paths would change. Using base url fixes that, which is why it works right now without the urls changing.

KosmosisDire avatar Feb 23 '24 19:02 KosmosisDire

I added relative TOC links to 1.8.1-0b, let me know how it works.

KosmosisDire avatar Mar 01 '24 10:03 KosmosisDire

Hi,

Such big news and how quickly, and it WORKS exactly as I expected. Not only the TOC links but the left side navigation also works when more files are selected. THANK YOU VERY MUCH 👍 🥇

Just a little side note: It would be good if the folder from which the file(files) were selected can be automatically given in the path text box, and even the folder would be folded/navigated there (as it was I think formerly, and given but the Root vault folder was needed to be selected in the path text box.) Now I need to fold manually and BROWSE manually to that exact folder from where the file(s) was/were selected and I wish the HTML file(s) to be saved. I'm speaking of the case of HTML document mode export, and when I select more files invoking from the tab right-click Export as HTML menu. (Not that case when more files may be selected from the explorer right-click Export as HTML menu albeit both cases allow to select files which are not in same folders ??) There is also a little problem with the "/" in the path name even if I select the folder by the Browse button. e.g. D:/VALI/MDTest, on Windows I'm getting a Windows error message there is no such folder! Yes because the path separator on Windows is backslash. However, there is no problem with the saving of files to the local file system and the browser handles the path as File:///D:/VALI/MDTest/file.html and the left-side navigation also works well.

Not so many big problems, that would not be handled manually :) In summary, thank you again, the essential things work as expected!!!

vgyenge6 avatar Mar 02 '24 13:03 vgyenge6

Hi, Just a reminder because this problem was reported here https://github.com/KosmosisDire/obsidian-webpage-export/issues/366#issuecomment-1959128417

BTW: regarding the TOC navigation I opened a new issue #362 (comment) where I referred to

embed; other notes works (however there is inconsistency in the main TOC if an embedded note has headings)

You wrote there https://github.com/KosmosisDire/obsidian-webpage-export/issues/362#issuecomment-1956872906

I'll look into the problem with the heading levels

Please do not forget because this #362 issue was renamed by you dealing mainly with the PDF embedding, not the embedded headings inconsistency. I do not want to open a new issue regarding this but it is still important.

Thank you.

vgyenge6 avatar Mar 02 '24 14:03 vgyenge6

If you could opena new issue for that that would be best. Multiple problems shouldn't really be tracked inside one issue.

KosmosisDire avatar Mar 03 '24 00:03 KosmosisDire

Can you also create new issues for each of the other problems you have had. Make sure to check for duplicates!

KosmosisDire avatar Mar 03 '24 00:03 KosmosisDire

Hi, See above https://github.com/KosmosisDire/obsidian-webpage-export/issues/366#issuecomment-1974791176

There is also a little problem with the "/" in the path name even if I select the folder by the Browse button. e.g. D:/VALI/MDTest, on Windows I'm getting a Windows error message there is no such folder! Yes because the path separator on Windows is backslash. However, there is no problem with the saving of files to the local file system and the browser handles the path as File:///D:/VALI/MDTest/file.html

I also mentioned that in #284 see above.

I found you released a newer 1.8.1b Pre-release where "Fix issue where windows would throw errors about path not found due to using forward slashes." also had resolved. I will try this release.

vgyenge6 avatar Mar 03 '24 10:03 vgyenge6

https://github.com/KosmosisDire/obsidian-webpage-export/issues/366#issuecomment-1974960911 I opened a new issue #386.

Make sure to check for duplicates! Little more to do for me okay, I did not find similar but, this does not mean there is not :)

vgyenge6 avatar Mar 03 '24 10:03 vgyenge6