当前文章锚点跳转

使用 markdown 内置的链接方式即可,其中如果有空格,需要把空格换成连字符 - ,如下:

1
[跳转到本文锚点](#hexo-标题与-id-关系)

站内文章链接

官方有标签插件实现站内文章链接,如下:

1
post_link官方文档{% post_link 'hexo blog' %}

注意: 这儿优先使用文章 Front-matter 中的permalink字段,如果没有 permalink ,则使用 文件名字

站内其他文章锚点链接

上面的 post_link 方式链接站内文章好用,但是不支持文章的锚点链接,我们需要换一种方式。

官方文档还有一个 post_path ,用于获取文章路径,结合 markdown 内置的链接方式,即可实现锚点超链接,如下:

1
post_path官方文档[hexo 安装]({% post_path 'hexo blog' %}#安装)

也可以使用 html <a> 标签实现,如下:

1
<a href="{% post_path 'hexo blog' %}#安装">hexo 安装</a>

注意:

  1. 如果文章中有图片,可能会出现锚点位置不准确问题,原因是图片加载成功之后会把内容高度撑开。
  2. 如果如果有空格,需要把空格换成连字符 -。

站外文章锚点

直接使用全路径即可,如下:

1
[hexo 引用文章](https://hexo.io/zh-cn/docs/tag-plugins#%E5%BC%95%E7%94%A8%E6%96%87%E7%AB%A0)

注意
要设置anchors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
markdown:
anchors:
# Minimum level for ID creation. (Ex. h2 to h6)
level: 2
# A suffix that is prepended to the number given if the ID is repeated.
collisionSuffix: ''
# If `true`, creates an anchor tag with a permalink besides the heading.
permalink: true
# Class used for the permalink anchor tag.
permalinkClass: header-anchor
# Set to 'right' to add permalink after heading
permalinkSide: 'right'
# The symbol used to make the permalink
permalinkSymbol:
# Transform anchor to (1) lower case; (2) upper case
case: 1
# Replace space with a character
separator: '-'

参考链接:https://augu1sto.gitee.io/9395aea8f2ae/