Word Count

Sunday 10 March 2013

What's the point of writing your own blogging platform if you're just going to serve static content?

The articles on this site are written as templates. When a page is requested the article is retrieved from the datastore and the template is executed. The result is cached and returned as the response. The template mechanism allows the site to automatically update content.

As a basic first example, consider counting the number of words in every article:

re := regexp.MustCompile(`\S*`) //not whitespace
m := re.FindAll([]byte("How many words are there here?"), -1)
This is a pretty naive way of counting words. It will include HTML and template markup. Invoking the entire regular expression engine just to count words (and returning each word separately) is overkill. Nevertheless, the simplicity of the code counts for a lot.

So far the word count is 12320.

Previous (N Queens)
Next (Three-body Problem)