Skip to content

Commit

Permalink
perf: optimize root path jump
Browse files Browse the repository at this point in the history
  • Loading branch information
XPoet committed Nov 29, 2023
1 parent 23d6283 commit 046c3f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion layout/_partial/footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const web_master = bi_author || hexo_author
<div class="copyright-info info-item <%= footer_style_type %>">
&copy;&nbsp;<% if (f_since) { %><span><%= f_since %></span>&nbsp;-&nbsp;<% } %><%= date(new Date(), 'YYYY') %>
<% if (web_master) { %>
&nbsp;<i class="fas fa-heart icon-animate"></i>&nbsp;&nbsp;<a href="/"><%= web_master %></a>
&nbsp;<i class="fas fa-heart icon-animate"></i>&nbsp;&nbsp;<a href="<%- url_for('/') %>"><%= web_master %></a>
<% } %>
</div>
Expand Down
30 changes: 21 additions & 9 deletions layout/_partial/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,38 @@
const { title: bi_title, logo: bi_logo } = theme?.base_info || {}
const { enable: s_fs_enable } = theme?.first_screen || {}
const { enable: local_search_enable } = theme?.local_search || {}
const h_menu_nav_object = theme?.menu || { Home: '/', Archives: '/archives' }
const h_menu_nav_object = theme?.menu || { Archives: '/archives' }
delete h_menu_nav_object['home']
delete h_menu_nav_object['Home']
delete h_menu_nav_object['HOME']
%>
<header class="header-wrapper<%= s_fs_enable === true && is_home() ? ' transparent-1' : '' %>">
<div class="border-box header-content<%- (s_fs_enable === true && is_home() && !page.prev) ? ' has-first-screen' : '' %>">
<div class="left border-box">
<% if (bi_logo) { %>
<a class="logo-image border-box" href="<%- url_for(h_menu_nav_object['Home']) %>">
<a class="logo-image border-box" href="<%- url_for('/') %>">
<%- image_tag(bi_logo) %>
</a>
<% } %>
<a class="site-name border-box" href="<%- url_for(h_menu_nav_object['Home']) %>">
<a class="site-name border-box" href="<%- url_for('/') %>">
<%= bi_title || config?.title || 'Keep Theme' %>
</a>
</div>
<div class="right border-box">
<div class="pc">
<ul class="menu-list">
<li class="menu-item">
<a class="<%- is_home() ? 'active' : '' %>"
href="<%- url_for('/') %>"
><%= __('home').toUpperCase() %></a>
</li>
<% for (const i in h_menu_nav_object) { %>
<li class="menu-item">
<a class="<%- isInHomePaging(page.path, h_menu_nav_object[i]) ? 'active' : is_current(h_menu_nav_object[i]) ? 'active' : '' %>"
<a class="<%- is_current(h_menu_nav_object[i]) ? 'active' : '' %>"
href="<%- url_for(h_menu_nav_object[i]) %>"
>
<%= __(i.toLowerCase()).toUpperCase() %>
</a>
><%= __(i.toLowerCase()).toUpperCase() %></a>
</li>
<% } %>
<% if (local_search_enable === true) { %>
Expand All @@ -50,10 +56,16 @@ const h_menu_nav_object = theme?.menu || { Home: '/', Archives: '/archives' }
<div class="header-drawer">
<ul class="drawer-menu-list">
<li class="drawer-menu-item flex-center">
<a class="<%- is_home() ? 'active' : '' %>"
href="<%- url_for('/') %>"
><%= __('home').toUpperCase() %></a>
</li>
<% for (let i in h_menu_nav_object) { %>
<li class="drawer-menu-item flex-center">
<a class="<%- isInHomePaging(page.path, h_menu_nav_object[i]) ? 'active' : is_current(h_menu_nav_object[i]) ? 'active' : '' %>"
href="<%- url_for(h_menu_nav_object[i]) %>"><%= __(i.toLowerCase()).toUpperCase() %></a>
<a class="<%- is_current(h_menu_nav_object[i]) ? 'active' : '' %>"
href="<%- url_for(h_menu_nav_object[i]) %>"
><%= __(i.toLowerCase()).toUpperCase() %></a>
</li>
<% } %>
</ul>
Expand Down
8 changes: 0 additions & 8 deletions scripts/helpers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

'use strict'

hexo.extend.helper.register('isInHomePaging', function (pagePath, route) {
if (pagePath.length > 5 && route === '/') {
return pagePath.slice(0, 5) === 'page/'
} else {
return false
}
})

hexo.extend.helper.register('createNewArchivePosts', function (posts) {
const postList = [],
postYearList = []
Expand Down

0 comments on commit 046c3f1

Please sign in to comment.