diff options
author | Justin Mayer <entroP@gmail.com> | 2013-11-25 17:26:31 -0800 |
---|---|---|
committer | Justin Mayer <entroP@gmail.com> | 2013-11-25 17:26:31 -0800 |
commit | ba0a715208942811e46f9b989f1d6d8c9f040d7a (patch) | |
tree | 45736f21ad8ce50a4733635cab50e4d30c6ad735 | |
parent | 7ef242b7580306f953756a7ea3d2632c70ef30b8 (diff) | |
parent | 18024acc4c3008e294d4301c39e20ca7c4f28919 (diff) | |
download | pelican-themes-ba0a715208942811e46f9b989f1d6d8c9f040d7a.tar.gz |
Merge pull request #174 from nikipore/pelican-bootstrap3-github-sort
GitHub activity: allow sorting by an arbitrary attribute
-rw-r--r-- | pelican-bootstrap3/README.md | 8 | ||||
-rw-r--r-- | pelican-bootstrap3/static/js/github.js | 10 | ||||
-rw-r--r-- | pelican-bootstrap3/templates/includes/github.html | 16 |
3 files changed, 24 insertions, 10 deletions
diff --git a/pelican-bootstrap3/README.md b/pelican-bootstrap3/README.md index 4d19ca4..ce129ef 100644 --- a/pelican-bootstrap3/README.md +++ b/pelican-bootstrap3/README.md @@ -37,9 +37,11 @@ Categories are disabled by default because I don't use them myself. If you want The theme can show your most recently active GitHub repos in the sidebar. To enable, provide a `GITHUB_USER`. Appearance and behaviour can be controlled using the following variables: -* `GITHUB_REPO_COUNT` -* `GITHUB_SKIP_FORK` -* `GITHUB_SHOW_USER_LINK` +* `GITHUB_REPO_COUNT` (default: `5`) +* `GITHUB_SKIP_FORK` (default: `False`) +* `GITHUB_SHOW_USER_LINK` (default: `True`) +* `GITHUB_SORT_ATTRIBUTE` (default: `pushed_at`, for other attributes like `stargazers_count` cf. `https://api.github.com/users/<GITHUB_USER>/repos`) +* `GITHUB_SORT_DESCENDING` (default: `True`) ### Bootswatch and other Bootstrap 3 themes diff --git a/pelican-bootstrap3/static/js/github.js b/pelican-bootstrap3/static/js/github.js index 7bdb6a4..0ac60ef 100644 --- a/pelican-bootstrap3/static/js/github.js +++ b/pelican-bootstrap3/static/js/github.js @@ -24,13 +24,11 @@ var github = (function(){ repos.push(data.data[i]); } repos.sort(function(a, b) { - var aDate = new Date(a.pushed_at).valueOf(), - bDate = new Date(b.pushed_at).valueOf(); - - if (aDate === bDate) { return 0; } - return aDate > bDate ? -1 : 1; + if (a[options.sort_attribute] > b[options.sort_attribute]) { return 1; } + if (a[options.sort_attribute] < b[options.sort_attribute]) { return -1; } + return 0; }); - + if (options.sort_descending) { repos.reverse(); } if (options.count) { repos.splice(options.count); } render(options.target, repos); } diff --git a/pelican-bootstrap3/templates/includes/github.html b/pelican-bootstrap3/templates/includes/github.html index 1d1e7f2..f8542c5 100644 --- a/pelican-bootstrap3/templates/includes/github.html +++ b/pelican-bootstrap3/templates/includes/github.html @@ -12,6 +12,18 @@ {% set GITHUB_SKIP_FORK = "false" %} {% endif %} {% endif %} + {% if GITHUB_SORT_ATTRIBUTE is not defined %} + {% set GITHUB_SORT_ATTRIBUTE = "pushed_at" %} + {% endif %} + {% if GITHUB_SORT_DESCENDING is not defined %} + {% set GITHUB_SORT_DESCENDING = "true" %} + {% else %} + {% if GITHUB_SORT_DESCENDING %} + {% set GITHUB_SORT_DESCENDING = "true" %} + {% else %} + {% set GITHUB_SORT_DESCENDING = "false" %} + {% endif %} + {% endif %} <section> <ul class="list-group list-group-flush"> @@ -37,7 +49,9 @@ user: '{{ GITHUB_USER }}', count: {{ GITHUB_REPO_COUNT }}, skip_forks: {{ GITHUB_SKIP_FORK }}, - target: '#gh_repos' + target: '#gh_repos', + sort_attribute: '{{ GITHUB_SORT_ATTRIBUTE }}', + sort_descending: {{ GITHUB_SORT_DESCENDING }} }); }); </script> |