diff --git a/exampleSite/content/home/tags.md b/exampleSite/content/home/tags.md new file mode 100644 index 00000000..cedab850 --- /dev/null +++ b/exampleSite/content/home/tags.md @@ -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 + ++++ diff --git a/exampleSite/content/post/widgets.md b/exampleSite/content/post/widgets.md index 6f411da0..fbe9f6f7 100644 --- a/exampleSite/content/post/widgets.md +++ b/exampleSite/content/post/widgets.md @@ -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. diff --git a/layouts/partials/widgets/tag_cloud.html b/layouts/partials/widgets/tag_cloud.html new file mode 100644 index 00000000..8b4965c0 --- /dev/null +++ b/layouts/partials/widgets/tag_cloud.html @@ -0,0 +1,35 @@ +{{ $ := .root }} +{{ $page := .page }} + +
+
+

{{ with $page.Title }}{{ . | markdownify }}{{ end }}

+ {{ with $page.Params.subtitle }}

{{ . | markdownify }}

{{ end }} +
+
+ {{ with $page.Content }}

{{ . | markdownify }}

{{ 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 }} + +
+ {{ 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 }} + {{ $name }} + {{ end }} +
+ {{ end }} + +
+