You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow absolute links to external sites in pages section of mkdocs.yml #989
DEBUG - Building page http:/www.google.com
ERROR - file not found: /Users/nsnyder/code/linkedin/layoutkit-opensource/docs/http:/www.google.com
ERROR - Error building page http:/www.google.com
It would be easy to skip the call to _build_pages if the value starts with http but also need to generate the correct absolute link in the nav. Happy to work on this if you agree.
If so, can you point me to the correct place for generating the link?
Reacted by Philip Tellis, Mikey Lombardi (He/Him), Mike Mitterer, Kyle Bowerman, Sebastian Tkaczyk, Yassir Barchi, Bill Niblock, Alexander Weigl, Dmytro Bogatov, Gurpartap Singh and 15 more
No, this is currently not possible. A few similar requests (#797 and #575) have been punted to the upcoming Plugin API (#206).
However, thinking about this, any such plugin would need to know where in the pages structure the new nav item would need to go. We could just say "add it within the plugin," but with multiple levels of nesting, that really limits what users can do. Either the plugin needs to know the structure of the pages and step through until it guesses the right location, or the plugin would just tack any new nav items on the end at the root level only. In other words, it's either really complex or extremely simple and limited. Perhaps we need to have some native support for a placeholder of some kind. Not really sure what that would look like though. Maybe a title with no data is understood to be a placeholder and just ignored. Then a plugin can use that placeholder as it sees fit (link to generated content, or an external resource, or ...).
Would it be possible as a quick fix to just customize the theme where the menu is created with the static link? It would be nice to make this modified easily, but it should be possible to just add another menu item if its going to be just one hardcoded value in a given project.
@erichgoldman yes that would be an alternate solution for some edge cases (especially with the new theme customization), but that won't address the needs of people who want their links embedded into the structure of the nav.
I suppose, if a user just wants to tack a link on the beginning or end of the nav, that would be easy enough through theme customization. That would also be easy enough to address with a simple Plugin. But if we want to support the ability to have external links anywhere in the nav, then we need to provide something built-in so that the user can define those links within the pages config setting. So I guess the question is, how complex of feature do we want to create? If we keep it simple (add to beginning or end) then we don't need to do anything (except maybe finish the Plugin API), but I can see the elegance of being able to just insert external links right in the pages config.
Hmm, I just went back and reread this entire thread and I was reminded that we have two separate use cases for adding non-page items to the nav:
Link to an external site. This is easy, just check the config for a URL that starts with http(s):// and insert a external link object in the nav but leave out of page.next/previous.
Link to some local HTML content (whether generated by a third party tool or hand-crafted). Maybe we check that the relative URL ends with .html? Inserting an appropriate object in the nav is easy enough once we identify the type of page, but do we include these pages in the page.next/previous or not? I'm thinking not as there would be no way to add next/previous links to the pages themselves. Or should the pages be treated as templates and run through the template engine?.
And then what do we do with an entire collection of pages (perhaps generated by a third party tool)? Require every page to be listed in the nav or just point to the dir? If we point to the dir, then next/previous is out I think. If an item in the pages config points to a directory, just create a nav item and that's it.
Perhaps it would help to remember that a common request is for people to be able to host their generated documentation (from the source code) for a project as a subsection of their prose documentation (using MkDocs). They expect to be able to run their tool of choice, which generates their documentation in a subdirectory of their docs_dir and then run MkDocs which would copy and integrate that documentation into the MkDocs site. In fact, this was the primary use case I had in mind for option 2 above.
In the end, it probably makes more sense for that type of integration to be left to a plugin. But in that case, how do users tell the plugin where to insert an item into the nav? That is the problem I am trying to solve here. Links to an outside resource are easy, it's the internal links which are less clear. Yes we could require the internal links to be "external" also, but that doesn't feel very clean to me.
One possibility I have thought of but am unsure about is adding support for some kind of "placeholder". Then a plugin could search for a placeholder with a given name and replace it with an actual nav item. Presumably any placheolders left in the nav would be skipped/ignored by the template. What that placeholder looks like and how it is given a unique name is not clear though. Just throwing the idea out there.
I had the same problem and found this thread. The simplest workaround I could think up is - in your pages.yml:
in pages:... section, compose link title as actual title|href (I found handy to mark external links with 🗗 Unicode character), for example - 'Google 🗗|http://www.google.com/': 'index.md'
(just pretend it's local file, it only must be existing md)
in extra_javascript:... section, declare file with following code:
var anchors = Array.from(document.getElementsByClassName("navbar-collapse")[0].getElementsByTagName("a"));
anchors.forEach(function(anchor) {
var sep = anchor.innerText.indexOf("|");
if (sep != -1) {
anchor.href = anchor.innerText.substring(sep + 1, anchor.innerText.length);
anchor.innerText = anchor.innerText.substring(0,sep);
}
if (anchor.innerText.indexOf("\uD83D\uDDD7") != -1) { // 🗗 = "new window" char, see http://www.fileformat.info/info/unicode/char/1f5d7/index.htm
anchor.target = "_blank";
}
});
Reacted by Matias Guijarro, Alex Zanetti de Lima, Stephen Stone and Chaz Reid
Reacted by Matias Guijarro, Giancarlos Salas, Alex Zanetti de Lima and Stephen Stone
Activity
waylan commentedon Jul 4, 2016
No, this is currently not possible. A few similar requests (#797 and #575) have been punted to the upcoming Plugin API (#206).
However, thinking about this, any such plugin would need to know where in the pages structure the new nav item would need to go. We could just say "add it within the plugin," but with multiple levels of nesting, that really limits what users can do. Either the plugin needs to know the structure of the pages and step through until it guesses the right location, or the plugin would just tack any new nav items on the end at the root level only. In other words, it's either really complex or extremely simple and limited. Perhaps we need to have some native support for a placeholder of some kind. Not really sure what that would look like though. Maybe a title with no data is understood to be a placeholder and just ignored. Then a plugin can use that placeholder as it sees fit (link to generated content, or an external resource, or ...).
nicksnyder commentedon Jul 5, 2016
Perhaps a plugin could register a handler for values.
Something like this? (warning, I haven't written Python in a while so read this like pseudocode).
In the meantime, it is easy to me to just create a dummy markdown page that does a redirect using a meta refresh tag.
erichgoldman commentedon Dec 15, 2016
Would it be possible as a quick fix to just customize the theme where the menu is created with the static link? It would be nice to make this modified easily, but it should be possible to just add another menu item if its going to be just one hardcoded value in a given project.
e.g., hard code in a
<li />under<ul class="nav navbar-nav">in the themewaylan commentedon Jan 20, 2017
@erichgoldman yes that would be an alternate solution for some edge cases (especially with the new theme customization), but that won't address the needs of people who want their links embedded into the structure of the nav.
I suppose, if a user just wants to tack a link on the beginning or end of the nav, that would be easy enough through theme customization. That would also be easy enough to address with a simple Plugin. But if we want to support the ability to have external links anywhere in the nav, then we need to provide something built-in so that the user can define those links within the
pagesconfig setting. So I guess the question is, how complex of feature do we want to create? If we keep it simple (add to beginning or end) then we don't need to do anything (except maybe finish the Plugin API), but I can see the elegance of being able to just insert external links right in thepagesconfig.erichgoldman commentedon Jan 20, 2017
Agree, the plugin solution is the best longer term solution.
My proposal is as a short term / bridge solution for other users who search, come here, and want a solution today.
waylan commentedon Jan 20, 2017
Hmm, I just went back and reread this entire thread and I was reminded that we have two separate use cases for adding non-page items to the nav:
Link to an external site. This is easy, just check the config for a URL that starts with
http(s)://and insert a external link object in the nav but leave out of page.next/previous.Link to some local HTML content (whether generated by a third party tool or hand-crafted). Maybe we check that the relative URL ends with
.html? Inserting an appropriate object in the nav is easy enough once we identify the type of page, but do we include these pages in the page.next/previous or not? I'm thinking not as there would be no way to add next/previous links to the pages themselves. Or should the pages be treated as templates and run through the template engine?.And then what do we do with an entire collection of pages (perhaps generated by a third party tool)? Require every page to be listed in the nav or just point to the dir? If we point to the dir, then next/previous is out I think. If an item in the
pagesconfig points to a directory, just create a nav item and that's it.waylan commentedon Jan 31, 2017
Perhaps it would help to remember that a common request is for people to be able to host their generated documentation (from the source code) for a project as a subsection of their prose documentation (using MkDocs). They expect to be able to run their tool of choice, which generates their documentation in a subdirectory of their
docs_dirand then run MkDocs which would copy and integrate that documentation into the MkDocs site. In fact, this was the primary use case I had in mind for option 2 above.In the end, it probably makes more sense for that type of integration to be left to a plugin. But in that case, how do users tell the plugin where to insert an item into the nav? That is the problem I am trying to solve here. Links to an outside resource are easy, it's the internal links which are less clear. Yes we could require the internal links to be "external" also, but that doesn't feel very clean to me.
waylan commentedon Jan 31, 2017
One possibility I have thought of but am unsure about is adding support for some kind of "placeholder". Then a plugin could search for a placeholder with a given name and replace it with an actual nav item. Presumably any placheolders left in the nav would be skipped/ignored by the template. What that placeholder looks like and how it is given a unique name is not clear though. Just throwing the idea out there.
joseluisq commentedon Oct 20, 2017
Cool!
Any progress on this feature ?
yannduran commentedon Jan 27, 2018
I'm also hoping that @waylan's #1 scenario will be easy to implement (hopefully soon :-))
tomaszalusky commentedon Feb 23, 2018
I had the same problem and found this thread. The simplest workaround I could think up is - in your
pages.yml:pages:...section, compose link title asactual title|href(I found handy to mark external links with 🗗 Unicode character), for example- 'Google 🗗|http://www.google.com/': 'index.md'(just pretend it's local file, it only must be existing md)
extra_javascript:...section, declare file with following code:Kikju commentedon Jun 27, 2018
Hello,
I edited @tomaszalusky's code to work properly for all browsers.
sstone2423 commentedon Jul 3, 2018
I edited it to meet my needs. Thanks for the fix!
Also, this helped me as well if anyone is linking back to a single home page. This will change the top Docs link from site/index to your home page
waylan commentedon Jul 3, 2018
FYI, this feature will be officially supported without hacks in the next release (1.0). See #1504 for more info.
csandanov commentedon Aug 31, 2018
I'm on 1.0.3 and external links under
nav:(pagesin older versions) don't work for me.froschdesign commentedon Aug 31, 2018
@csandanov
You should open a separate issue report and add the content from your
mkdocs.ymlfile.Internal Refactor of Pages, Files, and Navigation (mkdocs#1504)