Use render-heading to implement self links (#458)

Closes #443
This commit is contained in:
Patrice Chalin 2020-10-13 17:41:07 -04:00 committed by GitHub
parent 16192e4c0b
commit f31fedf425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 23 deletions

View File

@ -297,19 +297,14 @@ $colors: mergeColorMaps(("secondary": ($secondary, $white), "twitter-blue": ($tw
& + li & + li
margin-top: 0.75rem margin-top: 0.75rem
.hashlink .heading-self-link
@extend .icon @extend .is-hidden-desktop // On touch devices, always show self-link
height: 1rem margin-left: .3rem
width: 1rem
margin-left: 0.25rem
.headline-hash
display: none
@for $i from 1 through 6 @for $i from 1 through 6
h#{$i} h#{$i}[id]
&:hover > .headline-hash &:hover > .heading-self-link
display: inline display: initial !important
// Currently (2020-05-29), the external-link character is used as an icon in the // Currently (2020-05-29), the external-link character is used as an icon in the
// top navbar. The "a >" prefix is used in the next rule only as a simple means // top navbar. The "a >" prefix is used in the next rule only as a simple means

View File

@ -0,0 +1,3 @@
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
{{- .Text | safeHTML -}}
<a aria-hidden="true" class="heading-self-link is-size-5-touch" href="#{{ .Anchor | safeURL }}"><i class="fas fa-hashtag"></i></a></h{{ .Level }}>

View File

@ -1,5 +1,5 @@
{{ $size := .size | default "normal" }} {{ $size := .size | default "normal" -}}
{{ $constrained := .constrained | default false }} {{ $constrained := .constrained | default false -}}
<div class="content is-{{ $size }} has-bottom-padding{{ if $constrained }} is-constrained{{ end }}"> <div class="content is-{{ $size }} has-bottom-padding{{ if $constrained }} is-constrained{{ end }}">
{{ partial "headline-hash.html" .content }} {{ .content }}
</div> </div>

View File

@ -1,5 +1,5 @@
{{ $desc := .Params.description }} {{ $desc := .Params.description -}}
{{ $source := printf "https://github.com/grpc/grpc.io/tree/%s/content/%s" $.Site.Params.branch .File.Path }} {{ $source := printf "https://github.com/grpc/grpc.io/tree/%s/content/%s" $.Site.Params.branch .File.Path -}}
<section class="section"> <section class="section">
<div class="container"> <div class="container">
<div class="columns is-variable is-8"> <div class="columns is-variable is-8">

View File

@ -1,2 +0,0 @@
{{ . | 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 }}

View File

@ -1,6 +1,6 @@
{{ $menu := site.Menus.main -}} {{ $menu := site.Menus.main -}}
{{ range $menu -}} {{ range $menu }}
{{ $name := .Name -}} {{ $name := .Name -}}
{{ if .HasChildren -}} {{ if .HasChildren -}}
{{ $url := .URL | relLangURL -}} {{ $url := .URL | relLangURL -}}
@ -11,9 +11,8 @@
<i class="fas fa-caret-down"></i> <i class="fas fa-caret-down"></i>
</span> </span>
</a> </a>
<div class="navbar-dropdown"> <div class="navbar-dropdown">
{{ range .Children -}} {{- range .Children }}
{{ $name := .Name -}} {{ $name := .Name -}}
{{ $url := .URL -}} {{ $url := .URL -}}
{{ $isExternal := hasPrefix .URL "http" -}} {{ $isExternal := hasPrefix .URL "http" -}}
@ -25,7 +24,7 @@
<span class="icon has-text-secondary"> <span class="icon has-text-secondary">
<i class="fas fa-sm fa-external-link-alt"></i> <i class="fas fa-sm fa-external-link-alt"></i>
</span> </span>
{{- end }} {{- end -}}
</a> </a>
{{- end }} {{- end }}
</div> </div>
@ -42,7 +41,7 @@
<span class="icon has-text-secondary"> <span class="icon has-text-secondary">
<i class="fas fa-xs fa-external-link-alt"></i> <i class="fas fa-xs fa-external-link-alt"></i>
</span> </span>
{{- end }} {{- end -}}
</a> </a>
{{- end }} {{- end }}
{{- end -}} {{- end -}}