From f95591934822064aad21dfa868ccffce34387bf1 Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Thu, 4 Aug 2011 20:59:29 +0200 Subject: [PATCH 01/23] add github repositories sidebar plugin if you specify github_user: in you _config.yml and once you add asides/github.html to your sidebar items, this plugin will fetch the specified users github repositories and order them so the last pushed ones are shown first. Then it'll list them in the side-bar, including a link and the repository description The plugin will only list your own repositories, not forks, though this might need to be configurable later --- .../source/_includes/asides/github.html | 21 ++++++++++ .themes/classic/source/javascripts/github.js | 38 +++++++++++++++++++ _config.yml | 3 ++ 3 files changed, 62 insertions(+) create mode 100644 .themes/classic/source/_includes/asides/github.html create mode 100644 .themes/classic/source/javascripts/github.js diff --git a/.themes/classic/source/_includes/asides/github.html b/.themes/classic/source/_includes/asides/github.html new file mode 100644 index 0000000..07b37aa --- /dev/null +++ b/.themes/classic/source/_includes/asides/github.html @@ -0,0 +1,21 @@ +{% if site.github_user %} +
+

Github Repos

+ + + +
+{% endif %} diff --git a/.themes/classic/source/javascripts/github.js b/.themes/classic/source/javascripts/github.js new file mode 100644 index 0000000..56ebe96 --- /dev/null +++ b/.themes/classic/source/javascripts/github.js @@ -0,0 +1,38 @@ +github = (function(){ + function render(target, repos){ + var i = 0, fragment = '', t = $(target)[0]; + + for(i = 0; i < repos.length; i++) + fragment += '
  • '+repos[i].name+'

    '+repos[i].description+'

  • '; + + t.innerHTML = fragment; + } + return { + showRepos: function(user, target){ + var feed = new jXHR(); + feed.onerror = function (msg,url) { + $(target + ' li.loading').addClass('error').text("Error loading feed"); + } + feed.onreadystatechange = function(data){ + if (feed.readyState === 4) { + var repos = []; + var i; + for (i = 0; i < data.repositories.length; i++){ + if (!data.repositories[i].fork) + repos.push(data.repositories[i]); + } + repos.sort(function(a, b){ + var a = new Date(a.pushed_at), + b = new Date(b.pushed_at); + + if (a.valueOf() == b.valueOf()) return 0; + return a.valueOf() > b.valueOf() ? -1 : 1; + }) + render(target, repos) + } + }; + feed.open("GET","http://github.com/api/v2/json/repos/show/"+user+"?callback=?"); + feed.send(); + } + }; +})(); \ No newline at end of file diff --git a/_config.yml b/_config.yml index 9a48c01..30adf81 100644 --- a/_config.yml +++ b/_config.yml @@ -55,6 +55,9 @@ twitter_follow_button: true twitter_show_follower_count: false twitter_tweet_button: true +# github repositories +github_user: + # Google Plus google_plus_one: true google_plus_one_size: medium From 08af7b4e383976858ca5b7dd3246525c17bcb941 Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Thu, 4 Aug 2011 21:15:50 +0200 Subject: [PATCH 02/23] allow limiting the amount of repos to display by setting github_repo_count to someething that's not 0, you can limit the amount of repositories to render --- .../classic/source/_includes/asides/github.html | 7 ++++++- .themes/classic/source/javascripts/github.js | 14 +++++++++----- _config.yml | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.themes/classic/source/_includes/asides/github.html b/.themes/classic/source/_includes/asides/github.html index 07b37aa..5e0b0ed 100644 --- a/.themes/classic/source/_includes/asides/github.html +++ b/.themes/classic/source/_includes/asides/github.html @@ -13,7 +13,12 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(jxhr, s); } - github.showRepos('{{site.github_user}}', '#gh_repos'); + + github.showRepos({ + user: '{{site.github_user}}', + count: {{site.github_repo_count}}, + target: '#gh_repos' + }); }); diff --git a/.themes/classic/source/javascripts/github.js b/.themes/classic/source/javascripts/github.js index 56ebe96..8af5148 100644 --- a/.themes/classic/source/javascripts/github.js +++ b/.themes/classic/source/javascripts/github.js @@ -8,10 +8,10 @@ github = (function(){ t.innerHTML = fragment; } return { - showRepos: function(user, target){ + showRepos: function(options){ var feed = new jXHR(); feed.onerror = function (msg,url) { - $(target + ' li.loading').addClass('error').text("Error loading feed"); + $(options.target + ' li.loading').addClass('error').text("Error loading feed"); } feed.onreadystatechange = function(data){ if (feed.readyState === 4) { @@ -27,11 +27,15 @@ github = (function(){ if (a.valueOf() == b.valueOf()) return 0; return a.valueOf() > b.valueOf() ? -1 : 1; - }) - render(target, repos) + }); + + if (options.count) + repos.splice(options.count); + + render(options.target, repos) } }; - feed.open("GET","http://github.com/api/v2/json/repos/show/"+user+"?callback=?"); + feed.open("GET","http://github.com/api/v2/json/repos/show/"+options.user+"?callback=?"); feed.send(); } }; diff --git a/_config.yml b/_config.yml index 30adf81..a50abb3 100644 --- a/_config.yml +++ b/_config.yml @@ -57,6 +57,7 @@ twitter_tweet_button: true # github repositories github_user: +github_repo_count: 0 # Google Plus google_plus_one: true From 2e1f0c0bfc8d6f7cbc70a753e5424dbfb30b4d44 Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Thu, 4 Aug 2011 21:21:25 +0200 Subject: [PATCH 03/23] provide an option to show or not show github profile link --- .themes/classic/source/_includes/asides/github.html | 3 +++ _config.yml | 1 + 2 files changed, 4 insertions(+) diff --git a/.themes/classic/source/_includes/asides/github.html b/.themes/classic/source/_includes/asides/github.html index 5e0b0ed..74f8ea9 100644 --- a/.themes/classic/source/_includes/asides/github.html +++ b/.themes/classic/source/_includes/asides/github.html @@ -4,6 +4,9 @@
    • Status updating...
    + {% if site.github_show_profile_link %} + @{{site.github_user}} on Github + {% endif %} - {% include google_analytics.html %} - {% include google_plus_one.html %} - {% include twitter_sharing.html %} {% include custom/head.html %} diff --git a/.themes/classic/source/_layouts/default.html b/.themes/classic/source/_layouts/default.html index 5714757..5523ac1 100644 --- a/.themes/classic/source/_layouts/default.html +++ b/.themes/classic/source/_layouts/default.html @@ -9,5 +9,8 @@
    {% include footer.html %}
    + {% include google_analytics.html %} + {% include google_plus_one.html %} + {% include twitter_sharing.html %} From dae6cceec216856cc85163ad8cc22daccd02bf59 Mon Sep 17 00:00:00 2001 From: fhemberger Date: Sun, 4 Sep 2011 12:21:58 +0200 Subject: [PATCH 19/23] show page.title first, best practice for SEO and usability (e.g. bookmarks) --- .themes/classic/source/_includes/head.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.themes/classic/source/_includes/head.html b/.themes/classic/source/_includes/head.html index 2799ee5..5370cb4 100644 --- a/.themes/classic/source/_includes/head.html +++ b/.themes/classic/source/_includes/head.html @@ -4,7 +4,7 @@ - {{site.title}}{% if page.title %}: {{page.title}}{% endif %} + {% if page.title %}{{page.title}} « {% endif %}{{site.title}} {% if page.description %} From 80f8a609f6e2d7349ab76c7bee662024bdf2aa94 Mon Sep 17 00:00:00 2001 From: fhemberger Date: Sun, 4 Sep 2011 12:56:54 +0200 Subject: [PATCH 20/23] Improved support for non Latin characters in category names. Fixes #128 --- Gemfile | 3 ++- Gemfile.lock | 2 ++ plugins/category_generator.rb | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index ffb614f..14ee966 100644 --- a/Gemfile +++ b/Gemfile @@ -10,4 +10,5 @@ gem 'haml', '>= 3.1' gem 'compass', '>= 0.11' gem 'rubypants' gem 'rb-fsevent' -gem 'stringex' \ No newline at end of file +gem 'stringex' +gem 'unicode_utils' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index f2fc737..000eec9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,7 @@ GEM sass (3.1.7) stringex (1.3.0) syntax (1.0.0) + unicode_utils (1.0.0) PLATFORMS ruby @@ -58,3 +59,4 @@ DEPENDENCIES rdiscount rubypants stringex + unicode_utils diff --git a/plugins/category_generator.rb b/plugins/category_generator.rb index aa1180e..97fb9f3 100644 --- a/plugins/category_generator.rb +++ b/plugins/category_generator.rb @@ -16,8 +16,9 @@ # - category_dir: The subfolder to build category pages in (default is 'categories'). # - category_title_prefix: The string used before the category name in the page title (default is # 'Category: '). -module Jekyll +require "unicode_utils" +module Jekyll # The CategoryIndex class creates a single category page for the specified category. class CategoryIndex < Page @@ -68,7 +69,7 @@ module Jekyll if self.layouts.key? 'category_index' dir = self.config['category_dir'] || 'categories' self.categories.keys.each do |category| - self.write_category_index(File.join(dir, category.gsub(/_|\W/, '-')), category) + self.write_category_index(File.join(dir, UnicodeUtils.nfkd(category).gsub(/[^\x00-\x7F]/, '').gsub(/_|\W/, '-').to_s), category) end # Throw an exception if the layout couldn't be found. @@ -105,7 +106,7 @@ module Jekyll def category_links(categories) dir = @context.registers[:site].config['category_dir'] categories = categories.sort!.map do |item| - "#{item}" + "#{item}" end case categories.length From f03c4cdb2abe524e097fdfc67194e8d9fc0d19ab Mon Sep 17 00:00:00 2001 From: fhemberger Date: Sun, 4 Sep 2011 14:25:04 +0200 Subject: [PATCH 21/23] install: Adds confirmation before overwriting existing source_dir --- Rakefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Rakefile b/Rakefile index 702292a..59a6b19 100644 --- a/Rakefile +++ b/Rakefile @@ -27,6 +27,9 @@ server_port = "4000" # port for preview server eg. localhost:4000 desc "Initial setup for Octopress: copies the default theme into the path of Jekyll's generator. Rake install defaults to rake install[classic] to install a different theme run rake install[some_theme_name]" task :install, :theme do |t, args| + if File.directory?(source_dir) || File.directory?("sass") + abort("rake aborted!") if ask("A theme is already installed, proceeding will overwrite existing files. Are you sure?", ['y', 'n']) == 'n' + end # copy theme into working Jekyll directories theme = args.theme || 'classic' puts "## Copying "+theme+" theme into ./#{source_dir} and ./sass" @@ -293,6 +296,20 @@ def ok_failed(condition) end end +def get_stdin(message) + print message + STDIN.gets.chomp +end + +def ask(message, valid_options) + if valid_options + answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer) + else + answer = get_stdin(message) + end + answer +end + desc "list tasks" task :list do puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}" From b812500f392718ad80a5334350b7b7420fe618c3 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sun, 4 Sep 2011 08:47:36 -0500 Subject: [PATCH 22/23] Updated new_post and new_page taks to use new ask method for dialogs --- Rakefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 5a3f8f0..3d49fce 100644 --- a/Rakefile +++ b/Rakefile @@ -96,9 +96,7 @@ task :new_post, :title do |t, args| title = args.title filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}" if File.exist?(filename) - puts "### #{filename} Already exists. Overwrite? y/n:" - response = $stdin.gets.chomp.downcase - next unless response == 'y' + abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n' end puts "Creating new post: #{filename}" open(filename, 'w') do |post| @@ -128,9 +126,7 @@ task :new_page, :filename do |t, args| mkdir_p page_dir file = page_dir + filename if File.exist?(file) - puts "### #{file} Already exists. Overwrite? y/n:" - response = $stdin.gets.chomp.downcase - next unless response == 'y' + abort("rake aborted!") if ask("#{file} already exists. Do you want to overwrite?", ['y', 'n']) == 'n' end puts "Creating new page: #{file}" open(file, 'w') do |page| From 8c0dd58ee6de37b0a726f72c99dc84beeef0b6d3 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sun, 4 Sep 2011 09:21:01 -0500 Subject: [PATCH 23/23] changed left angle quote to dash for page titles --- .themes/classic/source/_includes/head.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.themes/classic/source/_includes/head.html b/.themes/classic/source/_includes/head.html index 5370cb4..d174112 100644 --- a/.themes/classic/source/_includes/head.html +++ b/.themes/classic/source/_includes/head.html @@ -4,7 +4,7 @@ - {% if page.title %}{{page.title}} « {% endif %}{{site.title}} + {% if page.title %}{{page.title}} - {% endif %}{{site.title}} {% if page.description %}