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" . }}
</head>
<body>
<body itemscope itemtype="https://schema.org/WebPage">
{{ partial "svg-icon-symbols" . }}
<div class="wrapper">

View File

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

View File

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