diff --git a/_includes/contributors-list.html b/_includes/contributors-list.html new file mode 100644 index 0000000000..0feecc424e --- /dev/null +++ b/_includes/contributors-list.html @@ -0,0 +1,4 @@ +
+

Contributors to this page:

+
+
diff --git a/_includes/inner-page-main-content.html b/_includes/inner-page-main-content.html index 9587a304cb..78a954b5ae 100644 --- a/_includes/inner-page-main-content.html +++ b/_includes/inner-page-main-content.html @@ -3,6 +3,8 @@
{{content}} + + {% include contributors-list.html %}
diff --git a/_layouts/cheatsheet.html b/_layouts/cheatsheet.html index 6dacd54d46..471a120c4f 100644 --- a/_layouts/cheatsheet.html +++ b/_layouts/cheatsheet.html @@ -30,6 +30,8 @@ {% endfor %} {% endif %} + + {% include contributors-list.html %} diff --git a/_layouts/glossary.html b/_layouts/glossary.html index ea5d5dde0f..e65a189e23 100644 --- a/_layouts/glossary.html +++ b/_layouts/glossary.html @@ -8,6 +8,8 @@
{{content}} + + {% include contributors-list.html %}
diff --git a/_layouts/multipage-overview.html b/_layouts/multipage-overview.html index cf7c0b5a32..a98e6742e3 100644 --- a/_layouts/multipage-overview.html +++ b/_layouts/multipage-overview.html @@ -9,6 +9,8 @@
{{content}} + + {% include contributors-list.html %}
diff --git a/_layouts/singlepage-overview.html b/_layouts/singlepage-overview.html index 87c3279b92..72cabad3fd 100644 --- a/_layouts/singlepage-overview.html +++ b/_layouts/singlepage-overview.html @@ -8,6 +8,8 @@
{{content}} + + {% include contributors-list.html %}
diff --git a/_layouts/style-guide.html b/_layouts/style-guide.html index 8028663a43..ecc9a53bf2 100644 --- a/_layouts/style-guide.html +++ b/_layouts/style-guide.html @@ -9,6 +9,8 @@
{{content}} + + {% include contributors-list.html %}
diff --git a/_layouts/tour.html b/_layouts/tour.html index a7f96b55c1..9369547dd7 100644 --- a/_layouts/tour.html +++ b/_layouts/tour.html @@ -20,6 +20,8 @@ next {% endif %} + + {% include contributors-list.html %} diff --git a/_sass/layout/content-contributors.scss b/_sass/layout/content-contributors.scss new file mode 100644 index 0000000000..ebf6f00b98 --- /dev/null +++ b/_sass/layout/content-contributors.scss @@ -0,0 +1,22 @@ +.content-contributors { + .contributors-container { + display: flex; + flex-wrap: wrap; + align-items: center; + div { + margin: 5px; + a { + vertical-align: middle; + padding: 3px; + text-decoration: none; + } + img { + vertical-align: middle; + width: 35px; + height: 35px; + margin-bottom: 0; + border-radius: 7px; + } + } + } +} diff --git a/resources/css/style.scss b/resources/css/style.scss index d6ce6e6aa6..7d297f71ea 100755 --- a/resources/css/style.scss +++ b/resources/css/style.scss @@ -54,7 +54,8 @@ @import 'layout/books'; @import 'layout/training-events'; @import 'layout/blog'; -@import 'layout/download'; // COMPONENTS +@import 'layout/download'; +@import 'layout/content-contributors'; // COMPONENTS //------------------------------------------------ //------------------------------------------------ @import 'components/buttons'; diff --git a/resources/js/functions.js b/resources/js/functions.js index d7e85b0646..ed94b16a9f 100644 --- a/resources/js/functions.js +++ b/resources/js/functions.js @@ -521,4 +521,85 @@ $(document).ready(function(){ $("html, body").animate({ scrollTop: 0 }, 600); return false; }); -}); \ No newline at end of file +}); + +//Contributors widget +// see https://stackoverflow.com/a/19200303/4496364 +$(document).ready(function () { + let githubApiUrl = 'https://api.github.com/repos/scala/docs.scala-lang/commits'; + let identiconsUrl = 'https://github.com/identicons'; + /* - we need to transform "/tour/basics.html" to "_ba/tour/basics.md" + * - some files aren't prefixed with underscore, see rootFiles + * - some files are placed in _overviews but rendered to its folder, see overviewsFolders + */ + + let rootFiles = ['getting-started', 'learn', 'glossary']; + let overviewsFolders = ['FAQ', 'cheatsheets', 'collections', 'compiler-options', + 'core', 'jdk-compatibility', 'macros', 'parallel-collections', + 'plugins', 'quasiquotes', 'reflection', + 'repl', 'scaladoc', 'tutorials' + ]; + + let thisPageUrl = window.location.pathname; + // chop off beginning slash and ending .html + thisPageUrl = thisPageUrl.substring(1, thisPageUrl.lastIndexOf('.')); + let isRootFile = rootFiles.some(rf => thisPageUrl.startsWith(rf)); + let isInOverviewsFolder = overviewsFolders.some(of => thisPageUrl.startsWith(of)); + if(isRootFile) { + thisPageUrl = thisPageUrl + '.md'; + } else if(isInOverviewsFolder) { + thisPageUrl = '_overviews/'+ thisPageUrl + '.md'; + } else { + thisPageUrl = '_' + thisPageUrl + '.md'; + } + + let url = githubApiUrl + '?path=' + thisPageUrl; + $.get(url, function (data, status) { + if(!data || data.length < 1) { + $('.content-contributors').html(''); // clear content + return false; // break + } + let contributorsUnique = []; + data.forEach(commit => { + // add if not already in array + let addedToList = contributorsUnique.find(c => { + let matches = c.authorName == commit.commit.author.name; + if (!matches && commit.author) { + matches = c.authorName == commit.author.login; + } + return matches; + }); + + if (!addedToList) { + // first set fallback properties + let authorName = commit.commit.author.name; + let authorLink = ''; + let authorImageLink = identiconsUrl + '/' + commit.commit.author.name + '.png'; + // if author present, fill these preferably + if (commit.author) { + authorName = commit.author.login; + authorLink = commit.author.html_url; + authorImageLink = commit.author.avatar_url; + } + contributorsUnique.push({ + 'authorName': authorName, + 'authorLink': authorLink, + 'authorImageLink': authorImageLink + }); + } + }); + + let contributorsHtml = ''; + contributorsUnique.forEach(contributor => { + let contributorHtml = '
'; + contributorHtml += ''; + if (contributor.authorLink) + contributorHtml += '' + contributor.authorName + ''; + else + contributorHtml += '' + contributor.authorName + ''; + contributorHtml += '
'; + contributorsHtml += contributorHtml; + }); + $('#contributors').html(contributorsHtml); + }); +});