Share js-yaml and Octokit between page scripts

js-yaml could probably be shared without the intermediate module, but is handled the same way as Octokit for consistency.
This commit is contained in:
Oliver Hamlet
2026-01-11 17:52:18 +00:00
parent 608864cc7d
commit ed24dd0bab
6 changed files with 25 additions and 21 deletions
+1
View File
@@ -0,0 +1 @@
export { dump, load } from 'js-yaml';
+4
View File
@@ -0,0 +1,4 @@
import { Octokit as RealOctokit } from '@octokit/rest';
import { throttling } from '@octokit/plugin-throttling';
export const Octokit = RealOctokit.plugin(throttling);
+1 -1
View File
@@ -1,5 +1,5 @@
'use strict';
import { load } from 'js-yaml';
import { load } from '/js/js-yaml.js';
import TOML from '@ltd/j-toml';
function upgradeOldYaml(yaml) {
+2 -6
View File
@@ -1,6 +1,4 @@
'use strict';
import { Octokit } from '@octokit/rest';
import { throttling } from '@octokit/plugin-throttling';
import { Octokit } from '/js/octokit.js';
// Commit 37e464f6001d440ae532516f40fe19162537475a and earlier are common
// between the loot and libloot repositories, so are double-counted by GitHub.
@@ -243,9 +241,7 @@ function fixStats(contributorsStats) {
}
async function getContributors() {
const ThrottledOctokit = Octokit.plugin(throttling);
const octokit = new ThrottledOctokit({
const octokit = new Octokit({
throttle: {
onAbuseLimit: () => true,
onRateLimit: () => true
+3 -7
View File
@@ -1,7 +1,5 @@
'use strict';
import { Octokit } from '@octokit/rest';
import { throttling } from '@octokit/plugin-throttling';
import { dump, load } from 'js-yaml';
import { Octokit } from '/js/octokit.js';
import { dump, load } from '/js/js-yaml.js';
// Globals
///////////////////
@@ -80,9 +78,7 @@ function onSearchInit(evt) {
console.log("Loading masterlist...");
progress.classList.remove('hidden');
const ThrottledOctokit = Octokit.plugin(throttling);
const octokit = new ThrottledOctokit({
const octokit = new Octokit({
throttle: {
onAbuseLimit: () => true,
onRateLimit: () => true
+14 -7
View File
@@ -32,15 +32,22 @@
<link rel="stylesheet" href="{{ $style.RelPermalink }}">
<link rel="stylesheet" href="{{ $cssOverrides.RelPermalink }}">
{{ $externals := slice "/js/js-yaml.js" "/js/octokit.js" }}
{{
$jsBuildOpts := dict
"format" "esm"
"minify" (not hugo.IsDevelopment)
"sourceMap" (cond hugo.IsDevelopment "external" "")
"target" "es2023"
"externals" $externals
}}
{{ (resources.Get "js/octokit.js" | js.Build $jsBuildOpts).Publish }}
{{ (resources.Get "js/js-yaml.js" | js.Build $jsBuildOpts).Publish }}
{{ range .Resources.ByType "text" }}
{{ if eq .MediaType.Type "text/javascript" }}
{{ $opts := dict
"format" "esm"
"minify" (not hugo.IsDevelopment)
"sourceMap" (cond hugo.IsDevelopment "external" "")
"target" "es2023"
}}
{{ $scriptSrc := . | js.Build $opts }}
{{ $scriptSrc := . | js.Build $jsBuildOpts }}
<script src="{{ $scriptSrc.RelPermalink }}" type="module"></script>
{{ end }}
{{ end }}