Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
static
node_modules/
.next/
out/
next-env.d.ts
tsconfig.tsbuildinfo
.DS_Store
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# latex2js.com

The website for [LaTeX2JS](https://github.com/Mathapedia/LaTeX2JS) — author interactive math equations and diagrams online using LaTeX and PSTricks.

Built with Next.js (static export) on the same architecture as [constructive.io](https://constructive.io) and [danlynch.com](https://danlynch.com):

- **JSON-LD knowledge graph** — `src/data/jsonld/` holds a flat graph of schema.org entities with namespaced `@id`s (`software:latex2js`, `org:constructive`, `person:danlynch`, …) shared across the site family. Pages slice per-page subgraphs via `jsonldjs` and the `<Head>` component injects them as `application/ld+json`.
- **SEO registry** — `src/seo.ts` holds per-route titles/descriptions; canonicals are derived from typed routes.
- **Sitemap + robots.txt** — generated post-build from the exported HTML by `src/seo/seo.ts`.
- **llms.txt + markdown twins** — `scripts/generate-llm-markdown.ts` emits `out/llms.txt` and a `.md` twin for every example and installation page.
- **Content as data** — the interactive PSTricks examples live as `.tex` files in `content/examples/`, registered in `src/data/examples.ts`, and rendered client-side by [`@latex2js/react`](https://www.npmjs.com/package/@latex2js/react).

## Develop

```bash
pnpm install
pnpm dev # http://localhost:5007
pnpm test # JSON-LD graph validation + registry tests
```

## Build & deploy

```bash
pnpm build # next build + llms.txt/md twins + sitemap/robots into out/
pnpm deploy:all # build, sync to s3://latex2js.com, extensionless copies, CloudFront invalidation
```
97 changes: 97 additions & 0 deletions __tests__/helpers/jsonld-test-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* JSON-LD Test Utilities
*
* Helper functions for testing JSON-LD output.
* Snapshots are kept lean by extracting only @id and @type properties.
*/

import { type JsonLdGraph, type JsonLdEntity } from 'jsonldjs';

/**
* Extract only @id properties from entities for lean snapshots
*/
export function extractIds(entities: JsonLdEntity[]): string[] {
return entities
.map((e) => e['@id'])
.filter((id): id is string => typeof id === 'string')
.sort();
}

/**
* Extract @id and @type for more detailed snapshots
*/
export function extractIdsAndTypes(entities: JsonLdEntity[]): { id: string; type: string | string[] }[] {
return entities
.map((e) => ({
id: e['@id'],
type: e['@type'] as string | string[],
}))
.filter((e): e is { id: string; type: string | string[] } => typeof e.id === 'string')
.sort((a, b) => a.id.localeCompare(b.id));
}

/**
* Group entities by @type
*/
export function groupByType(entities: JsonLdEntity[]): Record<string, string[]> {
const grouped: Record<string, string[]> = {};

for (const entity of entities) {
const type = entity['@type'];
const id = entity['@id'];

if (!id) continue;

const types = Array.isArray(type) ? type : [type];
for (const t of types) {
if (t) {
if (!grouped[t]) grouped[t] = [];
grouped[t].push(id);
}
}
}

// Sort IDs within each type
for (const type of Object.keys(grouped)) {
grouped[type].sort();
}

return grouped;
}

/**
* Create a summary of the JSON-LD graph
*/
export interface JsonLdSummary {
totalEntities: number;
entityIds: string[];
byType: Record<string, string[]>;
}

export function createJsonLdSummary(entities: JsonLdEntity[]): JsonLdSummary {
return {
totalEntities: entities.length,
entityIds: extractIds(entities),
byType: groupByType(entities),
};
}

/**
* Filter entities that have usesSoftware referencing a specific software ID
*/
export function findOrganizationsUsingSoftware(entities: JsonLdEntity[], softwareId: string): string[] {
return entities
.filter((entity) => {
if (entity['@type'] !== 'Organization') return false;
const usesSoftware = entity.usesSoftware;
if (!usesSoftware) return false;

const refs = Array.isArray(usesSoftware) ? usesSoftware : [usesSoftware];
return refs.some((ref) => {
const refId = typeof ref === 'string' ? ref : ref?.['@id'];
return refId === softwareId;
});
})
.map((e) => e['@id'] as string)
.sort();
}
33 changes: 33 additions & 0 deletions __tests__/jsonld/__snapshots__/graph-validation.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`JSON-LD Graph Validation Graph Integrity should have consistent entity count 1`] = `
{
"totalEntities": 24,
}
`;

exports[`JSON-LD Graph Validation findMissingReferences should find missing references in the graph 1`] = `[]`;

exports[`JSON-LD Graph Validation findNestedEntities should find nested entities in the graph 1`] = `[]`;

exports[`JSON-LD Graph Validation findOrphans should find orphaned entities in the graph 1`] = `
[
"software:latex2js-react",
"software:latex2js-vue",
"webpage:latex2js-example-block-diagram",
"webpage:latex2js-example-complex-plane",
"webpage:latex2js-example-custom-path",
"webpage:latex2js-example-derivative-story",
"webpage:latex2js-example-draggable-vector",
"webpage:latex2js-example-feedback-system",
"webpage:latex2js-example-function-plot",
"webpage:latex2js-example-geometric-series",
"webpage:latex2js-example-interactive-plot",
"webpage:latex2js-example-sampling-system",
"webpage:latex2js-example-shaded-integral",
"webpage:latex2js-example-two-variables",
"webpage:latex2js-example-unit-circle",
"webpage:latex2js-example-vector-functions",
"website:latex2js.com",
]
`;
32 changes: 32 additions & 0 deletions __tests__/jsonld/examples-registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Examples registry tests
*
* The examples registry drives routes, JSON-LD entities, and llms.txt —
* every entry must point at a real .tex file and have a unique slug.
*/

import fs from 'fs';
import path from 'path';

import { examples } from '@/data/examples';

const CONTENT_DIR = path.resolve(__dirname, '../../content/examples');

describe('Examples registry', () => {
it('every example points to an existing .tex file', () => {
examples.forEach((example) => {
expect(fs.existsSync(path.join(CONTENT_DIR, example.file))).toBe(true);
});
});

it('every .tex file is registered exactly once', () => {
const texFiles = fs.readdirSync(CONTENT_DIR).filter((f) => f.endsWith('.tex'));
const registered = examples.map((e) => e.file).sort();
expect(registered).toEqual(texFiles.sort());
});

it('slugs are unique', () => {
const slugs = examples.map((e) => e.slug);
expect(new Set(slugs).size).toBe(slugs.length);
});
});
85 changes: 85 additions & 0 deletions __tests__/jsonld/graph-validation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* JSON-LD Graph Validation Tests
*
* Tests for graph integrity - checking for missing references,
* nested entities, orphans, and duplicates.
*/

import { findMissingReferences, findNestedEntities, findOrphans } from 'jsonldjs';

import { jsonldGraph } from '@/data/jsonld';

describe('JSON-LD Graph Validation', () => {
describe('findMissingReferences', () => {
it('should find missing references in the graph', () => {
const missingRefs = findMissingReferences(jsonldGraph);

if (missingRefs.length > 0) {
console.log('Missing references found:', missingRefs.length);
console.log('First 10 missing references:', missingRefs.slice(0, 10));
}

expect(missingRefs.sort()).toMatchSnapshot();
});
});

describe('findNestedEntities', () => {
it('should find nested entities in the graph', () => {
const nestedEntities = findNestedEntities(jsonldGraph);

const summary = nestedEntities.map((n) => ({
parentId: n.parentId,
property: n.property,
hasId: n.hasId,
type: n.nestedEntity['@type'],
}));

expect(summary).toMatchSnapshot();
});
});

describe('findOrphans', () => {
it('should find orphaned entities in the graph', () => {
const orphans = findOrphans(jsonldGraph);

if (orphans.length > 0) {
console.log('Orphaned entities found:', orphans.length);
console.log('First 10 orphaned entities:', orphans.slice(0, 10));
}

expect(orphans.sort()).toMatchSnapshot();
});
});

describe('Graph Integrity', () => {
it('should track duplicate IDs in the graph', () => {
const ids = jsonldGraph.map((e) => e['@id']).filter(Boolean);
const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
const uniqueDuplicates = [...new Set(duplicates)].sort();

expect(uniqueDuplicates).toEqual([]);
});

it('should have software:latex2js in the graph', () => {
const latex2js = jsonldGraph.find((e) => e['@id'] === 'software:latex2js');
expect(latex2js).toBeDefined();
expect(latex2js?.['@type']).toBe('SoftwareApplication');
});

it('should have website:latex2js.com in the graph', () => {
const website = jsonldGraph.find((e) => e['@id'] === 'website:latex2js.com');
expect(website).toBeDefined();
expect(website?.['@type']).toBe('WebSite');
});

it('should have no missing references', () => {
expect(findMissingReferences(jsonldGraph)).toEqual([]);
});

it('should have consistent entity count', () => {
expect({
totalEntities: jsonldGraph.length,
}).toMatchSnapshot();
});
});
});
75 changes: 0 additions & 75 deletions assets/css/latex2js.css

This file was deleted.

26 changes: 0 additions & 26 deletions assets/css/website.css

This file was deleted.

Loading