mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Optimize canonical URL
This commit is contained in:
parent
f76c0d8a97
commit
219adffe10
@ -1,6 +1,11 @@
|
||||
{{ open_graph() }}
|
||||
|
||||
{{ canonical() }}
|
||||
{# https://github.com/theme-next/hexo-theme-next/issues/866 #}
|
||||
{%- set canonical = url | replace(r/index\.html$/, '') %}
|
||||
{%- if not config.permalink.endsWith('.html') %}
|
||||
{%- set canonical = canonical | replace(r/\.html$/, '') %}
|
||||
{%- endif %}
|
||||
<link rel="canonical" href="{{ canonical }}">
|
||||
|
||||
{# Exports some front-matter variables to Front-End #}
|
||||
<script{{ pjax }} class="page-configurations">
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
{%- set paths = page.path.split('/') %}
|
||||
{%- set count = paths.length %}
|
||||
{%- if count > 2 %}
|
||||
{%- set current = 0 %}
|
||||
{%- set link = '' %}
|
||||
<ul class="breadcrumb">
|
||||
{%- for path in paths %}
|
||||
{%- set current = current + 1 %}
|
||||
{%- if path != 'index.html' %}
|
||||
{%- if current == count - 1 and paths[count - 1] == 'index.html' %}
|
||||
{%- if loop.index == count - 1 and paths[loop.index] == 'index.html' %}
|
||||
<li>{{ path | upper }}</li>
|
||||
{% else %}
|
||||
{%- if link == '' %}
|
||||
@ -15,8 +13,8 @@
|
||||
{% else %}
|
||||
{%- set link = link + '/' + path %}
|
||||
{%- endif %}
|
||||
{%- if path.includes('.html') %}
|
||||
<li>{{ path | replace('.html', '') | upper }}</li>
|
||||
{%- if path.endsWith('.html') %}
|
||||
<li>{{ path | replace(r/\.html$/, '') | upper }}</li>
|
||||
{% else %}
|
||||
<li><a href="{{ url_for(link) }}/">{{ path | upper }}</a></li>
|
||||
{%- endif %}
|
||||
|
||||
2
layout/_third-party/quicklink.njk
vendored
2
layout/_third-party/quicklink.njk
vendored
@ -7,7 +7,7 @@
|
||||
quicklink.listen({
|
||||
timeout : {{ page.quicklink.timeout }},
|
||||
priority: {{ page.quicklink.priority }},
|
||||
ignores : [uri => uri.includes('#'),uri => uri === '{{ url | replace('index.html', '') }}',{{ page.quicklink.ignores }}]
|
||||
ignores : [uri => uri.includes('#'),uri => uri === '{{ url | replace(r/index\.html$/, '') }}',{{ page.quicklink.ignores }}]
|
||||
});
|
||||
{%- if page.quicklink.delay %}
|
||||
});
|
||||
|
||||
@ -32,6 +32,6 @@ module.exports = hexo => {
|
||||
let { plugins = 'jsdelivr' } = vendors;
|
||||
if (plugins === 'cdnjs' && unavailable && unavailable.includes('cdnjs')) plugins = 'jsdelivr';
|
||||
if (plugins === 'local' && typeof internal === 'undefined') plugins = 'jsdelivr';
|
||||
vendors[key] = links[plugins];
|
||||
vendors[key] = links[plugins] || links.jsdelivr;
|
||||
}
|
||||
};
|
||||
|
||||
@ -15,16 +15,15 @@ hexo.extend.helper.register('next_inject', function(point) {
|
||||
.join('');
|
||||
});
|
||||
|
||||
hexo.extend.helper.register('next_js', function(url, pjax = false) {
|
||||
hexo.extend.helper.register('next_js', function(file, pjax = false) {
|
||||
const { next_version } = this;
|
||||
const { js } = this.theme;
|
||||
const { internal } = this.theme.vendors;
|
||||
let src = this.url_for(`${js}/${url}`);
|
||||
if (internal === 'jsdelivr') {
|
||||
src = `//cdn.jsdelivr.net/npm/hexo-theme-next@${next_version}/source/js/${url}`;
|
||||
} else if (internal === 'unpkg') {
|
||||
src = `//unpkg.com/hexo-theme-next@${next_version}/source/js/${url}`;
|
||||
}
|
||||
const links = {
|
||||
local : this.url_for(`${this.theme.js}/${file}`),
|
||||
jsdelivr: `//cdn.jsdelivr.net/npm/hexo-theme-next@${next_version}/source/js/${file}`,
|
||||
unpkg : `//unpkg.com/hexo-theme-next@${next_version}/source/js/${file}`
|
||||
};
|
||||
const src = links[internal] || links.local;
|
||||
return `<script ${pjax ? 'data-pjax ' : ''}src="${src}"></script>`;
|
||||
});
|
||||
|
||||
@ -59,20 +58,9 @@ hexo.extend.helper.register('post_nav', function(post) {
|
||||
|
||||
hexo.extend.helper.register('gitalk_md5', function(path) {
|
||||
const str = this.url_for(path);
|
||||
str.replace('index.html', '');
|
||||
return crypto.createHash('md5').update(str).digest('hex');
|
||||
});
|
||||
|
||||
hexo.extend.helper.register('canonical', function() {
|
||||
// https://support.google.com/webmasters/answer/139066
|
||||
const { permalink } = hexo.config;
|
||||
let url = this.url.replace(/index\.html$/, '');
|
||||
if (!permalink.endsWith('.html')) {
|
||||
url = url.replace(/\.html$/, '');
|
||||
}
|
||||
return `<link rel="canonical" href="${url}">`;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get page path given a certain language tag
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user