Skip to content
Merged
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
33 changes: 30 additions & 3 deletions plugins/core/scripts/copy-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,34 @@ import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const src = path.join(__dirname, '../src/report/sitegraph.html');
const dest = path.join(__dirname, '../dist/report/sitegraph.html');

fs.copyFileSync(src, dest);
// Ensure dist directories exist
const reportDestDir = path.join(__dirname, '../dist/report');
if (!fs.existsSync(reportDestDir)){
fs.mkdirSync(reportDestDir, { recursive: true });
}

const analysisDestDir = path.join(__dirname, '../dist/analysis');
if (!fs.existsSync(analysisDestDir)){
fs.mkdirSync(analysisDestDir, { recursive: true });
}

// Copy Report Assets
const sitegraphSrc = path.join(__dirname, '../src/report/sitegraph.html');
const sitegraphDest = path.join(reportDestDir, 'sitegraph.html');
if (fs.existsSync(sitegraphSrc)) {
fs.copyFileSync(sitegraphSrc, sitegraphDest);
}

// Copy Analysis Assets
const analysisListSrc = path.join(__dirname, '../src/analysis/analysis_list.html');
const analysisListDest = path.join(analysisDestDir, 'analysis_list.html');
if (fs.existsSync(analysisListSrc)) {
fs.copyFileSync(analysisListSrc, analysisListDest);
}

const analysisPageSrc = path.join(__dirname, '../src/analysis/analysis_page.html');
const analysisPageDest = path.join(analysisDestDir, 'analysis_page.html');
if (fs.existsSync(analysisPageSrc)) {
fs.copyFileSync(analysisPageSrc, analysisPageDest);
}
35 changes: 35 additions & 0 deletions plugins/core/src/analysis/analysis_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Crawlith Analysis Report</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 1000px; margin: 0 auto; padding: 20px; color: #333; }
h1 { border-bottom: 2px solid #eee; padding-bottom: 10px; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { padding: 8px 12px; border: 1px solid #ddd; text-align: left; }
th { background-color: #f4f4f4; }
tr:nth-child(even) { background-color: #f9f9f9; }
tr:hover { background-color: #f1f1f1; }
</style>
</head>
<body>
<h1>Analysis</h1>
<p>Pages: {{PAGES_ANALYZED}}</p>
<p>Average SEO: {{AVG_SEO_SCORE}}</p>
<table border="1" cellspacing="0" cellpadding="6">
<thead>
<tr>
<th>URL</th>
<th>SEO Score</th>
<th>Thin Score</th>
<th>Title</th>
<th>Meta</th>
</tr>
</thead>
<tbody>
{{ROWS}}
</tbody>
</table>
</body>
</html>
123 changes: 123 additions & 0 deletions plugins/core/src/analysis/analysis_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analysis for {{URL}}</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; line-height: 1.6; color: #333; }
h1 { border-bottom: 2px solid #eee; padding-bottom: 10px; }
h2 { margin-top: 30px; border-bottom: 1px solid #eee; padding-bottom: 5px; }
.score-card { display: flex; gap: 20px; margin-bottom: 30px; }
.score-box { background: #f8f9fa; padding: 15px; border-radius: 8px; text-align: center; flex: 1; border: 1px solid #e1e4e8; }
.score-val { font-size: 24px; font-weight: bold; color: #0366d6; }
.status-ok { color: green; font-weight: bold; }
.status-warning { color: orange; font-weight: bold; }
.status-critical { color: red; font-weight: bold; }
.status-missing { color: red; font-weight: bold; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.data-table th, .data-table td { text-align: left; padding: 8px; border-bottom: 1px solid #eee; }
.data-table th { width: 150px; color: #666; }
code { background: #f6f8fa; padding: 2px 4px; border-radius: 3px; font-size: 0.9em; }
</style>
</head>
<body>
<h1>Page Analysis</h1>
<p><strong>URL:</strong> <a href="{{URL}}" target="_blank">{{URL}}</a></p>

<div class="score-card">
<div class="score-box">
<div class="score-val">{{SEO_SCORE}}</div>
<div>SEO Score</div>
</div>
<div class="score-box">
<div class="score-val">{{THIN_SCORE}}</div>
<div>Thin Content Score</div>
</div>
<div class="score-box">
<div class="score-val">{{HTTP_STATUS}}</div>
<div>HTTP Status</div>
</div>
</div>

<h2>Meta Tags</h2>
<table class="data-table">
<tr>
<th>Title</th>
<td>
<div>{{TITLE_VALUE}}</div>
<small>Length: {{TITLE_LENGTH}} | Status: <span class="status-{{TITLE_STATUS}}">{{TITLE_STATUS}}</span></small>
</td>
</tr>
<tr>
<th>Description</th>
<td>
<div>{{META_DESCRIPTION_VALUE}}</div>
<small>Length: {{META_DESCRIPTION_LENGTH}} | Status: <span class="status-{{META_DESCRIPTION_STATUS}}">{{META_DESCRIPTION_STATUS}}</span></small>
</td>
</tr>
<tr>
<th>Canonical</th>
<td>{{CANONICAL}}</td>
</tr>
<tr>
<th>Robots</th>
<td>
Index: {{ROBOTS_INDEX}},
Follow: {{ROBOTS_FOLLOW}}
</td>
</tr>
</table>

<h2>Content & Heading</h2>
<table class="data-table">
<tr>
<th>H1 Tag</th>
<td>
Status: <span class="status-{{H1_STATUS}}">{{H1_STATUS}}</span>
({{H1_COUNT}} detected)
{{H1_MATCHES_TITLE}}
</td>
</tr>
<tr>
<th>Word Count</th>
<td>{{WORD_COUNT}} words</td>
</tr>
<tr>
<th>Unique Sentences</th>
<td>{{UNIQUE_SENTENCES}}</td>
</tr>
<tr>
<th>Text / HTML Ratio</th>
<td>{{TEXT_HTML_RATIO}}%</td>
</tr>
</table>

<h2>Links & Images</h2>
<table class="data-table">
<tr>
<th>Internal Links</th>
<td>{{INTERNAL_LINKS}}</td>
</tr>
<tr>
<th>External Links</th>
<td>{{EXTERNAL_LINKS}} ({{EXTERNAL_RATIO}}%)</td>
</tr>
<tr>
<th>Images</th>
<td>{{TOTAL_IMAGES}} total ({{MISSING_ALT}} missing alt text)</td>
</tr>
</table>

<h2>Structured Data</h2>
<table class="data-table">
<tr>
<th>Status</th>
<td>
{{STRUCTURED_DATA_STATUS}}
</td>
</tr>
{{STRUCTURED_DATA_TYPES_ROW}}
</table>
</body>
</html>
167 changes: 39 additions & 128 deletions plugins/core/src/analysis/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getDb } from '../db/index.js';
import { SiteRepository } from '../db/repositories/SiteRepository.js';
import { SnapshotRepository } from '../db/repositories/SnapshotRepository.js';
import { PageRepository } from '../db/repositories/PageRepository.js';
import { ANALYSIS_LIST_TEMPLATE, ANALYSIS_PAGE_TEMPLATE } from './templates.js';

export interface CrawlPage {
url: string;
Expand Down Expand Up @@ -155,144 +156,54 @@ export function renderAnalysisHtml(result: AnalysisResult): string {
return renderSinglePageHtml(result.pages[0]);
}
const rows = result.pages
.map((page) => `< tr > <td>${escapeHtml(page.url)} </td><td>${page.seoScore}</td > <td>${page.thinScore} </td><td>${page.title.status}</td > <td>${page.metaDescription.status} </td></tr > `)
.map((page) => `<tr><td>${escapeHtml(page.url)}</td><td>${page.seoScore}</td><td>${page.thinScore}</td><td>${page.title.status}</td><td>${page.metaDescription.status}</td></tr>`)
.join('');

return `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><title>Crawlith Analysis Report</title></head><body><h1>Analysis</h1><p>Pages: ${result.site_summary.pages_analyzed}</p><p>Average SEO: ${result.site_summary.avg_seo_score}</p><table border="1" cellspacing="0" cellpadding="6"><thead><tr><th>URL</th><th>SEO Score</th><th>Thin Score</th><th>Title</th><th>Meta</th></tr></thead><tbody>${rows}</tbody></table></body></html>`;
return ANALYSIS_LIST_TEMPLATE
.replace('{{PAGES_ANALYZED}}', result.site_summary.pages_analyzed.toString())
.replace('{{AVG_SEO_SCORE}}', result.site_summary.avg_seo_score.toString())
.replace('{{ROWS}}', rows);
}

function renderSinglePageHtml(page: PageAnalysis): string {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analysis for ${escapeHtml(page.url)}</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; line-height: 1.6; color: #333; }
h1 { border-bottom: 2px solid #eee; padding-bottom: 10px; }
h2 { margin-top: 30px; border-bottom: 1px solid #eee; padding-bottom: 5px; }
.score-card { display: flex; gap: 20px; margin-bottom: 30px; }
.score-box { background: #f8f9fa; padding: 15px; border-radius: 8px; text-align: center; flex: 1; border: 1px solid #e1e4e8; }
.score-val { font-size: 24px; font-weight: bold; color: #0366d6; }
.status-ok { color: green; font-weight: bold; }
.status-warning { color: orange; font-weight: bold; }
.status-critical { color: red; font-weight: bold; }
.status-missing { color: red; font-weight: bold; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.data-table th, .data-table td { text-align: left; padding: 8px; border-bottom: 1px solid #eee; }
.data-table th { width: 150px; color: #666; }
code { background: #f6f8fa; padding: 2px 4px; border-radius: 3px; font-size: 0.9em; }
</style>
</head>
<body>
<h1>Page Analysis</h1>
<p><strong>URL:</strong> <a href="${page.url}" target="_blank">${page.url}</a></p>

<div class="score-card">
<div class="score-box">
<div class="score-val">${page.seoScore}</div>
<div>SEO Score</div>
</div>
<div class="score-box">
<div class="score-val">${page.thinScore}</div>
<div>Thin Content Score</div>
</div>
<div class="score-box">
<div class="score-val">${page.status === 0 ? 'Pending/Limit' : page.status}</div>
<div>HTTP Status</div>
</div>
</div>

<h2>Meta Tags</h2>
<table class="data-table">
<tr>
<th>Title</th>
<td>
<div>${escapeHtml(page.title.value || '(missing)')}</div>
<small>Length: ${page.title.length} | Status: <span class="status-${page.title.status}">${page.title.status}</span></small>
</td>
</tr>
<tr>
<th>Description</th>
<td>
<div>${escapeHtml(page.metaDescription.value || '(missing)')}</div>
<small>Length: ${page.metaDescription.length} | Status: <span class="status-${page.metaDescription.status}">${page.metaDescription.status}</span></small>
</td>
</tr>
<tr>
<th>Canonical</th>
<td>${page.meta.canonical ? escapeHtml(page.meta.canonical) : '<em>(none)</em>'}</td>
</tr>
<tr>
<th>Robots</th>
<td>
Index: ${!page.meta.noindex},
Follow: ${!page.meta.nofollow}
</td>
</tr>
</table>

<h2>Content & Heading</h2>
<table class="data-table">
<tr>
<th>H1 Tag</th>
<td>
Status: <span class="status-${page.h1.status}">${page.h1.status}</span>
(${page.h1.count} detected)
${page.h1.matchesTitle ? ' | Matches Title' : ''}
</td>
</tr>
<tr>
<th>Word Count</th>
<td>${page.content.wordCount} words</td>
</tr>
<tr>
<th>Unique Sentences</th>
<td>${page.content.uniqueSentenceCount}</td>
</tr>
<tr>
<th>Text / HTML Ratio</th>
<td>${(page.content.textHtmlRatio * 100).toFixed(2)}%</td>
</tr>
</table>

<h2>Links & Images</h2>
<table class="data-table">
<tr>
<th>Internal Links</th>
<td>${page.links.internalLinks}</td>
</tr>
<tr>
<th>External Links</th>
<td>${page.links.externalLinks} (${(page.links.externalRatio * 100).toFixed(1)}%)</td>
</tr>
<tr>
<th>Images</th>
<td>${page.images.totalImages} total (${page.images.missingAlt} missing alt text)</td>
</tr>
</table>

<h2>Structured Data</h2>
<table class="data-table">
<tr>
<th>Status</th>
<td>
${page.structuredData.present
const structuredDataStatus = page.structuredData.present
? (page.structuredData.valid ? '<span class="status-ok">Valid</span>' : '<span class="status-critical">Invalid JSON</span>')
: 'Not detected'
}
</td>
</tr>
${page.structuredData.present ? `
: 'Not detected';

const structuredDataTypesRow = page.structuredData.present ? `
<tr>
<th>Types Found</th>
<td>${page.structuredData.types.map(t => `<code>${t}</code>`).join(', ')}</td>
</tr>
` : ''}
</table>
</body>
</html>`;
` : '';

return ANALYSIS_PAGE_TEMPLATE
.replaceAll('{{URL}}', escapeHtml(page.url))
.replace('{{SEO_SCORE}}', page.seoScore.toString())
.replace('{{THIN_SCORE}}', page.thinScore.toString())
.replace('{{HTTP_STATUS}}', page.status === 0 ? 'Pending/Limit' : page.status.toString())
.replace('{{TITLE_VALUE}}', escapeHtml(page.title.value || '(missing)'))
.replace('{{TITLE_LENGTH}}', page.title.length.toString())
.replaceAll('{{TITLE_STATUS}}', page.title.status)
.replace('{{META_DESCRIPTION_VALUE}}', escapeHtml(page.metaDescription.value || '(missing)'))
.replace('{{META_DESCRIPTION_LENGTH}}', page.metaDescription.length.toString())
.replaceAll('{{META_DESCRIPTION_STATUS}}', page.metaDescription.status)
.replace('{{CANONICAL}}', page.meta.canonical ? escapeHtml(page.meta.canonical) : '<em>(none)</em>')
.replace('{{ROBOTS_INDEX}}', (!page.meta.noindex).toString())
.replace('{{ROBOTS_FOLLOW}}', (!page.meta.nofollow).toString())
.replaceAll('{{H1_STATUS}}', page.h1.status)
.replace('{{H1_COUNT}}', page.h1.count.toString())
.replace('{{H1_MATCHES_TITLE}}', page.h1.matchesTitle ? ' | Matches Title' : '')
.replace('{{WORD_COUNT}}', page.content.wordCount.toString())
.replace('{{UNIQUE_SENTENCES}}', page.content.uniqueSentenceCount.toString())
.replace('{{TEXT_HTML_RATIO}}', (page.content.textHtmlRatio * 100).toFixed(2))
.replace('{{INTERNAL_LINKS}}', page.links.internalLinks.toString())
.replace('{{EXTERNAL_LINKS}}', page.links.externalLinks.toString())
.replace('{{EXTERNAL_RATIO}}', (page.links.externalRatio * 100).toFixed(1))
.replace('{{TOTAL_IMAGES}}', page.images.totalImages.toString())
.replace('{{MISSING_ALT}}', page.images.missingAlt.toString())
.replace('{{STRUCTURED_DATA_STATUS}}', structuredDataStatus)
.replace('{{STRUCTURED_DATA_TYPES_ROW}}', structuredDataTypesRow);
}

export function renderAnalysisMarkdown(result: AnalysisResult): string {
Expand Down
9 changes: 9 additions & 0 deletions plugins/core/src/analysis/templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export const ANALYSIS_LIST_TEMPLATE = fs.readFileSync(path.join(__dirname, 'analysis_list.html'), 'utf-8');
export const ANALYSIS_PAGE_TEMPLATE = fs.readFileSync(path.join(__dirname, 'analysis_page.html'), 'utf-8');
Loading
Loading