From 545a122d6c17a541cc161b9660a1d590d7edf52d Mon Sep 17 00:00:00 2001 From: Track3 <34504964+Track3@users.noreply.github.com> Date: Sun, 27 Jan 2019 12:20:29 +0800 Subject: [PATCH] Add anchor links to heading (#38) * Closes #36 --- assets/scss/style.scss | 34 +++++++++++++++++++ layouts/_default/single.html | 2 +- layouts/posts/single.html | 2 +- ...s_c16d144eee185fbddd582cd5e25a4fae.content | 2 +- ...scss_c16d144eee185fbddd582cd5e25a4fae.json | 2 +- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/assets/scss/style.scss b/assets/scss/style.scss index 12d550c..3aa5ea4 100644 --- a/assets/scss/style.scss +++ b/assets/scss/style.scss @@ -22,6 +22,7 @@ html { background: $light-grey; line-height: 1.6; letter-spacing: .06em; + scroll-behavior: smooth; } body, @@ -534,6 +535,39 @@ hr.post-end { padding: 0; margin-left: 1.8em; } + + a.anchor { + float: left; + margin-left: -20px; + padding-right: 6px; + box-shadow: none; + opacity: .8; + &:hover { + background: none; + color: $theme; + opacity: 1; + } + + svg { + display: inline-block; + width: 14px; + height: 14px; + vertical-align: baseline; + visibility: hidden; + } + &:focus svg { + visibility: visible; + } + } + + h1:hover a.anchor svg, + h2:hover a.anchor svg, + h3:hover a.anchor svg, + h4:hover a.anchor svg, + h5:hover a.anchor svg, + h6:hover a.anchor svg { + visibility: visible; + } } .footnotes { diff --git a/layouts/_default/single.html b/layouts/_default/single.html index cef2cba..9ba7177 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -19,7 +19,7 @@

{{ .Title }}

- {{ .Content }} + {{ .Content | replaceRE "()" `${1}${3}` | safeHTML }}
{{- if .Params.comments }}
diff --git a/layouts/posts/single.html b/layouts/posts/single.html index e4fc4e4..9557916 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -23,7 +23,7 @@

{{ .Title }}

- {{ .Content }} + {{ .Content | replaceRE "()" `${1}${3}` | safeHTML }}