Skip to content
Closed
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
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ jobs:

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10

- name: Install Dependencies
run: pnpm install
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"engines": {
"node": ">=20.0.0"
},
"packageManager": "pnpm@9.15.4",
"dependencies": {
"vite": "7.3.1"
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/cli/src/utils/exportRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'node:path';
import fs from 'node:fs/promises';
import chalk from 'chalk';
import {
generateHtml,
renderSitegraphHtml,
renderSitegraphMarkdown,
renderSitegraphCsvNodes,
renderSitegraphCsvEdges,
Expand Down Expand Up @@ -37,13 +37,13 @@ export async function runSitegraphExports(
}

if (formats.includes('html')) {
const html = generateHtml(graphData, metrics);
const html = renderSitegraphHtml(graphData, metrics);
await fs.writeFile(path.join(outputDir, 'graph.html'), html);
console.log(chalk.green(`HTML report saved to ${path.join(outputDir, 'graph.html')}`));
}

if (formats.includes('visualize')) {
const siteGraphHtml = generateHtml(graphData, metrics);
const siteGraphHtml = renderSitegraphHtml(graphData, metrics);
await fs.writeFile(path.join(outputDir, 'sitegraph.html'), siteGraphHtml);
console.log(chalk.green(`Visualization saved to ${path.join(outputDir, 'sitegraph.html')}`));
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/cli/tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vi.mock('@crawlith/core', async (importOriginal) => {
...actual,
crawl: vi.fn(),
calculateMetrics: vi.fn(),
generateHtml: vi.fn(),
renderSitegraphHtml: vi.fn(),
compareGraphs: vi.fn(),
analyzeSite: vi.fn(),
renderAnalysisHtml: vi.fn(),
Expand Down Expand Up @@ -66,7 +66,7 @@ test('sitegraph command execution (DB-only, no file writes)', async () => {

// No file writes in DB-only mode (only lock file from LockManager)
expect(fs.mkdir).not.toHaveBeenCalled();
expect(core.generateHtml).not.toHaveBeenCalled();
expect(core.renderSitegraphHtml).not.toHaveBeenCalled();

// Verify snapshot ID is logged
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('snapshot #123'));
Expand Down Expand Up @@ -95,13 +95,13 @@ test('sitegraph --html flag triggers file export', async () => {
topPageRankPages: [],
limitReached: false
});
vi.mocked(core.generateHtml).mockReturnValue('<html></html>');
vi.mocked(core.renderSitegraphHtml).mockReturnValue('<html></html>');

const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { });

await sitegraph.parseAsync(['https://example.com', '--limit', '10', '--export', 'html', '--output', 'test-output'], { from: 'user' });

expect(core.generateHtml).toHaveBeenCalled();
expect(core.renderSitegraphHtml).toHaveBeenCalled();
expect(fs.mkdir).toHaveBeenCalledWith(expect.stringContaining('test-output'), { recursive: true });
expect(fs.writeFile).toHaveBeenCalledWith(expect.stringContaining('graph.html'), '<html></html>');

Expand Down
1 change: 0 additions & 1 deletion plugins/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './crawler/crawl.js';
export * from './crawler/metricsRunner.js';
export * from './graph/metrics.js';
export * from './report/html.js';
export * from './report/sitegraph_template.js';
export * from './report/sitegraphExport.js';
export * from './graph/graph.js';
Expand Down
27 changes: 0 additions & 27 deletions plugins/core/src/report/html.ts

This file was deleted.

28 changes: 28 additions & 0 deletions plugins/core/src/report/sitegraphExport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
import { Metrics } from '../graph/metrics.js';
import { SITEGRAPH_HTML } from './sitegraph_template.js';

function safeJson(data: any): string {
return JSON.stringify(data).replace(/</g, '\\u003c');
}

export function renderSitegraphHtml(graphData: any, metrics: Metrics): string {
// Strip heavy HTML content from nodes to keep the report lightweight
const vizGraphData = {
...graphData,
nodes: graphData.nodes ? graphData.nodes.map((n: any) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { html, ...rest } = n;
return rest;
}) : []
};

const graphJson = safeJson(vizGraphData);
const metricsJson = safeJson(metrics);

return SITEGRAPH_HTML.replace('</body>', `<script>
window.GRAPH_DATA = ${graphJson};
window.METRICS_DATA = ${metricsJson};
</script>
</body>`);
}

export function renderSitegraphCsvNodes(graphData: any): string {
const nodeHeaders = ['URL', 'Depth', 'Status', 'InboundLinks', 'OutboundLinks', 'PageRankScore'];
const nodeRows = graphData.nodes.map((n: any) => {
Expand Down
6 changes: 3 additions & 3 deletions plugins/core/tests/html_report.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'vitest';
import { generateHtml } from '../src/report/html.js';
import { renderSitegraphHtml } from '../src/report/sitegraphExport.js';
import { Metrics } from '../src/graph/metrics.js';

describe('html report generator', () => {
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('html report generator', () => {
edges: []
};

const html = generateHtml(mockGraphData, mockMetrics);
const html = renderSitegraphHtml(mockGraphData, mockMetrics);

// Check for template content
expect(html).toContain('<!DOCTYPE html>');
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('html report generator', () => {
topAuthorityPages: [],
sessionStats: null
};
const html = generateHtml({ nodes: [], edges: [] }, mockMetrics as any);
const html = renderSitegraphHtml({ nodes: [], edges: [] }, mockMetrics as any);
expect(html).toContain('window.METRICS_DATA =');
expect(html).toContain('"totalPages":10');
expect(html).toContain('"sessionStats":null');
Expand Down
Loading