All files / scripts/sitemap-html/articles docs-sections.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                                          7x 7x   7x                                 21x                
/**
 * @module Infrastructure/SitemapHtml/Articles/DocsSections
 * @category Intelligence Operations / Supporting Infrastructure
 * @name Docs sections probe
 *
 * @description
 * Cheap filesystem probe that records which `docs/` sections exist
 * (api / coverage / test-results / cypress / index). The sitemap render
 * uses this to conditionally show or hide the "Resources" section
 * entries and avoid emitting links to missing pages.
 *
 * Round-6 split: extracted from `scripts/generate-sitemap-html.ts`.
 *
 * @author Hack23 AB (Infrastructure Team)
 * @license Apache-2.0
 */
 
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
 
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
 
const DOCS_DIR = path.join(__dirname, '..', '..', '..', 'docs');
 
/** Boolean flags for each known documentation subsection. */
export interface DocsSections {
  readonly api: boolean;
  readonly coverage: boolean;
  readonly testResults: boolean;
  readonly cypress: boolean;
  readonly index: boolean;
}
 
/**
 * Probe the local `docs/` tree to determine which sections were built and
 * are therefore safe to link from the sitemap. Pure with respect to its
 * inputs (read-only filesystem checks).
 */
export function getDocsSections(): DocsSections {
  return {
    index: fs.existsSync(path.join(DOCS_DIR, 'index.html')),
    api: fs.existsSync(path.join(DOCS_DIR, 'api', 'index.html')),
    coverage: fs.existsSync(path.join(DOCS_DIR, 'coverage', 'index.html')),
    testResults: fs.existsSync(path.join(DOCS_DIR, 'test-results', 'index.html')),
    cypress: fs.existsSync(path.join(DOCS_DIR, 'cypress', 'index.html')),
  };
}