Skip to content

Commit

Permalink
Use render-heading to implement self links (grpc#458)
Browse files Browse the repository at this point in the history
Closes grpc#443
  • Loading branch information
chalin authored Oct 13, 2020
1 parent 16192e4 commit f31fedf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
17 changes: 6 additions & 11 deletions assets/sass/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,14 @@ $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
.heading-self-link
@extend .is-hidden-desktop // On touch devices, always show self-link
margin-left: .3rem

@for $i from 1 through 6
h#{$i}
&:hover > .headline-hash
display: inline
h#{$i}[id]
&:hover > .heading-self-link
display: initial !important

// 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
Expand Down
3 changes: 3 additions & 0 deletions layouts/_default/_markup/render-heading.html
Original file line number Diff line number Diff line change
@@ -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 }}>
6 changes: 3 additions & 3 deletions layouts/partials/content.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ $size := .size | default "normal" }}
{{ $constrained := .constrained | default false }}
{{ $size := .size | default "normal" -}}
{{ $constrained := .constrained | default false -}}
<div class="content is-{{ $size }} has-bottom-padding{{ if $constrained }} is-constrained{{ end }}">
{{ partial "headline-hash.html" .content }}
{{ .content }}
</div>
4 changes: 2 additions & 2 deletions layouts/partials/docs/article.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ $desc := .Params.description }}
{{ $source := printf "https://github.com/grpc/grpc.io/tree/%s/content/%s" $.Site.Params.branch .File.Path }}
{{ $desc := .Params.description -}}
{{ $source := printf "https://github.com/grpc/grpc.io/tree/%s/content/%s" $.Site.Params.branch .File.Path -}}
<section class="section">
<div class="container">
<div class="columns is-variable is-8">
Expand Down
2 changes: 0 additions & 2 deletions layouts/partials/headline-hash.html

This file was deleted.

9 changes: 4 additions & 5 deletions layouts/partials/navbar-menu.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ $menu := site.Menus.main -}}

{{ range $menu -}}
{{ range $menu }}
{{ $name := .Name -}}
{{ if .HasChildren -}}
{{ $url := .URL | relLangURL -}}
Expand All @@ -11,9 +11,8 @@
<i class="fas fa-caret-down"></i>
</span>
</a>

<div class="navbar-dropdown">
{{ range .Children -}}
{{- range .Children }}
{{ $name := .Name -}}
{{ $url := .URL -}}
{{ $isExternal := hasPrefix .URL "http" -}}
Expand All @@ -25,7 +24,7 @@
<span class="icon has-text-secondary">
<i class="fas fa-sm fa-external-link-alt"></i>
</span>
{{- end }}
{{- end -}}
</a>
{{- end }}
</div>
Expand All @@ -42,7 +41,7 @@
<span class="icon has-text-secondary">
<i class="fas fa-xs fa-external-link-alt"></i>
</span>
{{- end }}
{{- end -}}
</a>
{{- end }}
{{- end -}}

0 comments on commit f31fedf

Please sign in to comment.