Skip to content

Instantly share code, notes, and snippets.

@wikimatze
Last active June 19, 2017 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wikimatze/7b5eefc21b5dc01dd73188805dd259f6 to your computer and use it in GitHub Desktop.
Save wikimatze/7b5eefc21b5dc01dd73188805dd259f6 to your computer and use it in GitHub Desktop.

Sweetie is a plugin for to get statistics for jekyll and middleman projects. The statistics includes the unique number of all links, images, pages, and the last build time of the given project. You can specify the location the generated files (normally _site for jekyll and build for middleman apps) and of the config file where the changes will be written.

It can also grab the last changes of your bitbucket repositories. You can then use the information on various places in your project

Gem Version Build Status

Toc

Installation

$ gem install sweetie

Usage create stati

Jekyll

The easiest way is to add require 'sweetie' on the top of your Rakefile.

Before you build your page, you can run a rake task to update the status information of a page:

require 'sweetie'

desc 'write stats in the _config.yml file'
task :create_stati do
  sweetie = Sweetie::Conversion.new('./site', './_config.yml')
  sweetie.create_stati
end

Make sure that the following fields are set in your _config.yml:

build:
htmlpages:
images:
links:

After running the script, the changes in _config.yml will look like:

build: 6-18-2017
htmlpages: 600
images: 20
links: 271

Configuration variables for Jekyll

You can use the build, htmlpages, images, and links variables defined in your _config.yml file everywhere in your page with the liquid snippet for example:

  • {{ site.build }}
  • {{ site.htmlpages }}
  • {{ site.images }}
  • {{ site.links }}

If you also make use of Usage for Bitbucket repositories you can also use the last update value for your repositories:

<section class="lastupdate">
Last update {{ site.git }}
</section>
...


<section class="lastupdate">
Last update {{ site.pmwiki-twitter-recipe }}
</section>
...

will result the following html:

<h3 id="git">Git</h3>

<section class="lastupdate">
Last update 2011-10-16
</section>


<h3 id="twitter">Twitter</h3>

<section class="lastupdate">
Last update 2011-10-16
</section>

Middleman

The easiest way is to add require 'sweetie' on the top of your Rakefile.

Before you build your page, you can run a rake task to update the status information of a page:

require 'sweetie'

desc 'write stats in the config.rb file'
task :create_stati do
  sweetie = Sweetie::Conversion.new('./build', './config.rb')
  sweetie.create_stati
end

Make sure that the following fields are set in your config.rb:

set :build,
set :images,
set :htmlpages,
set :links,

After running the script, the changes in config.rb will look like:

set :build, 6-18-2017
set :images, 75
set :htmlpages, 111
set :links, 694

Configuration variables for Middleman

You can use the build, htmlpages, images, and links variables defined in your _config.yml file everywhere in your page with the erb snippet for example:

  • `<%= config[:build] %>
  • `<%= config[:htmlpages] %>
  • `<%= config[:images] %>
  • `<%= config[:links] %>

If you also make use of Usage for Bitbucket repositories you can also use the last update value for your repositories:

<section class="lastupdate">
Last update <%= config[:git] %>
</section>
...


<section class="lastupdate">
Last update <%= config[:pmwiki_twitter_recipe %>
</section>
...

will result the following html:

<h3 id="git">Git</h3>

<section class="lastupdate">
Last update 2011-10-16
</section>


<h3 id="twitter">Twitter</h3>

<section class="lastupdate">
Last update 2011-10-16
</section>

Usage Bitbucket repositories

Middleman

The easiest way is to add require 'sweetie' on the top of your Rakefile.

Before you build your page, you can run a rake task to update the status of the repositories for the given config-file and username:

require 'sweetie'

desc 'write repositories stats in the config.rb file'
task :create_bitbucket do
  stati_helper = Sweetie::BitbucketStatiHelper.new('./config.rb', 'wikimatze')
  bitbucket = Sweetie::Bitbucket.new(stati_helper)
  bitbucket.update_stati
end

Please note that you have to change wikimatze to your bitbucket user name

set :pmwiki_dropcaps_recipe,
set :pmwiki_syntaxlove_recipe,
set :pmwiki_twitter_recipe,
set :pmwiki_linkicons_recipe,
set :pmwiki_headlineimage_recipe,

After running the script, the names in config.rb above will be changed to:

set :pmwiki_dropcaps_recipe, 2017-02-24
set :pmwiki_syntaxlove_recipe, 2017-02-26
set :pmwiki_twitter_recipe, 2017-02-26
set :pmwiki_linkicons_recipe, 2017-02-26
set :pmwiki_headlineimage_recipe, 2017-02-25

Jekyll

The easiest way is to add require 'sweetie' on the top of your Rakefile.

Before you build your page, you can run a rake task to update the status of the repositories for the given config-file and username:

require 'sweetie'

desc 'write repositories stats in the _config.yml file'
desc 'write stats in the _config.yml'
task :create_bitbucket do
  stati_helper = Sweetie::BitbucketStatiHelper.new('./_config.yml', 'wikimatze')
  bitbucket = Sweetie::Bitbucket.new(stati_helper)
  bitbucket.update_stati
end

Please note that you have to change wikimatze to your bitbucket user name

set :pmwiki_dropcaps_recipe,
set :pmwiki_syntaxlove_recipe,
set :pmwiki_twitter_recipe,
set :pmwiki_linkicons_recipe,
set :pmwiki_headlineimage_recipe,

After running the script, the names in config.rb above will be changed to:

set :pmwiki_dropcaps_recipe, 2017-02-24
set :pmwiki_syntaxlove_recipe, 2017-02-26
set :pmwiki_twitter_recipe, 2017-02-26
set :pmwiki_linkicons_recipe, 2017-02-26
set :pmwiki_headlineimage_recipe, 2017-02-25

License

This software is licensed under the MIT license.

© 2011-2015 Matthias Günther matthias@wikimatze.de.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment