mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-26 03:00:50 +02:00
widgets: Add tag cloud
This commit is contained in:
parent
fcdf9b887f
commit
e6d4bd3e5f
3 changed files with 50 additions and 0 deletions
14
exampleSite/content/home/tags.md
Normal file
14
exampleSite/content/home/tags.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
+++
|
||||
# Tag Cloud widget.
|
||||
|
||||
date = 2017-09-20
|
||||
draft = false
|
||||
|
||||
title = "Tags"
|
||||
subtitle = ""
|
||||
widget = "tag_cloud"
|
||||
|
||||
# Order that this section will appear in.
|
||||
weight = 65
|
||||
|
||||
+++
|
|
@ -19,6 +19,7 @@ Homepage widgets display as sections on the homepage. They can be enabled/disabl
|
|||
- Selected talks
|
||||
- Recent talks
|
||||
- Contact
|
||||
- Tag cloud
|
||||
- Custom widget (demonstrated with the *teaching* example)
|
||||
|
||||
The example site that you copied to create your site uses all the different types of widget (except talks), so you can generally just delete the widgets you don't need and customize the parameters of the widgets you wish to keep.
|
||||
|
|
35
layouts/partials/widgets/tag_cloud.html
Normal file
35
layouts/partials/widgets/tag_cloud.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{{ $ := .root }}
|
||||
{{ $page := .page }}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-4 section-heading">
|
||||
<h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
|
||||
{{ with $page.Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-8">
|
||||
{{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}
|
||||
|
||||
{{ if not (eq (len $.Site.Taxonomies.tags) 0) }}
|
||||
{{ $fontSmall := 0.8 }}
|
||||
{{ $fontBig := 2.5 }}
|
||||
|
||||
{{ $fontDelta := sub $fontBig $fontSmall }}
|
||||
{{ $min := len (index $.Site.Taxonomies.tags.ByCount.Reverse 0).Pages }}
|
||||
{{ $max := add (len (index $.Site.Taxonomies.tags.ByCount 0).Pages) 1 }}
|
||||
{{ $delta := sub $max $min }}
|
||||
{{ $fontStep := div $fontDelta $delta }}
|
||||
|
||||
<div id="tag-cloud">
|
||||
{{ range $name, $taxonomy := $.Site.Taxonomies.tags }}
|
||||
{{ $tagCount := len $taxonomy.Pages }}
|
||||
{{ $weight := div (sub (math.Log $tagCount) (math.Log $min)) (sub (math.Log $max) (math.Log $min)) }}
|
||||
{{ $fontSize := add $fontSmall (mul (sub $fontBig $fontSmall) $weight) }}
|
||||
{{ $urlPart1 := relLangURL "/tags/" }}
|
||||
{{ $urlPart2 := urlize $name }}
|
||||
<a href="{{ delimit (slice $urlPart1 $urlPart2) "" }}" style="font-size:{{ $fontSize }}rem">{{ $name }}</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
</div>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue