Skip to content

Commit

Permalink
Replace GitHub.js and tomlify-j0.4 dependencies
Browse files Browse the repository at this point in the history
With the official GitHub JS client and @ltd/j-toml respectively.

As part of this, turn the JS files into modules and load the
dependencies from inside the modules.
  • Loading branch information
Ortham committed Aug 24, 2022
1 parent 1b0cd35 commit 05a6154
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ loot.github.io

This repository acts as the main LOOT team repository, and holds all the issues that aren't specific to the code or any one game. In addition to that, it also holds LOOT's static website.

The static website is a [Jekyll](https://jekyllrb.com/) site that uses [Material Design Lite](https://www.getmdl.io/) components and the [js-yaml](https://github.com/nodeca/js-yaml) and [Github.js](https://github.com/michael/github) libraries, which are provided by Google, Cloudflare and unpkg CDNs respectively.
The static website is a [Jekyll](https://jekyllrb.com/) site that uses [Material Design Lite](https://www.getmdl.io/) components and the [js-yaml](https://github.com/nodeca/js-yaml), [Octokit.js](https://github.com/octokit/rest.js) and [j-toml](https://github.com/LongTengDao/j-toml) libraries, which are provided by Google, Cloudflare and Skypack CDNs.

The easiest way to build this site locally is using Docker:

Expand Down
4 changes: 1 addition & 3 deletions convert-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ <h3>TOML <a id="download" download="settings.toml"></a></h3>

<p>Note that the download link that appears above after converting YAML does not work in Internet Explorer or Edge. Users of those browsers will need to copy the content of the TOML text box into a <code>settings.toml</code> file they create themselves, or use a different browser</code>.</p>

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/tomlify.min.js"></script>
<script src="/js/convert.js"></script>
<script src="/js/convert.js" type="module"></script>
3 changes: 1 addition & 2 deletions credits.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
<div id="progress" class="mdl-spinner mdl-js-spinner mdl-spinner--single-color is-active"></div>
</div>

<script src="https://unpkg.com/[email protected]/dist/GitHub.bundle.min.js"></script>
<script src="/js/credits.js"></script>
<script src="/js/credits.js" type="module"></script>
17 changes: 6 additions & 11 deletions js/convert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
import { load } from 'https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.mjs';
import TOML from 'https://cdn.skypack.dev/-/@ltd/[email protected]/dist=es2019,mode=imports/optimized/@ltd/j-toml.js';

function upgradeOldYaml(yaml) {
if (yaml['Debug Verbosity'] && !yaml.enableDebugLogging) {
Expand Down Expand Up @@ -37,20 +39,13 @@ function upgradeOldYaml(yaml) {

function yamlToToml(evt) {
try {
const settings = upgradeOldYaml(jsyaml.load(evt.target.value));
const settings = upgradeOldYaml(load(evt.target.value));

const options = {
space: 2,
replace: function(key, value) {
if (typeof value === 'number') {
/* Settings only use integers, no floats. */
return Math.round(value).toString();
}

return false;
}
indent: 2,
newline: '\n'
}
const toml = tomlify.toToml(settings, options);
const toml = TOML.stringify(settings, options);

document.getElementById('output').value = toml;

Expand Down
33 changes: 24 additions & 9 deletions js/credits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
import { Octokit } from "https://cdn.skypack.dev/pin/@octokit/[email protected]/mode=imports,min/optimized/@octokit/rest.js";
import { throttling } from "https://cdn.skypack.dev/pin/@octokit/[email protected]/mode=imports,min/optimized/@octokit/plugin-throttling.js";

function addToList(listElement, person) {
const a = document.createElement('a');
Expand Down Expand Up @@ -45,12 +47,12 @@ function sortContributors(a,b) {
}

function getStats(contributor) {
const isAnon = contributor.author.type === 'Anonymous';
const isAnon = contributor.type === 'Anonymous';
return {
contributions: contributor.total,
name: isAnon ? contributor.author.name : contributor.author.login,
avatar_url: isAnon ? undefined : contributor.author.avatar_url,
html_url: isAnon ? 'mailto:' + contributor.author.email : contributor.author.html_url
contributions: contributor.contributions,
name: isAnon ? contributor.name : contributor.login,
avatar_url: isAnon ? undefined : contributor.avatar_url,
html_url: isAnon ? 'mailto:' + contributor.email : contributor.html_url
};
}

Expand Down Expand Up @@ -81,13 +83,26 @@ function getContributorsStats(contributors) {
}

async function getContributors() {
const github = new GitHub();
const ThrottledOctokit = Octokit.plugin(throttling);

const reposResponse = await github.getOrganization('loot').getRepos();
const octokit = new ThrottledOctokit({
throttle: {
onAbuseLimit: () => true,
onRateLimit: () => true
}
});

const promises = reposResponse.data
const repos = await octokit.paginate(octokit.rest.repos.listForOrg, {
org: 'loot'
});

const promises = repos
.filter(repo => !repo.fork)
.map(repo => github.getRepo('loot', repo.name).getContributors());
.map(repo => octokit.paginate(octokit.rest.repos.listContributors, {
owner: 'loot',
repo: repo.name,
anon: true
}));

return Promise.all(promises).then(results => results.flat());
}
Expand Down
31 changes: 24 additions & 7 deletions js/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';
import { Octokit } from 'https://cdn.skypack.dev/pin/@octokit/[email protected]/mode=imports,min/optimized/@octokit/rest.js';
import { throttling } from 'https://cdn.skypack.dev/pin/@octokit/[email protected]/mode=imports,min/optimized/@octokit/plugin-throttling.js';
import { dump, load } from 'https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.mjs';

// Globals
///////////////////
Expand Down Expand Up @@ -76,13 +79,27 @@ function onSearchInit(evt) {
console.log("Loading masterlist...");
progress.classList.remove('hidden');

var repo = (new GitHub())
.getRepo('loot', gameButton.getAttribute('data-selected'))
.getContents(undefined, 'masterlist.yaml', true)
.then(readMasterlist)
.catch(function() {
document.getElementById('progress').classList.add('hidden');
});
const ThrottledOctokit = Octokit.plugin(throttling);

const octokit = new ThrottledOctokit({
throttle: {
onAbuseLimit: () => true,
onRateLimit: () => true
}
});

octokit.rest.repos.getContent({
owner: 'loot',
repo: gameButton.getAttribute('data-selected'),
path: 'masterlist.yaml',
mediaType: {
format: 'raw'
}
})
.then(readMasterlist)
.catch(function() {
document.getElementById('progress').classList.add('hidden');
});
}

function onGameSelect(evt) {
Expand Down
4 changes: 1 addition & 3 deletions search.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
<div id="progress" class="mdl-spinner mdl-js-spinner mdl-spinner--single-color is-active hidden"></div>
<div id="results" class="mdl-shadow--2dp"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/GitHub.bundle.min.js"></script>
<script src="/js/search.js"></script>
<script src="/js/search.js" type="module"></script>

0 comments on commit 05a6154

Please sign in to comment.