Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_current('') is always true, regardless of current page url #1112

Closed
webuniverseio opened this issue Mar 13, 2015 · 4 comments
Closed

is_current('') is always true, regardless of current page url #1112

webuniverseio opened this issue Mar 13, 2015 · 4 comments
Labels
question Needs help in usage

Comments

@webuniverseio
Copy link

I expect that is_current('') should return false for pages like /about/, /contact, etc... Do I misunderstand something? Thank you.

@kokjinsam
Copy link

I encountered this problem as well.

@kokjinsam
Copy link

in order to make this work, I had to do this is_current('about/index.html') which seems to me a little bit counter-intuitive.

@NoahDragon NoahDragon added this to the 4.0 milestone Apr 6, 2017
@NoahDragon NoahDragon mentioned this issue Apr 6, 2017
53 tasks
@dcanetma
Copy link

dcanetma commented Jun 5, 2019

Here's a sample using EJS that seems to work.

		<% if(site.data.menu) {%>
			  <ul class="navbar-nav ml-auto">
			  	<% for (link in site.data.menu) { %>
				  	<li class="nav-item <%- is_current(site.data.menu[link]+'/index.html') ? 'active' : '' %>">
				  		<a class="nav-link" href="<%= config.root %><%= site.data.menu[link] %>" title="Go to <%= link %> page"><%= link %></a>
				  	</li>
					<% } %>
			  </ul>
	  <% } %>

@stevenjoezhang
Copy link
Member

is_current('') is always true

function isCurrentHelper(path = '/', strict) {
const currentPath = this.path.replace(/^[^/].*/, '/$&');
if (strict) {
if (path[path.length - 1] === '/') path += 'index.html';
path = path.replace(/^[^/].*/, '/$&');
return currentPath === path;
}
path = path.replace(/\/index\.html$/, '/');
if (path === '/') return currentPath === '/index.html';
path = path.replace(/^[^/].*/, '/$&');
return currentPath.startsWith(path);
}

https://hexo.io/docs/helpers#is-current

@stevenjoezhang stevenjoezhang added question Needs help in usage and removed need-verify labels Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Needs help in usage
Projects
None yet
Development

No branches or pull requests

6 participants