Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4a1b90f
Fail early in scripts
RichDom2185 Aug 19, 2025
9d8f933
Add TS and TSX
RichDom2185 Aug 19, 2025
d0f568c
Remove invalid command
RichDom2185 Aug 19, 2025
756ebeb
Migrate to ESM
RichDom2185 Aug 19, 2025
41bc11b
Switch to tsx as runner
RichDom2185 Aug 19, 2025
f5997fd
Remove babel
RichDom2185 Aug 19, 2025
9c19481
Migrate constants to TS
RichDom2185 Aug 19, 2025
57c5812
Configure types
RichDom2185 Aug 19, 2025
456c43c
Migrate findBadTags to TS
RichDom2185 Aug 19, 2025
baaca3c
Update lockfile
RichDom2185 Aug 19, 2025
9d72cc0
Update scripts
RichDom2185 Aug 19, 2025
c60a349
Add type definitions
RichDom2185 Aug 19, 2025
39d4133
Set up Hono
RichDom2185 Aug 19, 2025
f6fe671
Use Hono for HTML links head
RichDom2185 Aug 19, 2025
effa59d
Use Hono for HTML licences
RichDom2185 Aug 19, 2025
ccf1a62
Fix scripts
RichDom2185 Aug 19, 2025
569a0ad
Move `generateChapterIndex` to utils file
RichDom2185 Aug 19, 2025
9b2db39
Create TocCards.tsx
RichDom2185 Aug 19, 2025
a01aa76
Update generateTocHtml.jsx
RichDom2185 Aug 19, 2025
7616a45
Refactor legends to own components
RichDom2185 Aug 19, 2025
dad596c
Fix missing closing tag
RichDom2185 Aug 19, 2025
e88b1da
Move navigation elements to separate file
RichDom2185 Aug 19, 2025
b682bc0
Rewrite Trie logic in TS
RichDom2185 Aug 19, 2025
fd99332
Migrate utility functions to TS
RichDom2185 Aug 19, 2025
9875ebd
Fix some imports
RichDom2185 Aug 19, 2025
fefe019
Add more types
RichDom2185 Aug 19, 2025
40a745b
Migrate scripts to TS
RichDom2185 Aug 19, 2025
4ab3300
Reformat
RichDom2185 Aug 19, 2025
8eb9c0f
Fix HTML content typing
RichDom2185 Aug 19, 2025
d8fbc51
Add and refactor body navigation
RichDom2185 Aug 19, 2025
eb10283
Move attribution to component
RichDom2185 Aug 19, 2025
43e0431
Add types
RichDom2185 Aug 19, 2025
4a2dcfc
Fix imports
RichDom2185 Aug 19, 2025
14d5e6f
Migrate entrypoint to TS
RichDom2185 Aug 19, 2025
18712a9
Move `createMain` to utils file
RichDom2185 Aug 19, 2025
f1440db
Add more types
RichDom2185 Aug 19, 2025
b2e5e47
Add import extensions
RichDom2185 Aug 19, 2025
e5b6eca
Migrate `generateSearchData` to TS
RichDom2185 Aug 19, 2025
0a20561
Improve search generation typing
RichDom2185 Aug 19, 2025
aa293cf
Reformat
RichDom2185 Aug 19, 2025
9b5b2d0
Fix __dirname
RichDom2185 Aug 19, 2025
71d2ec8
Fix double escaping
RichDom2185 Aug 19, 2025
92a9d5f
Fix incorrect path following file move
RichDom2185 Aug 19, 2025
48aacc1
Reformat some templates to simplify diff output
RichDom2185 Aug 19, 2025
f6aaebc
Fix generated HTML
RichDom2185 Aug 19, 2025
d524db4
Pass output directory to search script
RichDom2185 Aug 20, 2025
8f589fa
Fix stylesheet path
RichDom2185 Aug 20, 2025
6f4ae24
Revert "Reformat some templates to simplify diff output"
RichDom2185 Aug 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

79 changes: 79 additions & 0 deletions javascript/TocCards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { html, raw } from "hono/html";
import type { FC } from "hono/jsx";

type HeaderCardProps = {
index: number;
chapterIndex: number;
displayTitle: string;
toIndexFolder: string;
};

export const IndexHeaderCard: FC<HeaderCardProps> = ({
index,
chapterIndex,
displayTitle,
toIndexFolder
}) => {
return html`<div class="card-header" role="tab" id="index-${index + 1}">
<h5 class="mb-0">
<a
class="index-show collapsed"
data-toggle="collapse"
href="#index-collapse-${index + 1}"
aria-expanded="true"
aria-controls="index-collapse-${index + 1}"
>
&#10148;
<!-- ➤ (because this one is rendered blue on mobile: ▶ -->
</a>
<a
class="index-hide collapsed"
data-toggle="collapse"
href="#index-collapse-${index + 1}"
aria-expanded="true"
aria-controls="index-collapse-${index + 1}"
>
&#x25BC;
<!-- ▼ (because the corresponding one is not rendered) -->
</a>
<a href="${raw(toIndexFolder)}${chapterIndex}.html"
>${raw(displayTitle)}</a
>
</h5>
</div>`;
};

export const SidebarHeaderCard: FC<HeaderCardProps> = ({
index,
chapterIndex,
displayTitle,
toIndexFolder
}) => {
return html`<div class="card-header" role="tab" id="sidebar-${index + 1}">
<h5 class="mb-0">
<a
class="sidebar-show collapsed"
data-toggle="collapse"
href="#sidebar-collapse-${index + 1}"
aria-expanded="true"
aria-controls="sidebar-collapse-${index + 1}"
>
&#10148;
<!-- ➤ (because this one is rendered blue on mobile: ▶ -->
</a>
<a
class="sidebar-hide collapsed"
data-toggle="collapse"
href="#sidebar-collapse-${index + 1}"
aria-expanded="true"
aria-controls="sidebar-collapse-${index + 1}"
>
&#x25BC;
<!-- ▼ (because the corresponding one is not rendered) -->
</a>
<a href="${raw(toIndexFolder)}${chapterIndex}.html"
>${raw(displayTitle)}</a
>
</h5>
</div>`;
};
66 changes: 66 additions & 0 deletions javascript/commands/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import fs from "node:fs";
import fse from "fs-extra";
import path from "node:path";
import { ending, frontmatter, preamble } from "../latexContent.js";

const __dirname = path.resolve(import.meta.dirname);

export const createMain = (
inputDir: string,
outputDir: string,
parseType: string
) => {
// TODO: Use fs-extra to auto create subfolders
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}

if (parseType == "js" || parseType == "json") {
return;
}

if (parseType == "web") {
if (!fs.existsSync(path.join(outputDir, "/chapters"))) {
fs.mkdirSync(path.join(outputDir, "/chapters"));
}
fse.copy(path.join(__dirname, "../../static"), outputDir, err => {
if (err) return console.error(err);
});
return;
}

// for latex version only
// create sicpjs.tex file
// FIXME: Remove any
const chaptersFound: any[] = [];
const files = fs.readdirSync(inputDir);
files.forEach(file => {
if (file.match(/chapter/)) {
chaptersFound.push(file);
}
});
const stream = fs.createWriteStream(path.join(outputDir, "sicpjs.tex"));
stream.once("open", fd => {
stream.write(preamble);
stream.write(frontmatter);
chaptersFound.forEach(chapter => {
const pathStr = "./" + chapter + "/" + chapter + ".tex";
stream.write("\\input{" + pathStr + "}\n");
});
stream.write(ending);
stream.end();
});
// makes the .latexmkrc file
const latexmkrcStream = fs.createWriteStream(
path.join(outputDir, ".latexmkrc")
);
latexmkrcStream.once("open", fd => {
latexmkrcStream.write(latexmkrcContent);
latexmkrcStream.end();
});
};

const latexmkrcContent = `$pdflatex = "xelatex %O %S";
$pdf_mode = 1;
$dvi_mode = 0;
$postscript_mode = 0;`;
7 changes: 0 additions & 7 deletions javascript/constants.js → javascript/constants.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
export const sourceAcademyURL = "https://sourceacademy.org";

// to change to localhost if required
// http://localhost:8075

export const authors = "Harold Abelson and Gerald Jay Sussman";

export const authors_with = "Julie Sussman";

export const adapters = "Martin Henz and Tobias Wrigstad";

export const adapters_with = "Samuel Fang";
24 changes: 14 additions & 10 deletions javascript/findBadTags.js → javascript/findBadTags.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import fs from "fs";
import util from "util";
import path from "path";
import fs from "node:fs";
import util from "node:util";
import path from "node:path";

import { DOMParser as dom } from "xmldom";

const readdir = util.promisify(fs.readdir);
const open = util.promisify(fs.open);
const readFile = util.promisify(fs.readFile);

const __dirname = path.resolve(import.meta.dirname);
const inputDir = path.join(__dirname, "../xml");

const validTags = new Set([
Expand Down Expand Up @@ -171,11 +172,10 @@ const recursiveCheckChildrenForValidTag = node => {
return found;
};

async function recursiveCheckXmlForTag(filepath, tagName) {
let files;
async function recursiveCheckXmlForTag(filepath: string, tagName: string) {
const fullPath = path.join(inputDir, filepath);
files = await readdir(fullPath);
const promises = [];
const files = await readdir(fullPath);
const promises: Promise<void>[] = [];

files.forEach(file => {
if (file.match(/\.xml$/)) {
Expand All @@ -189,7 +189,11 @@ async function recursiveCheckXmlForTag(filepath, tagName) {
await Promise.all(promises);
}

async function checkXmlForTag(filepath, filename, tagName) {
async function checkXmlForTag(
filepath: string,
filename: string,
tagName: string
) {
const fullFilepath = path.join(inputDir, filepath, filename);
const fileToRead = await open(fullFilepath, "r");

Expand All @@ -210,7 +214,7 @@ async function checkXmlForTag(filepath, filename, tagName) {
async function main() {
const args = process.argv;
let tagName = "";
if (args.length > 2 && args[2] != "") {
if (args.length > 2 && args[2]) {
tagName = args[2];
console.log("\nLooking for tag: " + tagName + "\n");
} else {
Expand All @@ -220,7 +224,7 @@ async function main() {
recursiveCheckXmlForTag("", tagName);
}

// babel-node ./javascript/findBadTags <tagname>
// tsx ./javascript/findBadTags <tagname>

// Can provide 0 or 1 arguments.
// If no arguments provided, checks for all invalid tags.
Expand Down
Loading
Loading