HTML - Link to files in a different folder - html

I am trying to make a clickable link to an HTML doc that is in a different folder than the original doc. I have read article after article and I can't figure it out.
Hello
I understand this fine^
Usually, when I'm linking to another file, it is in the same folder as the one I'm currently using so it works just fine.
Please see the path bellow I use on my computer to reach the file I want:
Desktop>My Folder>Oct 2020>Oct 15
After reading through articles on the subject, I came up with this, but it's not working.
<a href="file:///C:/Desktop/My Folder/Oct 2020/Oct 15/hello.html" target="_blank">
Obviously, there is a key concept I am missing here.
Your advice is appreciated!

What you want to do is determine how to get from the folder that contains your HTML document to the folder that contains your original document.
When writing a path from one folder to another, separate each folder with a /, and use two periods .. to go "up" one level in your folders.
For example, in the folders shown below, if you wanted to edit file1.html which is in My Folder so it contained a link to hello.html, you could use a link like this:
Hello
If, instead, you wanted to edit file2.html so it contained a link to hello.html, then you could use a link like this:
Hello
Note that we need to go "up" two levels (up to Nov 2020 and then up to My Folder), so we need to use .. twice.

Related

How to link to html in a folder not directly connected

I am creating a website with simple HTML+CSS. How do I create a hyperlink (href) in an HTML file, to an HTML file in a folder, that is not directly related.
See picture. If I want to insert a link in HTML 4 to HTML 3.
I know one can use ..\HTML2.html to go back in parent folder, but what is the best way here?
Typing / points to the relative root directory. So you can just do HTML 3 and it should take you to HTML3.
You can also use HTML 3 as you seem to know.
General recommendation would be to pick the closest path. If it's from the root, then select the first. If it's from a relative point from where you are, then the second.
Considering your drawing, I assume that node 1 is the root so the simplest way would be: .\html3.html

Github readme.md preview rendered html inside the repository [duplicate]

Is there a way to create a URL anchor, <a>, link from within a Markdown file, to another file within the same repository and branch (aka a link relative to the current branch)?
For example, in the master branch I have a README.md file, which I would like do something like:
# My Project
is really really cool. My Project has a subdir named myLib, see below.
## myLib documentation
see documentation [here](myLib/README.md)
This would allow me to link from one .md to another within the same branch and not have to worry about which branch I'm in (avoid having to do an absolute URL that includes the github.com branch name).
Here is a working example of what I mean:
GOTO http://github.com/rynop/testRel, link does not work.
GOTO http://github.com/rynop/testRel/blob/master/README.md, link works.
This is expected because at this point the starting URL is in the branch. Now how do I get it to pick up the current branch in the README.md at the root of the repository?
Update: I opened an issue against GitHub for this feature request.
Update 30th, January 2013, 16 months later:
GitHub Blog Post Relative links in markup files:
Starting today, GitHub supports relative links in markup files.
Now you can link directly between different documentation files, whether you view the documentation on GitHub itself, or locally, using a different markup renderer.
You want examples of link definitions and how they work? Here's some Markdown for you.
Instead of an absolute link:
[a link](https://github.com/user/repo/blob/branch/other_file.md)
…you can use a relative link:
[a relative link](other_file.md)
[a relative link](path%20with%20spaces/other_file.md)
and we'll make sure it gets linked to user/repo/blob/branch/other_file.md.
If you were using a workaround like [a workaround link](repo/blob/master/other_file.md), you'll have to update your documentation to use the new syntax.
This also means your documentation can now easily stand on its own, without always pointing to GitHub.
Marcono1234 adds in the comments
Also useful: When the link starts with a /, it is relative to the root of the repository (regardless of whether the markdown file is nested in subdirectories)
Update December 20th, 2011:
The GitHub markup issue 84 is currently closed by technoweenie, with the comment:
We tried adding a <base> tag for this, but it causes problems with other relative links on the site.
October 12th, 2011:
If you look at the raw source of the README.md of Markdown itself(!), relative paths don't seem to be supported.
You will find references like:
[r2h]: http://github.com/github/markup/tree/master/lib/github/commands/rest2html
[r2hc]: http://github.com/github/markup/tree/master/lib/github/markups.rb#L13
As noted in InvisibleWolf's answer, if the target link is a directory and it has space, then you need to use %20 for each space.
For example, you have a repo like the following:
project/
text.md
subpro/
subtext.md
subsubpro/
subsubtext.md
subsubpro2/
subsubtext2.md
The relative link to subtext.md in text.md might look like this:
[this subtext](subpro/subtext.md)
The relative link to subsubtext.md in text.md might look like this:
[this subsubtext](subpro/subsubpro/subsubtext.md)
The relative link to subtext.md in subsubtext.md might look like this:
[this subtext](../subtext.md)
The relative link to subsubtext2.md in subsubtext.md might look like this:
[this subsubtext2](../subsubpro2/subsubtext2.md)
The relative link to text.md in subsubtext.md might look like this:
[this text](../../text.md)
GitHub could make this a lot better with minimal work. Here is a work-around.
I think you want something more like
[Your Title](your-project-name/tree/master/your-subfolder)
or to point to the README itself
[README](your-project-name/blob/master/your-subfolder/README.md)
As of January 31, 2013 Github markdown supports relative links to files.
[a relative link](markdown_file.md)
However, there are a few deficiencies that have been discussed in this comment thread.
As an alternative, you can use Gitdown to construct full URLs to the repository and even make them branch aware, e.g.
{"gitdown": "gitinfo", "name": "url"} // https://github.com/gajus/gitdown
{"gitdown": "gitinfo", "name": "branch"} // master
Gitdown is a GitHub markdown preprocessor. It streamlines common tasks associated with maintaining a documentation page for a GitHub repository, e.g. generating table of contents, including variables, generating URLs and getting information about the repository itself at the time of processing the input. Gitdown seamlessly integrates with your building scripts.
I am the author of the Gitdown library.
Just wanted to add this because none of the above solutions worked if target link is directory with spaces in it's name. If target link is a directory and it has space then even escaping space with \ doesn't render the link on Github. Only solution worked for me is using %20 for each space.
e.g.: if directory structure is this
Top_dir
|-----README.md
|-----Cur_dir1
|----Dir A
|----README.md
|----Dir B
|----README.md
To make link to Dir A in README.md present in Top_dir you can do this:
[Dir 1](Cur_dir1/Dir%20A)
You can link to file, but not to folders, and keep in mind that, Github will add /blob/master/ before your relative link(and folders lacks that part so they cannot be linked, neither with HTML <a> tags or Markdown link).
So, if we have a file in myrepo/src/Test.java, it will have a url like:
https://github.com/WesternGun/myrepo/blob/master/src/Test.java
And to link it in the readme file, we can use:
[This is a link](src/Test.java)
or: This is a link.
(I guess, master represents the master branch and it differs when the file is in another branch.)
You can use relative URLs from the root of your repo with <a href="">. Assuming your repo is named testRel, put the following in testRel/README.md:
# My Project
is really really cool. My Project has a subdir named myLib, see below.
## myLib docs
see documentation:
* myLib/
* myLib/README.md
This question is pretty old, but it still seems important, as it isn't easy to put relative references from readme.md to wiki pages on Github.
I played around a little bit and this relative link seems to work pretty well:
[Your wiki page](../../wiki/your-wiki-page)
The two ../ will remove /blob/master/ and use your base as a starting point. I haven't tried this on other repositories than Github, though (there may be compatibility issues).
In .md file when you want to create a link to any related files which is related to same project folder or URL based links:
Existing file link:
In .md file add showing name in [] box then open () in this box add / after that it will auto fetch all existing folders name form which you choose your folder then add '/' it will show inner file or 'folders`. This means it will auto fetch the paths and at the end, your URL is created.
Example:
[Enter Showing Name](/users/4000266/heysushil)
This line show like this:
Enter Showing Name
Add URLs on .md file
Follow the same process only change the () box path with URL like this:
[HeySushil - YouTube](https://youtube.com/heysushil)
This looks like HeySushil - YouTube
Note: Remember no need to add force manually after adding / on () box it will auto fetch all existing folders and files.
I am not sure if I see this option here. You can just create a /folder in your repository and use it directly:
[a relative link](/folder/myrelativefile.md)
No blob or tree or repository name is needed, and it works like a charm.
If you want a relative link to your wiki page on GitHub, use this:
Read here: [Some other wiki page](path/to/some-other-wiki-page)
If you want a link to a file in the repository, let us say, to reference some header file, and the wiki page is at the root of the wiki, use this:
Read here: [myheader.h](../tree/master/path/to/myheader.h)
The rationale for the last is to skip the "/wiki" path with "../", and go to the master branch in the repository tree without specifying the repository name, that may change in the future.
The behaviour in Github directory links in markdown files could create some headaches.
All files have an url are starting with blob,
blob/<branch>/<path>/<fileName>
whereas directories have an url starting with tree:
tree/<branch>/<path>
So no relative link to a directory should work. It points to an url that starts with a blob. Magically Github changes some relative path automatically to the tree path. Unfortunately not urls containing ".."
I investigate some time to examine the strange behaviour with Github directory links on https://github.com/fluentcodes/GitSamples-GIT/tree/github-readme-links.
Just follow the format below.
[TEXT TO SHOW](actual URL to navigate)
Here is what I found for relative links in github's .md files:
Relative links without ../ (aka. link to file in the same level, or in sub dir), seems always work.
Relative links that contains ../ works only when you are already in a page whose url contains substring /blob/.
Otherwise need to use full url that contains /blob/, to link.
Actually except top level /README.md, when view any other files, their url already contains /blob/.
Thus probably you can always use relative links that contains ../ in files, except /README.md.
But /README.md is in top level, thus it shouldn't need a relative link that contains ../.
So, you should never need a full path link (that contains github domain) to link to files in the same github repo.
Example (links among multiple language doc)
In /README.md, can use relative links without ../.
[中文](doc/cn/README.md) |
[日本語](doc/jp/README.md)
In /doc/cn/README.md, since when we view it, the url already contains /blob/, thus could use relative links with ../.
[English](../../README.md) |
[日本語](../jp/README.md)
(BTW, the example come from this git-merge-flow repo.)
What I found to work for relative folders:
[link text](subfolder/subsubfolder/relevantfolder/)
where relevant folder is the folder you are trying to link to. The backslash is needed after the folder name. I tried including the project name and tree/main in the path and the other things suggested in previous answers, that lead to a nonexistent page error. The subfolder is a folder within the overall repo project folder.
Thus, file links would be in the form of:
[link text](subfolder/subsubfolder/relevantfolder/index.html)
If the desired file is not in any folder or subfolder the link is simply:
[link text](README.md)
for example the README file is not in any subfolders, so that could be the exact relative link you use for the README file.
You can also insert your links (relative or absolute) at the bottom to reduce clutter in text.
It can also be a good option for repetitive links.
This is [my linked text].
[my linked text]: relative/path/in/repo/to/file.txt "Optional title for mouse hover"
This is my linked text.

Html directory link not working if the directory is not from the beginning

My problem is that I have a bunch of HTML files but in simple I have public_html/pages folder + index.html/under pages folder a dmca.html is located.
So when I want to locate the file using href = "pages/dmca.html" it doesn't work and on another side when I use "../../public_html/pages/dmca.html" from the beginning it works is it normal or something wrong so I can only use the simple way as I have mentioned above(the link)
You have to look where is the .html file located on the hierarchy. If you are in dmca.html and you have a href on that page to second.html, you will need to jump backwards to the pages directory, and then go to the file: ../second.html
Now, if you are in index.html, and you have a href linking to dmca.html, you will need to hop back one level, enter pages directory, and choose the .html file. So it would be like this: ../pages/dmca.html
-public_html
|
|--index.html
|--pages
|--dmca.html
|--second.html
If I have not explained myself correctly, or I've understood the question wrong, please tell me.
What is happening, if I understand the problem properly, is that you are in index.html, and you want to href dmca.html, but the route you use pages/dmca.html, doesn't work, but if you use ../../public_html/pages/dmca.html, then, it does work. And I guess you are asking why is this happening.
Well, what happens when you use pages/dmca.html is that you are saying: search for a subdirectory called 'pages' and go to the file inside it called dmca.html. This would be correct if you had this hierarchy:
-public_html
|
|--index.html
|--pages
|--dmca.html
|--second.html
But index.html is a file, so it can't contain subdirectories. That's why you have to go one level up the hierarchy, and then, once you are in public_html/ you can choose to load index.html or go to the subdirectory public_html/pages and choose a file from it.
Right now I'm working on my web page, and... rethinking about it, I have to say that you were right, I mean, what you were doing was supposed to work.
Look at my directories. I have a htdocs folder, inside it I have some .png, index.html, and a folder called "prova", inside the folder "prova" I have index2. You can see that it is the same case as yours. I have an href on index.html that says href="prova/index2.html" and it works for me. Actually what I've said to you on the morning is wrong. I'm sorry :/
Because if I write ../prova/inedx2.html what happens is that the folder "htdocs" is removed from the URL. Remaining as: "PortàtilHP_antic_pare/prova/index2.html" You can see that the folder between "PortàtilHP_antic_pare" and "prova", which should be "htdocs", has disappeared.
So now I'm wondering how my answer has been useful for you. I guess I have understand it wrong, and somehow, my answer has made you change something that somehow has worked.

html links to files in my domain

I need to link to files in my domain. I don't want to use the full https://my-domain.com/dir-1/file.gif
Assuming the file isn't in a subdirectory under my current page but is in another subdirectory off somewhere. How do I link to it with minimal coding?
There's a lot of info on the web about html links but usually after one basic example they diverge off into coding colored links or css.
This may also be an irrelevant question but is there any way I can have a unique page identifier and link to that page even if it's location or name changes? I do not want to use another #$%^&?! CMS system.
Say your index file is in the root directory, and you want to link to that gif in your dir-1 directory, you'd need to use dir-/file.gif as your url.
If as an image:
<img src="dir-1/file.gif" />

Changing the location of the index.html file in Doxygen output

I'm using Doxygen to create html output.
I'd like to customize the output so that the index.html file could be more noticeable, since at the moment it is buried half way down a huge list of files in the html output folder.
For example, if it were moved up one directory to be outside of the 'bits and pieces' html files then it would be much more accessible for others who will be looking for it. However, I can't just ass a line of script to copy it to that location, since all of the links it has would break.
If I could configure Doxygen to have the index file go to a different location, or if you can think of another solution to my problem, I'd be grateful for your response.
Thanks
I would leave the documentation in its place and instead use the meta refresh option of the HTML language. Place a file, for instance called, "Documentation.html" in any folder you want with the following content
<meta http-equiv="REFRESH" content="0;URL=RELATIVE/PATH/TO/index.html">
As I mention in comments to the OP the easiest solution is probably to create a symbolic link or shortcut to the index.html file generated by doxygen, rather than trying to get doxygen to change the layout of it's output files. This symlink/shortcut can then be placed in the root directory of your project (or elsewhere), pointing to ./html/index/html, and named anything you like to make it obvious to your users what it is.