feat(theme-nav): remove nav link for current page

- reimplement in js, avoid disabling hexo layout caching
- revert f9889702b7
This commit is contained in:
Ming Di Leom 2021-02-23 07:48:56 +00:00
parent 748fec2f1d
commit 056d4389ab
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
5 changed files with 15 additions and 11 deletions

View File

@ -1,5 +1,5 @@
<article id="<%= post.layout %>-<%= post.slug %>" class="h-entry article article-type-<%= post.layout %>" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<%- partial('_partial/header', {}, { cache: false }) %>
<%- partial('_partial/header', {}, { cache: true }) %>
<hr class="header-hr">
<div class="article-inner">
<%- partial('post/gallery') %>

View File

@ -4,11 +4,7 @@
<% if (!theme.menu) { %><a class="main-nav-link" href="<%- config.root %>">Home</a>
<% } else { %>
<% for (const i in theme.menu) { %>
<% if (url_for(theme.menu[i]) !== url_for(page.path)) { %>
<a class="main-nav-link" href="<%- url_for(theme.menu[i]) %>"><%= i %></a>
<% } else { %>
<span class="main-nav-link"><%= i %></span>
<% } %>
<% }} %>
<div class="search-container">
@ -55,11 +51,7 @@
<% if (!theme.menu) { %><a class="mobile-nav-link-a" href="<%- config.root %>">Home</a>
<% } else { %>
<% for (const i in theme.menu) { %>
<% if (url_for(theme.menu[i]) !== url_for(page.path)) { %>
<a class="mobile-nav-link-a" href="<%- url_for(theme.menu[i]) %>"><%= i %></a>
<% } else { %>
<span class="mobile-nav-link-a"><%= i %></span>
<% } %>
<% }} %>
</ul>
</ul>

View File

@ -1,5 +1,5 @@
<div class="archive-container">
<%- partial('_partial/header', {}, { cache: false }) %>
<%- partial('_partial/header', {}, { cache: true }) %>
<hr class="header-hr"/>
<%- partial('_partial/archive', {pagination: config.archive, index: true}) %>
</div>

View File

@ -1,5 +1,5 @@
<div class="archive-container">
<%- partial('_partial/header', {}, { cache: false }) %>
<%- partial('_partial/header', {}, { cache: true }) %>
<hr class="header-hr"/>
<h2>Recent posts:</h2>
<%- list_posts({

View File

@ -55,3 +55,15 @@ if (document.location.hostname.endsWith('.onion')) {
form.setAttribute('action', 'https://3g2upl4pq6kufc4m.onion/')
})
}
// Remove navigation link of current page
const navLink = document.querySelectorAll('a.main-nav-link, a.mobile-nav-link-a')
navLink.forEach((ele) => {
const eleHref = new URL(ele.href)
if (eleHref.pathname === document.location.pathname) {
const span = document.createElement('span')
span.className = ele.className
span.textContent = ele.textContent
ele.outerHTML = span.outerHTML
}
})