From 056d4389ab2ec8d876d3607a2283965b62f662b3 Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Tue, 23 Feb 2021 07:48:56 +0000 Subject: [PATCH] feat(theme-nav): remove nav link for current page - reimplement in js, avoid disabling hexo layout caching - revert f9889702b7222cc56274807d135ab96090a2c490 --- themes/chameleon/layout/_partial/article.ejs | 2 +- themes/chameleon/layout/_partial/header.ejs | 8 -------- themes/chameleon/layout/archive.ejs | 2 +- themes/chameleon/layout/index.ejs | 2 +- themes/chameleon/source/js/chameleon.js | 12 ++++++++++++ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/themes/chameleon/layout/_partial/article.ejs b/themes/chameleon/layout/_partial/article.ejs index 63f12a6..f447a0a 100644 --- a/themes/chameleon/layout/_partial/article.ejs +++ b/themes/chameleon/layout/_partial/article.ejs @@ -1,5 +1,5 @@
- <%- partial('_partial/header', {}, { cache: false }) %> + <%- partial('_partial/header', {}, { cache: true }) %>
<%- partial('post/gallery') %> diff --git a/themes/chameleon/layout/_partial/header.ejs b/themes/chameleon/layout/_partial/header.ejs index 980ba99..6853920 100644 --- a/themes/chameleon/layout/_partial/header.ejs +++ b/themes/chameleon/layout/_partial/header.ejs @@ -4,11 +4,7 @@ <% if (!theme.menu) { %>Home <% } else { %> <% for (const i in theme.menu) { %> - <% if (url_for(theme.menu[i]) !== url_for(page.path)) { %> <%= i %> - <% } else { %> - <%= i %> - <% } %> <% }} %>
@@ -55,11 +51,7 @@ <% if (!theme.menu) { %>Home <% } else { %> <% for (const i in theme.menu) { %> - <% if (url_for(theme.menu[i]) !== url_for(page.path)) { %> <%= i %> - <% } else { %> - <%= i %> - <% } %> <% }} %> diff --git a/themes/chameleon/layout/archive.ejs b/themes/chameleon/layout/archive.ejs index 62bf1a8..7867541 100644 --- a/themes/chameleon/layout/archive.ejs +++ b/themes/chameleon/layout/archive.ejs @@ -1,5 +1,5 @@
- <%- partial('_partial/header', {}, { cache: false }) %> + <%- partial('_partial/header', {}, { cache: true }) %>
<%- partial('_partial/archive', {pagination: config.archive, index: true}) %>
diff --git a/themes/chameleon/layout/index.ejs b/themes/chameleon/layout/index.ejs index 5a80b3b..830fc33 100644 --- a/themes/chameleon/layout/index.ejs +++ b/themes/chameleon/layout/index.ejs @@ -1,5 +1,5 @@
- <%- partial('_partial/header', {}, { cache: false }) %> + <%- partial('_partial/header', {}, { cache: true }) %>

Recent posts:

<%- list_posts({ diff --git a/themes/chameleon/source/js/chameleon.js b/themes/chameleon/source/js/chameleon.js index 3ebf581..70686cc 100644 --- a/themes/chameleon/source/js/chameleon.js +++ b/themes/chameleon/source/js/chameleon.js @@ -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 + } +})