Words planted in:
Seedlings, 11ty and Blogging

Adding statistics to 11ty


~326 words, about a 2 min read

Last month I stumbled upon Tim Hårek Andreassen's blog stats page and thought it cool enough to open issue #148 as a reminder to add the same to PhotoGabble.

Tim's blog uses the Zola static site generator and therefore made use of the filters built into Zola for discovering the following statistics:

  • Total words written
  • Total posts published
  • Average words per post
  • First Post (linked)
  • Longest Post (linked) with word count
  • Number of posts, total words and average words per post by year
  • Top Tags by posts

I have already written code for "Top Tags" the output of which can be seen at the bottom of the main Photogabble Archive page and I wrote @photogabble/eleventy-plugin-word-stats: a word stats plugin for Eleventy (for more details read A 11ty Reading Time Plugin Quest) which can help with obtaining the other stats.

In order to obtain the other statistics I wrote a filter than reduced an input collection to the following data structure:

interface Data{
    totalWords: number;
    totalItems: number;
    firstItem?: Object;
    longestItem: {
        wordCount: number;
        item?: Object;
    }
    byYear: Map<number, DataByYear>
}

interface DataByYear {
    year: number;
    totalWords: number;
    totalItems: number;
}

This filter didn't actually end up directly using @photogabble/eleventy-plugin-word-stats for obtaining word counts, but it did use the reading-time library it depends upon so that my statistics all came from the same source.

You can see the live output at /stats.

Similar Stories