feat: add structured data annotation to breadcrumb nav (#67)

This commit is contained in:
i7d3v3l0p3r 2021-02-21 00:54:49 +03:00 committed by GitHub
parent 1cf78cea4f
commit e29fa7a327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 16 deletions

View File

@ -5,7 +5,7 @@
{{ partial "head" . }} {{ partial "head" . }}
</head> </head>
<body> <body itemscope itemtype="https://schema.org/WebPage">
{{ partial "svg-icon-symbols" . }} {{ partial "svg-icon-symbols" . }}
<div class="wrapper"> <div class="wrapper">

View File

@ -10,8 +10,9 @@
{{ $parent := .page.Parent }} {{ $parent := .page.Parent }}
{{ if $parent }} {{ if $parent }}
{{ $name := (partial "title" $parent) }} {{ $name := (partial "title" $parent) }}
{{ $value := (printf "<a href='%s'>%s</a> / %s" $parent.RelPermalink $name .value) }} {{ $position := (sub .position 1) }}
{{ template "breadcrumb" dict "page" $parent "value" $value }} {{ $value := (printf "<li itemprop='itemListElement' itemscope itemtype='https://schema.org/ListItem'><a itemscope itemtype='https://schema.org/WebPage' itemprop='item' itemid='%s' href='%s'><span itemprop='name'>%s</span></a><meta itemprop='position' content='%d' /></li><li> / </li>%s" $parent.RelPermalink $parent.RelPermalink $name $position .value) }}
{{ template "breadcrumb" dict "page" $parent "value" $value "position" $position }}
{{ else }} {{ else }}
{{ .value | safeHTML }} {{ .value | safeHTML }}
{{ end }} {{ end }}
@ -19,24 +20,29 @@
{{ $showBreadcrumb := (and (default true .Page.Params.GeekdocBreadcrumb) (default true .Site.Params.GeekdocBreadcrumb)) }} {{ $showBreadcrumb := (and (default true .Page.Params.GeekdocBreadcrumb) (default true .Site.Params.GeekdocBreadcrumb)) }}
{{ $showEdit := (and ($.Scratch.Get "geekdocFilePath") $geekdocRepo $geekdocEditPath) }} {{ $showEdit := (and ($.Scratch.Get "geekdocFilePath") $geekdocRepo $geekdocEditPath) }}
<div class="gdoc-page__header flex flex-wrap justify-between{{ if not $showEdit }} hidden-mobile{{ end }}{{ if (and (not $showBreadcrumb) (not $showEdit)) }} hidden {{ end }}" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> <div class="gdoc-page__header flex flex-wrap
<span> {{ if $showBreadcrumb }} justify-between {{ else }} justify-end {{ end }}
{{if $showBreadcrumb }} {{ if not $showEdit }} hidden-mobile {{ end }}
<span class="breadcrumb"> {{ if (and (not $showBreadcrumb) (not $showEdit)) }} hidden {{ end }}" itemprop="breadcrumb">
<svg class="icon path"><use xlink:href="#path"></use></svg> {{if $showBreadcrumb }}
<div>
<svg class="icon path hidden-mobile"><use xlink:href="#path"></use></svg>
<ol class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
{{ $position := sub (len (split .RelPermalink "/")) 1 }}
{{ $name := (partial "title" .) }} {{ $name := (partial "title" .) }}
{{ template "breadcrumb" dict "page" . "value" $name }} {{ $value := (printf "<li itemprop='itemListElement' itemscope itemtype='https://schema.org/ListItem'><span itemprop='name'>%s</span><meta itemprop='position' content='%d' /></li>" $name $position ) }}
</span> {{ template "breadcrumb" dict "page" . "value" $value "position" $position }}
{{ end }} </ol>
</span> </div>
<span> {{ end }}
{{ if $showEdit }} {{ if $showEdit }}
<div>
<span class="editpage"> <span class="editpage">
<svg class="icon code"><use xlink:href="#code"></use></svg> <svg class="icon code"><use xlink:href="#code"></use></svg>
<a href="{{ $geekdocRepo }}/{{ $geekdocEditPath }}/{{ $.Scratch.Get "geekdocFilePath" }}"> <a href="{{ $geekdocRepo }}/{{ $geekdocEditPath }}/{{ $.Scratch.Get "geekdocFilePath" }}">
Edit this page Edit this page
</a> </a>
</span> </span>
{{ end }} </div>
</span> {{ end }}
</div> </div>

View File

@ -538,3 +538,14 @@ img {
transition-property: transform, margin-left, opacity; transition-property: transform, margin-left, opacity;
will-change: transform, margin-left; will-change: transform, margin-left;
} }
// Breadcrumbs styles
.breadcrumb {
display: inline;
padding: 0;
margin: 0;
li {
display: inline;
}
}