mirror of https://github.com/grpc/grpc.io.git
Add anchor bookmarks (#154)
* Add header links Signed-off-by: lucperkins <lucperkins@gmail.com> * CSS partial housekeeping Signed-off-by: lucperkins <lucperkins@gmail.com> * Add scroll offset Signed-off-by: lucperkins <lucperkins@gmail.com>
This commit is contained in:
parent
0ce986ed93
commit
cf9efbe10d
|
|
@ -285,3 +285,17 @@ $colors: mergeColorMaps(("secondary": ($secondary, $white), "twitter-blue": ($tw
|
|||
|
||||
& + li
|
||||
margin-top: 0.75rem
|
||||
|
||||
.hashlink
|
||||
@extend .icon
|
||||
height: 1rem
|
||||
width: 1rem
|
||||
margin-left: 0.25rem
|
||||
|
||||
.headline-hash
|
||||
display: none
|
||||
|
||||
@for $i from 1 through 6
|
||||
h#{$i}
|
||||
&:hover > .headline-hash
|
||||
display: inline
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{{ $size := .size | default "normal" }}
|
||||
{{ $constrained := .constrained | default false }}
|
||||
<div class="content is-{{ $size }} has-bottom-padding{{ if $constrained }} is-constrained{{ end }}">
|
||||
{{ .content }}
|
||||
{{ partial "headline-hash.html" .content }}
|
||||
</div>
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
{{- $inServerMode := site.IsServer }}
|
||||
{{- $includePaths := (slice "node_modules") }}
|
||||
{{- $sass := "sass/style.sass" }}
|
||||
{{- $cssOutput := "css/style.css" }}
|
||||
{{- $devOpts := (dict "targetPath" $cssOutput "includePaths" $includePaths "enableSourceMap" true) }}
|
||||
{{- $prodOpts := (dict "targetPath" $cssOutput "includePaths" $includePaths "outputStyle" "compressed") }}
|
||||
{{- $cssOpts := cond $inServerMode $devOpts $prodOpts }}
|
||||
{{- $css := resources.Get $sass | resources.ExecuteAsTemplate $sass . | toCSS $cssOpts }}
|
||||
{{- if $inServerMode }}
|
||||
{{ $inServerMode := site.IsServer }}
|
||||
{{ $includePaths := (slice "node_modules") }}
|
||||
{{ $sass := "sass/style.sass" }}
|
||||
{{ $cssOutput := "css/style.css" }}
|
||||
{{ $devOpts := (dict "targetPath" $cssOutput "includePaths" $includePaths "enableSourceMap" true) }}
|
||||
{{ $prodOpts := (dict "targetPath" $cssOutput "includePaths" $includePaths "outputStyle" "compressed") }}
|
||||
{{ $cssOpts := cond $inServerMode $devOpts $prodOpts }}
|
||||
{{ $css := resources.Get $sass | resources.ExecuteAsTemplate $sass . | toCSS $cssOpts }}
|
||||
{{ if $inServerMode }}
|
||||
<link rel="stylesheet" href="{{ $css.RelPermalink }}">
|
||||
{{- else }}
|
||||
{{- $prodCss := $css | fingerprint }}
|
||||
{{ else }}
|
||||
{{ $prodCss := $css | fingerprint }}
|
||||
<link rel="stylesheet" href="{{ $prodCss.RelPermalink }}" integrity="{{ $prodCss.Data.Integrity }}">
|
||||
{{- end }}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
|
||||
{{ end }}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
{{ . | replaceRE "(<h[2-9] id=\"([^\"]+)\".+)(</h[2-9]+>)" `${1} <a class="headline-hash" href="#${2}">
|
||||
<span class="icon hashlink"><i class="fas fa-hashtag"></i></span></a>${3}` | safeHTML }}
|
||||
|
|
@ -9,4 +9,15 @@
|
|||
inputSelector: '#search-bar',
|
||||
debug: false
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
{{/* Anchor link scroll offset */}}
|
||||
<script>
|
||||
const navbarHeight = document.getElementsByClassName('navbar')[0].offsetHeight;
|
||||
const extraPadding = 15;
|
||||
const navbarOffset = -1 * (navbarHeight + extraPadding);
|
||||
var shiftWindow = function() { scrollBy(0, navbarOffset) };
|
||||
window.addEventListener("hashchange", shiftWindow);
|
||||
window.addEventListener("pageshow", shiftWindow);
|
||||
function load() { if (window.location.hash) shiftWindow(); }
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue