Skip to content

Commit

Permalink
Fix docfx template bug: navbar not working if site is not hosted unde…
Browse files Browse the repository at this point in the history
…r root url; navbar is not working for files under root folder
  • Loading branch information
vicancy committed Nov 5, 2015
1 parent 51ae3cf commit 007331b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ artifacts/
target/
/**/_site/
.vscode/
.vs/

###############
# temp file #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void UpdateRelativePathAndAddTocMap(TocViewModel toc, FileModel model, H
tocPath = absHref.GetPathFromWorkingFolder();
if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
{
var error = $"Unable to find either toc.yml or toc.md inside {item.Href}";
var error = $"Unable to find either toc.yml or toc.md inside {item.Href}. Make sure the file is included in config file docfx.json!";
Logger.LogError(error, file: model.LocalPathFromRepoRoot);
throw new DocumentException(error);
}
Expand All @@ -124,6 +124,8 @@ private void UpdateRelativePathAndAddTocMap(TocViewModel toc, FileModel model, H

// Add toc.yml to tocMap before change item.Href to home page
item.Href = ((RelativePath)file + (RelativePath)item.Href).GetPathFromWorkingFolder();
if (item.OriginalHref != null) item.OriginalHref = (RelativePath)file + (RelativePath)item.OriginalHref;

HashSet<string> value;
if (tocMap.TryGetValue(item.Href, out value))
{
Expand Down
11 changes: 6 additions & 5 deletions src/docfx.website.themes/default/styles/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ $(function() {
if (navbarPath) navbarPath = navbarPath.replace(/\\/g, '/');
$('#navbar').load(navbarPath + " #toc>ul", function() {
var index = navbarPath.lastIndexOf('/');
if (index === -1) {
console.log("invalid navbar path: " + navbarPath);
return;
var navrel = '';
if (index > -1) {
navrel = navbarPath.substr(0, index + 1);
}
var navrel = navbarPath.substr(0, index + 1);

$('#navbar>ul').addClass('navbar-nav');
var currentAbsPath = getAbsolutePath(window.location.pathname);
// set active item
Expand All @@ -83,7 +83,8 @@ $(function() {
var isActive = false;
var originalHref = e.name;
if (originalHref){
if ('/' + getDirectory(originalHref) === getDirectory(getAbsolutePath(tocPath))) {
originalHref = navrel + originalHref;
if (getDirectory(getAbsolutePath(originalHref)) === getDirectory(getAbsolutePath(tocPath))) {
isActive = true;
}
} else {
Expand Down
Binary file modified src/docfx/Template/default.zip
Binary file not shown.

0 comments on commit 007331b

Please sign in to comment.