From 219adffe10b40b4f652de1535df4037d0ab2f869 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 7 Aug 2020 10:38:32 +0800 Subject: [PATCH] Optimize canonical URL --- layout/_partials/head/head-unique.njk | 7 ++++++- layout/_partials/page/breadcrumb.njk | 8 +++----- layout/_third-party/quicklink.njk | 2 +- scripts/events/lib/vendors.js | 2 +- scripts/helpers/engine.js | 26 +++++++------------------- 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/layout/_partials/head/head-unique.njk b/layout/_partials/head/head-unique.njk index 7aa830868..54249091b 100644 --- a/layout/_partials/head/head-unique.njk +++ b/layout/_partials/head/head-unique.njk @@ -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 %} + {# Exports some front-matter variables to Front-End #} diff --git a/layout/_partials/page/breadcrumb.njk b/layout/_partials/page/breadcrumb.njk index 267617f0a..4405b6557 100644 --- a/layout/_partials/page/breadcrumb.njk +++ b/layout/_partials/page/breadcrumb.njk @@ -1,13 +1,11 @@ {%- set paths = page.path.split('/') %} {%- set count = paths.length %} {%- if count > 2 %} - {%- set current = 0 %} {%- set link = '' %}