Skip to content

Commit

Permalink
feat: Add working install scripts.
Browse files Browse the repository at this point in the history
I actually can't test the Windows script myself, so I'll need help
from someone else to do that. That said, both the Unix and Windows
install scripts *should* be working now. They're simple, only
delegating to the 'real' scripts on GitHub since we don't have
the ability to set HTTP redirects with GitHub Pages. In the future
if we end up on something like Netlify we could.

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker committed Nov 1, 2024
1 parent fde25db commit 694c851
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 13 deletions.
44 changes: 35 additions & 9 deletions site/scripts/src/footer/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ export function setupSearchModal() {
return;
}

// 'Escape' when the modal is open to close it.
if (modalIsOpen($modal) && e.key === "Escape") {
e.preventDefault();
$modalShroud.click();
return;
if (modalIsOpen($modal)) {
switch (e.key) {
case "Escape":
e.preventDefault();
$modalShroud.click();
return;
case "ArrowDown":
// TODO: Focus the next result in the search results.
break;
case "ArrowUp":
// TODO: Focus the prior result in the search result.
break;
default:
break;
}
}
});
}
Expand Down Expand Up @@ -104,7 +114,7 @@ declare global {
let elasticlunr: {
Index: Index;
// deno-lint-ignore no-explicit-any
stemmer: any,
stemmer: any;
};
}

Expand Down Expand Up @@ -186,12 +196,28 @@ export function setupSearch() {
function buildListEntry(data: SearchResult, terms: string[]): HTMLElement {
return elem("li", {}, { classList: ["border-t", "border-neutral-300"] }, [
elem("div", {}, {}, [
elem("a", { href: data.ref }, { classList: ["block", "px-5", "py-2", "hover:bg-blue-50", "hover:text-blue-500", "group"] }, [
elem("span", {}, { classList: ["block", "text-base", "mb-1", "font-medium"] }, [
elem("a", { href: data.ref }, {
classList: [
"block",
"px-5",
"py-2",
"hover:bg-blue-50",
"hover:text-blue-500",
"group",
],
}, [
elem("span", {}, {
classList: ["block", "text-base", "mb-1", "font-medium"],
}, [
data.doc.title,
]),
elem("span", {}, {
classList: ["block", "text-neutral-500", "text-sm", "group-hover:text-blue-500"],
classList: [
"block",
"text-neutral-500",
"text-sm",
"group-hover:text-blue-500",
],
}, [
makeTeaser(data.doc.body, terms),
]),
Expand Down
9 changes: 9 additions & 0 deletions site/static/dl/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# This installer delegates to the "real" installer included with each new
# release of Hipcheck.

$hc_version = "3.7.0"
$repo = "https://github.com/mitre/hipcheck"
$installer = "$repo/releases/download/hipcheck-v${hc_version}/hipcheck-installer.ps1"

irm "$installer" | iex "$Args"
16 changes: 16 additions & 0 deletions site/static/dl/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# This installer delegates to the "real" installer included with each new
# release of Hipcheck.

HC_VERSION="3.7.0"
REPO="https://github.com/mitre/hipcheck"
INSTALLER="$REPO/releases/download/hipcheck-v$HC_VERSION/hipcheck-installer.sh"

# Check that curl is installed and error out if it isn't.
if ! command -v curl >/dev/null; then
echo "error: 'curl' is required to run the installer" 1>&2
exit 1
fi

curl -LsSf "$INSTALLER" | sh "$@"
2 changes: 1 addition & 1 deletion site/static/js/footer.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
function c(e){let t=document.querySelector(e);if(t===null)throw new b(`could not find ${e}`);return t}function f(e){let t=document.querySelectorAll(e);if(t===null)throw new b(`could not find all '${e}'`);return Array.from(t)}function A(e){navigator.clipboard.writeText(e).then(null,t=>{throw new k(t)})}var k=class extends Error{constructor(t){super(`clipboard copy rejected: '${t}'`)}},b=class extends Error{constructor(t){super(t)}};function W(){let e,t,s,o;try{e=f(".installer-button"),t=c("#installer-cmd"),s=c("#installer-copy"),o=c("#installer-copy > svg > use")}catch{return}e.forEach(r=>{r.addEventListener("click",a=>{a.preventDefault(),e.forEach(n=>delete n.dataset.active),r.dataset.active="true",t.innerText=N(r.dataset.platform)}),r.dataset.active&&r.dataset.active==="true"&&(t.innerText=N(r.dataset.platform))}),s.addEventListener("click",r=>{r.preventDefault(),A(t.innerText);let a=z(o),n=a.replace("#icon-clipboard","#icon-check");console.log(n),_(o,n),setTimeout(()=>_(o,a),1500)})}function z(e){let t=e.getAttributeNS(K,"href");if(t===null)throw new I;return t}function _(e,t){e.setAttributeNS(K,"href",t)}var K="http://www.w3.org/1999/xlink";function N(e){if(e===void 0)throw new x(e);switch(e){case"macos":return D;case"linux":return D;case"windows":return V;default:throw new x(e)}}var P=`${globalThis.window.location.protocol}//${globalThis.window.location.host}`,D=`curl -LsSf ${P}/dl/install.sh | sh`,V=`irm ${P}/dl/install.ps1 | iex`,x=class extends Error{constructor(t){super(`could not determine platform: '${t||"undefined"}'`)}},I=class extends Error{constructor(){super("could not find copy icon")}};function $(){f('a[href^="#"]').forEach(e=>{e.addEventListener("click",t=>{if(t.preventDefault(),t.currentTarget===null)return;let s=t.currentTarget.getAttribute("href");if(s===null)return;let r=c(s).getBoundingClientRect().top,a=globalThis.window.scrollY,n=r+a;globalThis.window.scrollTo({top:n,behavior:"smooth"})})})}function O(e,t){let s;return(...o)=>{clearTimeout(s),s=setTimeout(()=>t(...o),e)}}function Y(e){let t=Object.entries(e).filter(([s,o])=>o!==void 0);return Object.fromEntries(t)}function p(e,t={},s={},o=[]){let r=document.createElement(e);Object.assign(r,Y(t)),s.classList&&s.classList.forEach(n=>r.classList.add(n)),s.dataset&&Object.entries(s.dataset).filter(([n,d])=>d!==void 0).forEach(([n,d])=>r.dataset[n]=d);let a=o.map(n=>typeof n=="string"?document.createTextNode(n):n);return r.append(...a),r}function q(){let e=c("#search-button"),t=c("#search-modal"),s=c("#search-modal-close"),o=c("#search-modal-shroud"),r=c("#search-modal-box"),a=c("#search-input");e.addEventListener("click",n=>v(n,t,a)),o.addEventListener("click",n=>v(n,t,a)),s.addEventListener("click",n=>v(n,t,a)),r.addEventListener("click",n=>n.stopPropagation()),document.addEventListener("keydown",n=>{if(n.metaKey===!0&&n.shiftKey===!1&&n.key==="k"){n.preventDefault(),e.click();return}if(C(t)&&n.key==="Escape"){n.preventDefault(),o.click();return}})}function v(e,t,s){e.preventDefault(),t.classList.toggle("hidden"),C(t)&&s.focus()}function C(e){return!e.classList.contains("hidden")}var J="/search_index.en.json",Z=6;function F(){let e=c("#search-input"),t=c("#search-results"),s=c("#search-results-items"),o,r="",a=async function(){return o===void 0&&(o=fetch(J).then(async function(n){return await elasticlunr.Index.load(await n.json())})),await o};e.addEventListener("keyup",O(150,async function(){let n=e.value.trim();if(n===r||(t.style.display=n===""?"none":"block",s.innerHTML="",r=n,r===""))return;let d=(await a()).search(n,{bool:"AND",fields:{title:{boost:2},body:{boost:1}}});if(d.length===0){t.style.display="none";return}for(let m=0;m<Math.min(d.length,Z);++m){let u=Q(d[m],r.split(" "));s.appendChild(u)}}))}function Q(e,t){return p("li",{},{classList:["border-t","border-neutral-300"]},[p("div",{},{},[p("a",{href:e.ref},{classList:["block","px-5","py-2","hover:bg-blue-50","hover:text-blue-500","group"]},[p("span",{},{classList:["block","text-base","mb-1","font-medium"]},[e.doc.title]),p("span",{},{classList:["block","text-neutral-500","text-sm","group-hover:text-blue-500"]},[ee(e.doc.body,t)])])])])}function ee(e,t){let n=t.map(function(l){return elasticlunr.stemmer(l.toLowerCase())}),d=!1,m=0,u=[],H=e.toLowerCase().split(". ");for(let l in H){let i=H[l].split(" "),S=8;for(let X in i){let w=i[X];if(w.length>0){for(let B in n)elasticlunr.stemmer(w).startsWith(n[B])&&(S=40,d=!0);u.push([w,S,m]),S=2}m+=w.length,m+=1}m+=1}if(u.length===0)return e;let g=[],y=Math.min(u.length,15),T=0;for(let l=0;l<y;l++)T+=u[l][1];g.push(T);for(let l=0;l<u.length-y;l++)T-=u[l][1],T+=u[l+y][1],g.push(T);let L=0;if(d){let l=0;for(let i=g.length-1;i>=0;i--)g[i]>l&&(l=g[i],L=i)}let h=[],E=u[L][2];for(let l=L;l<L+y;l++){let i=u[l];E<i[2]&&(h.push(e.substring(E,i[2])),E=i[2]),i[1]===40&&h.push("<b>"),E=i[2]+i[0].length,h.push(e.substring(i[2],E)),i[1]===40&&h.push("</b>")}h.push("\u2026");let U=h.join(""),R=p("span",{},{},[]);return R.innerHTML=U,R}function j(e){if(e===void 0)throw new M(e);switch(e){case"system":switch(localStorage.removeItem("theme"),ne()){case"dark":document.documentElement.classList.add("dark");break;case"light":document.documentElement.classList.remove("dark");break}break;case"light":localStorage.setItem("theme",e),document.documentElement.classList.remove("dark");break;case"dark":localStorage.setItem("theme",e),document.documentElement.classList.add("dark");break;default:throw new M(e)}te(e)}function te(e){f(".theme-option").forEach(t=>{t.dataset.theme===e?t.dataset.active="true":delete t.dataset.active})}function ne(){return globalThis.window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var M=class extends Error{constructor(t){super(`could not determine theme: '${t||"undefined"}'`)}};function G(){f(".theme-option").forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),j(e.dataset.theme)})})}function re(){G(),W(),q(),F(),$()}(function(){try{re()}catch(e){console.error(e)}})();
function c(e){let t=document.querySelector(e);if(t===null)throw new b(`could not find ${e}`);return t}function f(e){let t=document.querySelectorAll(e);if(t===null)throw new b(`could not find all '${e}'`);return Array.from(t)}function A(e){navigator.clipboard.writeText(e).then(null,t=>{throw new k(t)})}var k=class extends Error{constructor(t){super(`clipboard copy rejected: '${t}'`)}},b=class extends Error{constructor(t){super(t)}};function W(){let e,t,s,i;try{e=f(".installer-button"),t=c("#installer-cmd"),s=c("#installer-copy"),i=c("#installer-copy > svg > use")}catch{return}e.forEach(r=>{r.addEventListener("click",a=>{a.preventDefault(),e.forEach(n=>delete n.dataset.active),r.dataset.active="true",t.innerText=N(r.dataset.platform)}),r.dataset.active&&r.dataset.active==="true"&&(t.innerText=N(r.dataset.platform))}),s.addEventListener("click",r=>{r.preventDefault(),A(t.innerText);let a=z(i),n=a.replace("#icon-clipboard","#icon-check");console.log(n),_(i,n),setTimeout(()=>_(i,a),1500)})}function z(e){let t=e.getAttributeNS(K,"href");if(t===null)throw new I;return t}function _(e,t){e.setAttributeNS(K,"href",t)}var K="http://www.w3.org/1999/xlink";function N(e){if(e===void 0)throw new x(e);switch(e){case"macos":return D;case"linux":return D;case"windows":return V;default:throw new x(e)}}var P=`${globalThis.window.location.protocol}//${globalThis.window.location.host}`,D=`curl -LsSf ${P}/dl/install.sh | sh`,V=`irm ${P}/dl/install.ps1 | iex`,x=class extends Error{constructor(t){super(`could not determine platform: '${t||"undefined"}'`)}},I=class extends Error{constructor(){super("could not find copy icon")}};function $(){f('a[href^="#"]').forEach(e=>{e.addEventListener("click",t=>{if(t.preventDefault(),t.currentTarget===null)return;let s=t.currentTarget.getAttribute("href");if(s===null)return;let r=c(s).getBoundingClientRect().top,a=globalThis.window.scrollY,n=r+a;globalThis.window.scrollTo({top:n,behavior:"smooth"})})})}function O(e,t){let s;return(...i)=>{clearTimeout(s),s=setTimeout(()=>t(...i),e)}}function Y(e){let t=Object.entries(e).filter(([s,i])=>i!==void 0);return Object.fromEntries(t)}function p(e,t={},s={},i=[]){let r=document.createElement(e);Object.assign(r,Y(t)),s.classList&&s.classList.forEach(n=>r.classList.add(n)),s.dataset&&Object.entries(s.dataset).filter(([n,d])=>d!==void 0).forEach(([n,d])=>r.dataset[n]=d);let a=i.map(n=>typeof n=="string"?document.createTextNode(n):n);return r.append(...a),r}function q(){let e=c("#search-button"),t=c("#search-modal"),s=c("#search-modal-close"),i=c("#search-modal-shroud"),r=c("#search-modal-box"),a=c("#search-input");e.addEventListener("click",n=>v(n,t,a)),i.addEventListener("click",n=>v(n,t,a)),s.addEventListener("click",n=>v(n,t,a)),r.addEventListener("click",n=>n.stopPropagation()),document.addEventListener("keydown",n=>{if(n.metaKey===!0&&n.shiftKey===!1&&n.key==="k"){n.preventDefault(),e.click();return}if(C(t)&&n.key==="Escape"){n.preventDefault(),i.click();return}})}function v(e,t,s){e.preventDefault(),t.classList.toggle("hidden"),C(t)&&s.focus()}function C(e){return!e.classList.contains("hidden")}var J="/search_index.en.json",Z=6;function F(){let e=c("#search-input"),t=c("#search-results"),s=c("#search-results-items"),i,r="",a=async function(){return i===void 0&&(i=fetch(J).then(async function(n){return await elasticlunr.Index.load(await n.json())})),await i};e.addEventListener("keyup",O(150,async function(){let n=e.value.trim();if(n===r||(t.style.display=n===""?"none":"block",s.innerHTML="",r=n,r===""))return;let d=(await a()).search(n,{bool:"AND",fields:{title:{boost:2},body:{boost:1}}});if(d.length===0){t.style.display="none";return}for(let m=0;m<Math.min(d.length,Z);++m){let u=Q(d[m],r.split(" "));s.appendChild(u)}}))}function Q(e,t){return p("li",{},{classList:["border-t","border-neutral-300"]},[p("div",{},{},[p("a",{href:e.ref},{classList:["block","px-5","py-2","hover:bg-blue-50","hover:text-blue-500","group"]},[p("span",{},{classList:["block","text-base","mb-1","font-medium"]},[e.doc.title]),p("span",{},{classList:["block","text-neutral-500","text-sm","group-hover:text-blue-500"]},[ee(e.doc.body,t)])])])])}function ee(e,t){let n=t.map(function(o){return elasticlunr.stemmer(o.toLowerCase())}),d=!1,m=0,u=[],H=e.toLowerCase().split(". ");for(let o in H){let l=H[o].split(" "),S=8;for(let X in l){let w=l[X];if(w.length>0){for(let B in n)elasticlunr.stemmer(w).startsWith(n[B])&&(S=40,d=!0);u.push([w,S,m]),S=2}m+=w.length,m+=1}m+=1}if(u.length===0){let o=e,l=p("span",{},{},[]);return l.innerHTML=o,l}let g=[],y=Math.min(u.length,15),T=0;for(let o=0;o<y;o++)T+=u[o][1];g.push(T);for(let o=0;o<u.length-y;o++)T-=u[o][1],T+=u[o+y][1],g.push(T);let L=0;if(d){let o=0;for(let l=g.length-1;l>=0;l--)g[l]>o&&(o=g[l],L=l)}let h=[],E=u[L][2];for(let o=L;o<L+y;o++){let l=u[o];E<l[2]&&(h.push(e.substring(E,l[2])),E=l[2]),l[1]===40&&h.push("<b>"),E=l[2]+l[0].length,h.push(e.substring(l[2],E)),l[1]===40&&h.push("</b>")}h.push("\u2026");let U=h.join(""),R=p("span",{},{},[]);return R.innerHTML=U,R}function j(e){if(e===void 0)throw new M(e);switch(e){case"system":switch(localStorage.removeItem("theme"),ne()){case"dark":document.documentElement.classList.add("dark");break;case"light":document.documentElement.classList.remove("dark");break}break;case"light":localStorage.setItem("theme",e),document.documentElement.classList.remove("dark");break;case"dark":localStorage.setItem("theme",e),document.documentElement.classList.add("dark");break;default:throw new M(e)}te(e)}function te(e){f(".theme-option").forEach(t=>{t.dataset.theme===e?t.dataset.active="true":delete t.dataset.active})}function ne(){return globalThis.window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var M=class extends Error{constructor(t){super(`could not determine theme: '${t||"undefined"}'`)}};function G(){f(".theme-option").forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),j(e.dataset.theme)})})}function re(){G(),W(),q(),F(),$()}(function(){try{re()}catch(e){console.error(e)}})();
//# sourceMappingURL=footer.mjs.map
Loading

0 comments on commit 694c851

Please sign in to comment.