Skip to content

Commit dc89ee0

Browse files
committed
get tsc to compile scripts directly
1 parent f00337a commit dc89ee0

File tree

4 files changed

+32
-55
lines changed

4 files changed

+32
-55
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules/
22
_site/
33
.DS_Store
4-
src/lib/*.js
4+
src/**/*.js

eleventy.config.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,9 @@ export default function (eleventyConfig) {
44
// Ignore .gitignore and use .eleventyignore instead
55
eleventyConfig.setUseGitIgnore(false);
66

7-
// Static resources.
7+
// Copy over static resources.
88
eleventyConfig.addPassthroughCopy("src/style.css");
99

10-
// This is the incantation recommended to enable TypeScript compilation for
11-
// frontend scripts.
12-
eleventyConfig.addTemplateFormats("ts");
13-
eleventyConfig.addExtension("ts", {
14-
outputFileExtension: "js",
15-
compile: async (inputContent, inputPath) => {
16-
return async (data) => {
17-
let { code } = await esbuild.transform(inputContent, {
18-
loader: "ts",
19-
minify: process.env.NODE_ENV === "production",
20-
});
21-
return code;
22-
};
23-
},
24-
});
25-
26-
// A filter to format bit ranges in a more human-friendly way.
27-
eleventyConfig.addFilter("bitRange", function (range) {
28-
if (!range) return "";
29-
if (typeof range === "string") return range;
30-
if (Array.isArray(range)) return `${range[0]}-${range[1]}`;
31-
return String(range);
32-
});
33-
3410
// Directory configurations and template engines.
3511
return {
3612
dir: {

src/scripts/search.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
const input = document.getElementById("search");
2-
const instruction_list = document.getElementById("instruction_list");
3-
const filtersFieldset = document.getElementById("extension-filters-fieldset");
4-
// the blank area where we’ll insert checkboxes
5-
const filtersContainer = document.getElementById("extension-filters");
6-
const items = Array.from(instruction_list.querySelectorAll("li"));
7-
const activeExtensions = new Set();
8-
9-
// Gather unique extension names from the rendered instruction <li> items.
10-
const extensionSet = new Set();
1+
// Obtaining relevant DOM elements
2+
const input = document.getElementById("search") as HTMLInputElement;
3+
const instructionList = document.getElementById("instruction_list") as HTMLUListElement;
4+
const filtersContainer = document.getElementById("extension-filters") as HTMLDivElement;
5+
const items = Array.from(instructionList.querySelectorAll("li"));
6+
7+
8+
// Extracting unique extensions to filter
9+
const activeExtensions = new Set<string>();
10+
const extensionSet = new Set<string>();
1111
for (const li of items) {
1212
const extension = li.dataset.extension;
13-
extensionSet.add(extension);
13+
if (extension) extensionSet.add(extension);
1414
}
15-
1615
const extensions = Array.from(extensionSet).sort();
16+
17+
18+
// Creating a checkbox for each unique extension
1719
for (const extension of extensions) {
1820
const id = `ext-${extension}`;
1921
const label = document.createElement("label");
@@ -23,12 +25,10 @@ for (const extension of extensions) {
2325
checkbox.type = "checkbox";
2426
checkbox.value = extension;
2527
checkbox.id = id;
28+
2629
checkbox.addEventListener("change", () => {
27-
if (checkbox.checked) {
28-
activeExtensions.add(extension);
29-
} else {
30-
activeExtensions.delete(extension);
31-
}
30+
if (checkbox.checked) activeExtensions.add(extension);
31+
else activeExtensions.delete(extension);
3232
applyFilters();
3333
});
3434

@@ -40,9 +40,12 @@ for (const extension of extensions) {
4040
filtersContainer.appendChild(label);
4141
}
4242

43+
44+
// Function to apply both text and extension filters to the instruction list
4345
function applyFilters() {
4446
const q = input.value.trim().toLowerCase();
4547
const filtersActive = activeExtensions.size > 0;
48+
4649
for (const li of items) {
4750
/* Check if the item matches the text search
4851
- If the search box is empty, match everything
@@ -52,25 +55,21 @@ function applyFilters() {
5255
/* Check if the item matches an active extension filter
5356
- If no filters are active, match everything
5457
- Otherwise, show only if its extension is selected */
55-
const matchesExtension =
56-
!filtersActive || activeExtensions.has(li.dataset.extension);
58+
const matchesExtension = !filtersActive || activeExtensions.has(li.dataset.extension);
5759

5860
// Show or hide this <li> depending on whether both match conditions are true
5961
li.style.display = matchesQuery && matchesExtension ? "" : "none";
6062
}
6163
}
6264

63-
input.addEventListener("input", applyFilters);
6465

66+
// Set up event listeners for the search input
67+
input.addEventListener("input", applyFilters);
6568
input.addEventListener("keydown", (e) => {
6669
// Only act if Enter is pressed
6770
if (e.key !== "Enter") return;
68-
6971
const q = input.value.trim().toLowerCase();
70-
71-
// Do nothing if the box is empty
72-
if (!q) return;
73-
72+
if (!q) return; // Do nothing if the box is empty
7473
const filtersActive = activeExtensions.size > 0;
7574

7675
/* Look for an exact mnemonic match among all instructions
@@ -88,4 +87,6 @@ input.addEventListener("keydown", (e) => {
8887
}
8988
});
9089

90+
91+
// Apply filters on page load
9192
applyFilters();

tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"target": "ESNext",
44
"module": "NodeNext",
55
"moduleResolution": "NodeNext",
6-
"outDir": "src/lib",
7-
"rootDir": "src/lib",
6+
"outDir": "src",
7+
"rootDir": "src",
88
"allowJs": true,
99
"esModuleInterop": true,
1010
"skipLibCheck": true,
1111
"noEmit": false
1212
},
13-
"include": ["src/lib/**/*"],
14-
"exclude": ["node_modules", "src/scripts"]
13+
"include": ["src/lib/**/*", "src/scripts/**/*"],
14+
"exclude": ["node_modules"]
1515
}

0 commit comments

Comments
 (0)