Skip to content

Commit

Permalink
Update doc side menu JS to allow for external links
Browse files Browse the repository at this point in the history
Author: Angela Murrell <[email protected]>

Reviewers: Jagadish<[email protected]>

Closes apache#679 from amurrell/master
  • Loading branch information
amurrell authored and jagadish-v0 committed Oct 1, 2018
1 parent 5e4ba7d commit 334d24e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h2 class="section__title section__title--sub">
<a class="button" href="/startup/hello-samza/{{site.version}}">
Quick Start
</a>
<a class="button" href="/startup/hello-samza/{{site.version}}">
<a class="button" href="/case-studies/">
Case studies
</a>
</div>
Expand Down
17 changes: 15 additions & 2 deletions docs/js/main.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,19 @@ var buildDocMenu = (status, body, docMenu) => {

} else if (h4Link) {
var h4LinkEl = document.createElement('a');
var linkDestination = docMenuLinkBase + h4Link.getAttribute('href');
var h4href =h4Link.getAttribute('href');
var linkDestination = h4href.match(/^http/) ? h4href : docMenuLinkBase + h4href;
var linkText = h4Link.text.trim();

h4LinkEl.classList.add('side-navigation__group-item');
h4LinkEl.setAttribute('href', linkDestination);
h4LinkEl.setAttribute('data-match-active', h4Link.getAttribute('data-match-active'));

if (h4href.match(/^http/)) {
h4LinkEl.setAttribute('target', '_blank');
h4LinkEl.setAttribute('rel', 'nofollow');
}

h4LinkEl.text = linkText;

docMenu.appendChild(h4LinkEl);
Expand All @@ -302,7 +309,8 @@ var buildDocMenu = (status, body, docMenu) => {

Array.from(listItems).forEach( listItem => {
var link = listItem.querySelector('a');
linkDestination = docMenuLinkBase + link.getAttribute('href');
var linkhref = link.getAttribute('href');
linkDestination = linkhref.match(/^http/) ? linkhref : docMenuLinkBase + linkhref;

linkText = link.text.trim();

Expand All @@ -311,6 +319,11 @@ var buildDocMenu = (status, body, docMenu) => {
newLink.setAttribute('href', linkDestination);
newLink.text = linkText;

if (linkhref.match(/^http/)) {
newLink.setAttribute('target', '_blank');
newLink.setAttribute('rel', 'nofollow');
}

itemsDiv.appendChild(newLink);
})

Expand Down

0 comments on commit 334d24e

Please sign in to comment.