From b3675127126c69f94c6f1cafcc47317f5e5ac0ee Mon Sep 17 00:00:00 2001 From: Stephen Brennan Date: Fri, 24 May 2024 10:09:18 -0700 Subject: [PATCH] Tweaks to the permalinking implementation Using Date.getDateString() didn't quite work for me: the dates returned by the date picker never seemed to show up in the mapping. So use the simpler YYYY-MM-DD date format and manually format the dates. The result has been reliable for me. Another tweak is to store the currentVersion, and once the commits are loaded, identify the date for this version and update the header to display a date (more user-friendly than a SHA). Signed-off-by: Stephen Brennan --- index.html | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index b8c8a54..53f8486 100644 --- a/index.html +++ b/index.html @@ -83,9 +83,9 @@ var selectedConfigs = new Set(); var versionDateMapping = new Map(); + var currentVersion = ""; function navigateToVersionFromDate(date) { - date = new Date(date).toDateString(); version = versionDateMapping.get(date); if(!version) { return // if no version present, do not navigate @@ -97,16 +97,30 @@ window.location.href = url; } + function dateString(date) { + const yearStr = date.getUTCFullYear().toString().padStart(4, "0"); + const monthStr = (date.getUTCMonth() + 1).toString().padStart(2, "0"); + const dayStr = date.getUTCDate().toString().padStart(2, "0"); + return `${yearStr}-${monthStr}-${dayStr}`; + } + function populateVersionOptions(data) { data = JSON.parse(data) let resp = Array.from(data); + let dates = new Set(); resp.forEach((res)=>{ - versionDateMapping.set(new Date(res.commit.committer.date).toDateString(), res.sha) + let date = new Date(res.commit.committer.date); + dates.add(date); + versionDateMapping.set(dateString(date), res.sha) + // If we started with a SHA, replace it with the date string + // for a better user experience. + if (currentVersion == res.sha) + setHeading(currentVersion, dateString(date)); }) let datepicker = document.getElementById("versionDateTimePicker") new tempusDominus.TempusDominus(datepicker, { restrictions: { - enabledDates: Array.from(versionDateMapping.keys().map(ds => new Date(ds))), + enabledDates: Array.from(dates), }, display: { viewMode: 'calendar', @@ -119,7 +133,7 @@ }, }, localization: { - format: 'MM-dd-yyyy', + format: 'yyyy-MM-dd', }, useCurrent: false, }) @@ -131,9 +145,16 @@ return `https://raw.githubusercontent.com/oracle/kconfigs/${version}/docs/summary.json` } + function setHeading(version, date) { + let sp = document.getElementById("heading") + if (date) + sp.innerHTML = `Distribution Kernel Configs (date: ${date})` + else + sp.innerHTML = `Distribution Kernel Configs (version: ${version})` + } + function updateVersion(invalid=false) { let params = new URLSearchParams(document.location.search); - let sp = document.getElementById("heading") if(invalid) { sp.innerHTML = `Distribution Kernel Configs` alert("Invalid Version. Please add a valid version") @@ -142,9 +163,13 @@ window.location.href = url; return } - var version = params.get("version"); - if(!version) return "gh-pages"; - sp.innerHTML = `Distribution Kernel Configs (version: ${version})` + let version = params.get("version"); + let date = ""; + if(!version) { + version = "gh-pages"; + date = "latest"; + } + setHeading(version, date); return version } @@ -268,7 +293,7 @@ } window.onpopstate = setState; setState(); - let version = updateVersion(); + currentVersion = updateVersion(); let vor = new XMLHttpRequest() vor.open("GET", "https://api.github.com/repos/oracle/kconfigs/commits?sha=gh-pages", true) @@ -279,7 +304,7 @@ vor.send(null) const xhr = new XMLHttpRequest(); - xhr.open("GET", getSummaryURL(version), true); + xhr.open("GET", getSummaryURL(currentVersion), true); xhr.onload = (event) => { console.log("Loaded kernel config summary") if(event.target.status === 200)