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