Skip to content

Commit

Permalink
fix/refactor(path): fix subdir error & refactor url concatenation
Browse files Browse the repository at this point in the history
 - Use "url_for(path)" instead of "config.root + path" (ref: https://hexo.io/docs/helpers.html ).
 - Fix 404 error when site is in a subdirectory.
Closes iblh#420
  • Loading branch information
bloodtox3710 authored and EYHN committed Jul 24, 2017
1 parent 67092e7 commit 636206b
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions layout/_partial/Isolation-post_entry.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Post Header Info -->
<div class="post_entry-header_info without-thumbnail">
<!-- Author Avatar & Name -->
<img src="<%= theme.img.avatar %>" class="avatar-img" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<img src="<%= url_for(theme.img.avatar) %>" class="avatar-img" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<span class="name-span"><%= config.author %></span>
</div>
Expand All @@ -14,7 +14,7 @@
<!-- Post Header Info -->
<div class="post_entry-header_info with-thumbnail">
<!-- Author Avatar & Name -->
<img src="<%= theme.img.avatar %>" class="avatar-img" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<img src="<%= url_for(theme.img.avatar) %>" class="avatar-img" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<span class="name-span"><%= config.author %></span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion layout/_partial/Paradox-post-info.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- Author Avatar -->
<div id="author-avatar">
<img src="<%- theme.img.avatar %>" width="44px" height="44px" alt="Author Avatar"/>
<img src="<%- url_for(theme.img.avatar) %>" width="44px" height="44px" alt="Author Avatar"/>
</div>
<!-- Author Name & Date -->
<div>
Expand Down
2 changes: 1 addition & 1 deletion layout/_partial/Paradox-post-thumbnail.ejs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script type="text/ls-javascript" id="post-thumbnail-script">
var randomNum = Math.floor(Math.random() * <%= theme.thumbnail.random_amount %> + 1);
$('.post_thumbnail-random').attr('data-original', '<%= theme.img.random_thumbnail %>' + randomNum + '.png');
$('.post_thumbnail-random').attr('data-original', '<%= url_for(theme.img.random_thumbnail) %>' + randomNum + '.png');
$('.post_thumbnail-random').addClass('lazy');
</script>
2 changes: 1 addition & 1 deletion layout/_partial/Paradox-post_entry-thumbnail.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
randomNum = Math.floor(Math.random() * <%= theme.thumbnail.random_amount %> + 1);
locatePost.children('.post_thumbnail-random').attr('id', 'random_thumbnail-'+randomNum);
locatePost.children('.post_thumbnail-random').attr('data-original', '<%= theme.img.random_thumbnail %>' + randomNum + '.png');
locatePost.children('.post_thumbnail-random').attr('data-original', '<%= url_for(theme.img.random_thumbnail) %>' + randomNum + '.png');
$('.post_thumbnail-random').addClass('lazy');
locatePost = locatePost.next();
Expand Down
2 changes: 1 addition & 1 deletion layout/_partial/Paradox-post_entry.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<div id="post_entry-left-info" class="mdl-card__supporting-text meta mdl-color-text--grey-600 ">
<!-- Author Avatar -->
<div id="author-avatar">
<img src="<%= theme.img.avatar %>" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<img src="<%= url_for(theme.img.avatar) %>" width="44px" height="44px" alt="<%= config.author %>'s avatar">
</div>
<div>
<strong><%= config.author %></strong>
Expand Down
16 changes: 8 additions & 8 deletions layout/_partial/blog_info.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- LOGO -->
<div class="something-else-logo mdl-color--white mdl-color-text--grey-600">
<a href="<%= theme.url.logo || '#' %>" target="_blank">
<img src="<%= theme.img.logo %>" alt="logo" />
<img src="<%= url_for(theme.img.logo) %>" alt="logo" />
</a>
</div>

Expand Down Expand Up @@ -60,55 +60,55 @@
<% } %>

<% if(theme.sns_share.weibo === true) { %>
<a class="index_share-link" href="http://service.weibo.com/share/share.php?appkey=&title=<%= config.title %>&url=<%- config.url + config.root %>&pic=&searchPic=false&style=simple" target="_blank">
<a class="index_share-link" href="http://service.weibo.com/share/share.php?appkey=&title=<%= config.title %>&url=<%- config.url %>&pic=<%- config.url + theme.head.favicon %>&searchPic=false&style=simple" target="_blank">
<li class="mdl-menu__item mdl-js-ripple-effect">
<%= __('share.toWeibo') %>
</li>
</a>
<% } %>

<% if(theme.sns_share.twitter === true) { %>
<a class="index_share-link" href="https://twitter.com/intent/tweet?text=<%= config.title %>&url=<%- config.url + config.root %>&via=<%= config.author %>" target="_blank">
<a class="index_share-link" href="https://twitter.com/intent/tweet?text=<%= config.title %>&url=<%- config.url %>&via=<%= config.author %>" target="_blank">
<li class="mdl-menu__item mdl-js-ripple-effect">
<%= __('share.toTwitter') %>
</li>
</a>
<% } %>

<% if(theme.sns_share.facebook === true) { %>
<a class="index_share-link" href="https://www.facebook.com/sharer/sharer.php?u=<%= config.url + url_for(path) %>" target="_blank">
<a class="index_share-link" href="https://www.facebook.com/sharer/sharer.php?u=<%= config.url %>" target="_blank">
<li class="mdl-menu__item mdl-js-ripple-effect">
<%= __('share.toFacebook') %>
</li>
</a>
<% } %>

<% if(theme.sns_share.googleplus === true) { %>
<a class="index_share-link" href="https://plus.google.com/share?url=<%- config.url + config.root %>" target="_blank">
<a class="index_share-link" href="https://plus.google.com/share?url=<%- config.url %>" target="_blank">
<li class="mdl-menu__item mdl-js-ripple-effect">
<%= __('share.toGplus') %>
</li>
</a>
<% } %>

<% if(theme.sns_share.linkedin === true) { %>
<a class="index_share-link" href="https://www.linkedin.com/shareArticle?mini=true&url=<%- config.url + config.root %>&title=<%= config.title %>" target="_blank">
<a class="index_share-link" href="https://www.linkedin.com/shareArticle?mini=true&url=<%- config.url %>&title=<%= config.title %>" target="_blank">
<li class="mdl-menu__item mdl-js-ripple-effect">
<%= __('share.toLinkedIn') %>
</li>
</a>
<% } %>

<% if(theme.sns_share.qq === true) { %>
<a class="post_share-link" href="http://connect.qq.com/widget/shareqq/index.html?site=<%= config.title %>&title=<%= config.title %>&summary=<%= config.description %>&pics=<%- config.url + theme.head.favicon %>&url=<%- config.url + config.root %>" target="_blank">
<a class="post_share-link" href="http://connect.qq.com/widget/shareqq/index.html?site=<%= config.title %>&title=<%= config.title %>&summary=<%= config.description %>&pics=<%- config.url + theme.head.favicon %>&url=<%- config.url %>" target="_blank">
<li class="mdl-menu__item">
<%= __('share.toQQ') %>
</li>
</a>
<% } %>

<% if(theme.sns_share.telegram === true) { %>
<a class="post_share-link" href="https://telegram.me/share/url?url=<%- config.url + config.root %>&text=<%= config.title %>" target="_blank">
<a class="post_share-link" href="https://telegram.me/share/url?url=<%- config.url %>&text=<%= config.title %>" target="_blank">
<li class="mdl-menu__item">
<%= __('share.toTelegram') %>
</li>
Expand Down
6 changes: 3 additions & 3 deletions layout/_partial/config_font.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
font-weight: 400;
src: local('Material Icons'),
local('MaterialIcons-Regular'),
url(<%- config.root %>fonts/MaterialIcons-Regular.woff2) format('woff2'),
url(<%- config.root %>fonts/MaterialIcons-Regular.woff) format('woff'),
url(<%- config.root %>fonts/MaterialIcons-Regular.ttf) format('truetype');
url(<%- url_for('fonts/MaterialIcons-Regular.woff2') %>) format('woff2'),
url(<%- url_for('fonts/MaterialIcons-Regular.woff') %>) format('woff'),
url(<%- url_for('fonts/MaterialIcons-Regular.ttf') %>) format('truetype');
}
</style>
<% } %>
4 changes: 2 additions & 2 deletions layout/_partial/daily_pic.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="mdl-card <% if(theme.card_elevation) { %><%= 'mdl-shadow--' + theme.card_elevation + 'dp' %><% } %> daily-pic mdl-cell mdl-cell--8-col index-top-block">

<!-- Pic & Slogan -->
<div class="mdl-card__media mdl-color-text--grey-50" style="background-image:url(<%= theme.img.daily_pic %>)">
<div class="mdl-card__media mdl-color-text--grey-50" style="background-image:url(<%= url_for(theme.img.daily_pic) %>)">
<p class="index-top-block-slogan"><a href="<%= theme.url.daily_pic %>">
<% if(theme.uiux.slogan) { %>
<% if(Array.isArray(theme.uiux.slogan)) { %>
Expand All @@ -18,7 +18,7 @@
<div class="mdl-card__supporting-text meta mdl-color-text--grey-600">
<!-- Author Avatar -->
<div id="author-avatar">
<img src="<%= theme.img.avatar %>" width="32px" height="32px" alt="avatar">
<img src="<%= url_for(theme.img.avatar) %>" width="32px" height="32px" alt="avatar">
</div>
<div>
<strong><%= config.author %></strong>
Expand Down
24 changes: 12 additions & 12 deletions layout/_partial/head.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
<script>function Queue(){this.dataStore=[];this.offer=b;this.poll=d;this.execNext=a;this.debug=false;this.startDebug=c;function b(e){if(this.debug){console.log("Offered a Queued Function.")}if(typeof e==="function"){this.dataStore.push(e)}else{console.log("You must offer a function.")}}function d(){if(this.debug){console.log("Polled a Queued Function.")}return this.dataStore.shift()}function a(){var e=this.poll();if(e!==undefined){if(this.debug){console.log("Run a Queued Function.")}e()}}function c(){this.debug=true}}var queue=new Queue();</script>
<!-- Favicons -->
<link rel="icon shortcut" type="image/ico" href="<%= theme.head.favicon %>">
<link rel="icon" sizes="192x192" href="<%= theme.head.high_res_favicon %>">
<link rel="apple-touch-icon" href="<%= theme.head.apple_touch_icon %>">
<link rel="icon shortcut" type="image/ico" href="<%= url_for(theme.head.favicon) %>">
<link rel="icon" sizes="192x192" href="<%= url_for(theme.head.high_res_favicon) %>">
<link rel="apple-touch-icon" href="<%= url_for(theme.head.apple_touch_icon) %>">
<!--iOS -->
<meta name="apple-mobile-web-app-title" content="Title">
Expand Down Expand Up @@ -93,7 +93,7 @@
<% } else { %>
<% } %>
<% } %>
<!--[if lte IE 9]>
<link rel="stylesheet" href="/css/ie-blocker.css">
Expand All @@ -120,13 +120,13 @@
<% } %>
<% } else { %>
<%- cssLsload({path:(config.root + 'css/material.min.css'),key:'material_css'}) %>
<%- cssLsload({path:(config.root + 'css/style.min.css'),key:'style_css'}) %>
<%- cssLsload({path:('css/material.min.css'),key:'material_css'}) %>
<%- cssLsload({path:('css/style.min.css'),key:'style_css'}) %>
<% if (theme.prettify.enable){ %>
<% if ( (is_post()) ) { %>
<%- cssLsload({path:(config.root + 'css/prettify.min.css'),key:'prettify_css'}) %>
<%- cssLsload({path:(config.root + 'css/prettify/' + theme.prettify.theme + '.min.css'),key:'prettify_theme'}) %>
<%- cssLsload({path:('css/prettify.min.css'),key:'prettify_css'}) %>
<%- cssLsload({path:('css/prettify/' + theme.prettify.theme + '.min.css'),key:'prettify_theme'}) %>
<% } %>
<% } %>
Expand All @@ -136,7 +136,7 @@
<% if(theme.vendors.fontawesome) { %>
<link rel="preload" href="<%= theme.vendors.fontawesome %>" as="style" onload="this.rel='stylesheet'">
<% } else { %>
<link rel="preload" href="<%= config.root + 'css/fontawesome.min.css' %>" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="<%= url_for('css/fontawesome.min.css') %>" as="style" onload="this.rel='stylesheet'">
<% } %>
<% } %>
Expand All @@ -150,14 +150,14 @@
<% if(theme.vendors.jquery) { %>
<%- jsLsload({path:(theme.vendors.jquery),key:'jq_js'}) %>
<% } else { %>
<%- jsLsload({path:(config.root + 'js/jquery.min.js'),key:'jq_js'}) %>
<%- jsLsload({path:('js/jquery.min.js'),key:'jq_js'}) %>
<% } %>
<!-- The Open Graph protocol -->
<meta property="og:url" content="<%= config.url %>">
<meta property="og:type" content="blog">
<meta property="og:title" content="<% if (title) { %><%= title %> | <% } %><%= config.title %>">
<meta property="og:image" content="<%= theme.head.high_res_favicon %>" />
<meta property="og:image" content="<%= config.url + theme.head.high_res_favicon %>" />
<meta property="og:description" content="<% if(page.description) { %><%= page.description %><% } else if(page.excerpt){ %><%= strip_html(page.excerpt).replace(/^s*/, '').replace(/s*$/, '') %><% } else if (config.description){ %><%= config.description %><% } %>">
<% if(page.tags && page.tags.each) { page.tags.each(function(tag){ %><meta property="og:article:tag" content="<%= tag.name %>"> <% })} %>
Expand All @@ -169,7 +169,7 @@
<!-- The Twitter Card protocol -->
<meta name="twitter:title" content="<% if (title) { %><%= title %> | <% } %><%= config.title %>">
<meta name="twitter:description" content="<% if(page.description) { %><%= page.description %><% } else if(page.excerpt){ %><%= strip_html(page.excerpt).replace(/^s*/, '').replace(/s*$/, '') %><% } else if (config.description){ %><%= config.description %><% } %>">
<meta name="twitter:image" content="<%= theme.head.high_res_favicon %>">
<meta name="twitter:image" content="<%= config.url + theme.head.high_res_favicon %>">
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:url" content="<%= config.url %>" />
Expand Down
8 changes: 4 additions & 4 deletions layout/_partial/import_js.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<% if(theme.vendors.materialcdn) { %>
<%- jsLsload({path:(theme.vendors.materialcdn + '/js/lazyload.min.js'),key:'lazyload_js'}) %>
<% } else { %>
<%- jsLsload({path:(config.root + 'js/lazyload.min.js'),key:'lazyload_js'}) %>
<%- jsLsload({path:('js/lazyload.min.js'),key:'lazyload_js'}) %>
<% } %>

<% if(theme.vendors.materialcdn) { %>
<%- jsLsload({path:(theme.vendors.materialcdn + '/js/js.min.js'),key:'js_js'}) %>
<% } else { %>
<%- jsLsload({path:(config.root + 'js/js.min.js'),key:'js_js'}) %>
<%- jsLsload({path:('js/js.min.js'),key:'js_js'}) %>
<% } %>

<%- partial('_widget/nprogress') %>
Expand All @@ -17,7 +17,7 @@
<% if(theme.vendors.materialcdn) { %>
<%- jsLsload({path:(theme.vendors.materialcdn + '/js/smoothscroll.js'),key:'sm_js'}) %>
<% } else { %>
<%- jsLsload({path:(config.root + 'js/smoothscroll.js'),key:'sm_js'}) %>
<%- jsLsload({path:('js/smoothscroll.js'),key:'sm_js'}) %>
<% } %>
<% } %>

Expand Down Expand Up @@ -64,7 +64,7 @@
<% if(theme.vendors.prettify) { %>
<%- jsLsload({path:(theme.vendors.prettify),key:'prettify_js'}) %>
<% } else { %>
<%- jsLsload({path:(config.root + 'js/prettify.min.js'),key:'prettify_js'}) %>
<%- jsLsload({path:('js/prettify.min.js'),key:'prettify_js'}) %>
<% } %>
<% } %>
<% } %>
Expand Down
4 changes: 2 additions & 2 deletions layout/_partial/post-header.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<!-- Post Header Info -->
<div class="post-header_info without-thumbnail">
<!-- Author Avatar & Name -->
<img src="<%= theme.img.avatar %>" class="avatar-img" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<img src="<%= url_for(theme.img.avatar) %>" class="avatar-img" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<span class="name-span"><%= config.author %></span>
</div>
Expand All @@ -36,7 +36,7 @@
<!-- Post Header Info -->
<div class="post-header_info with-thumbnail">
<!-- Author Avatar & Name -->
<img src="<%= theme.img.avatar %>" class="avatar-img" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<img src="<%= url_for(theme.img.avatar) %>" class="avatar-img" width="44px" height="44px" alt="<%= config.author %>'s avatar">
<span class="name-span"><%= config.author %></span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion layout/_partial/post-info-share.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<!-- Share Weibo -->
<% if(theme.sns_share.weibo === true) { %>
<a class="post_share-link" href="http://service.weibo.com/share/share.php?appkey=&title=<%= page.title %>&url=<%= config.url + url_for(path) %>&pic=&searchPic=false&style=simple" target="_blank">
<a class="post_share-link" href="http://service.weibo.com/share/share.php?appkey=&title=<%= page.title %>&url=<%= config.url + url_for(path) %>&pic=<%- config.url + theme.head.favicon %>&searchPic=false&style=simple" target="_blank">
<li class="mdl-menu__item">
<%= __('share.toWeibo') %>
</li>
Expand Down
4 changes: 2 additions & 2 deletions layout/_partial/post-nav.ejs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="material-nav mdl-color-text--grey-50 mdl-cell mdl-cell--12-col">
<!-- Prev Nav -->
<% if (page.prev) { %>
<a href="<%- config.root %><%- page.prev.path %>" id="post_nav-newer" class="prev-content">
<a href="<%- url_for(page.prev.path) %>" id="post_nav-newer" class="prev-content">
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
<i class="material-icons">arrow_back</i>
</button>
Expand All @@ -15,7 +15,7 @@

<!-- Next Nav -->
<% if (page.next) { %>
<a href="<%- config.root %><%- page.next.path %>" id="post_nav-older" class="next-content">
<a href="<%- url_for(page.next.path) %>" id="post_nav-older" class="next-content">
<%= __('post.older') %>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
Expand Down
4 changes: 2 additions & 2 deletions layout/_partial/sidebar-footer_image.ejs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% for (var i in theme.img.footer_image) { %>
<span id="footer-image">
<a href="<%= theme.img.footer_image[i].link %>" target="_blank" title="<%= i %>">
<img src="<%= theme.img.footer_image[i].src %>" alt="<%= i %>"><!--
<a href="<%= url_for(theme.img.footer_image[i].link) %>" target="_blank" title="<%= i %>">
<img src="<%= url_for(theme.img.footer_image[i].src) %>" alt="<%= i %>"><!--
--></a>
</span>
<% } %>
4 changes: 2 additions & 2 deletions layout/_partial/sidebar-header.ejs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="sidebar-header header-cover" style="background-image: url(<%= theme.img.sidebar_header %>);">
<div class="sidebar-header header-cover" style="background-image: url(<%= url_for(theme.img.sidebar_header) %>);">
<!-- Top bar -->
<div class="top-bar"></div>

Expand All @@ -13,7 +13,7 @@

<!-- Sidebar Avatar -->
<div class="sidebar-image">
<img src="<%= theme.img.avatar %>" alt="<%= config.author %>'s avatar">
<img src="<%= url_for(theme.img.avatar) %>" alt="<%= config.author %>'s avatar">
</div>

<!-- Sidebar Email -->
Expand Down
4 changes: 2 additions & 2 deletions layout/_widget/mathjax.ejs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
});
</script>
<% if(theme.vendors.mathjax) { %>
<script src="<%= theme.vendors.mathjax %>?config=TeX-AMS-MML_HTMLorMML"></script>
<script src="<%= theme.vendors.mathjax + '?config=TeX-AMS-MML_HTMLorMML' %>"></script>
<%}else{%>
<script type="text/javascript" src="<%= config.root %>js/mathjax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="<%= url_for('js/mathjax.js?config=TeX-AMS-MML_HTMLorMML') %>"></script>
<%}%>
2 changes: 1 addition & 1 deletion layout/_widget/nprogress.ejs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if(theme.vendors.nprogress) { %>
<%- jsLsload({path:(theme.vendors.nprogress),key:'np_js'}) %>
<% } else { %>
<%- jsLsload({path:(config.root + 'js/nprogress.js'),key:'np_js'}) %>
<%- jsLsload({path:('js/nprogress.js'),key:'np_js'}) %>
<% } %>

<script type="text/ls-javascript" id="NProgress-script">
Expand Down
Loading

0 comments on commit 636206b

Please sign in to comment.