GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Electricity markets and data pipelines / pipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/data

Newspaper News v1 Base and 4 more files

A JavaScript module in the plugins folder of PipelineNews that draws major project news and battery storage (BESS), and uses data from the GlobalGrid2050 repository.

535 lines of JavaScript from pipelinenews, in 5 files. Topic: Electricity markets and data pipelines. Section 984 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Canonical Projects News v1 Release automation · pipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/data/canonical-projects-newsv1-release.js lines 1–34
  2. Canonical Projects News v1 render · pipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/data/canonical-projects-newsv1.js lines 1–129
  3. Gauges V9 2 render · pipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/plugins/gauges-v9-2.js lines 1–94
  4. Newspaper News v1 Base render · pipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/plugins/newspaper-newsv1-base.js lines 1–177
  5. Newspaper News v1 render · pipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/plugins/newspaper-newsv1.js lines 1–101

Canonical Projects News v1 Release

A JavaScript module in the data folder of PipelineNews that fetches release newsv1. It fetches release (`fetchRelease`).

automationpipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/data/canonical-projects-newsv1-release.js · lines 1–34 of 34 · version 2026-08-26 15:47 · pattern fetchRelease (shared by 9 files)

What it does
It fetches release newsv1. Defines invariant, fetchRelease, loadCanonicalProjectsNewsV1Release. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage experimental (path word 'archive'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Inputs & outputs
In: JSON file release.newsv1.json.
Downstream impact
Used directly by 1 file: Projects News v1 (pipelinenews). Reached from 4 other entry points, including PipelineNews — News v1 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv1/); PipelineNews — News v7 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv7/); PipelineNews — PipelineNews Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/202608251651-PipelineNews/).
What it achieves
Defines `invariant`, `fetchRelease` and `loadCanonicalProjectsNewsV1Release`.
Why it matters
Imported by Projects News v1.
Application
pipelinenews · archive/202608261547-pipelinenews/newsv1/scripts/data · JavaScript module
Uses
Canonical Projects News v1 (import)
Used by
imported by Projects News v1 (import)
Produces
loadCanonicalProjectsNewsV1Release
Defines here
invariant, fetchRelease, loadCanonicalProjectsNewsV1Release
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
pipelinenews@45c944c8640a9d7ae65edb51d66032ba204f3f46 archive/202608261547-pipelinenews/newsv1/scripts/data/canonical-projects-newsv1-release.js:1-34 · blob fd38cc2bd7d64f3d617a0b9580880cc5f7d123f3 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
import { loadCanonicalProjectsNewsV1 } from "./canonical-projects-newsv1.js";

const RELEASE_URL = "contracts/release.newsv1.json";

function invariant(condition, message) {
  if (!condition) throw new Error(`News V1 canonical projects: ${message}`);
}

async function fetchRelease() {
  const response = await fetch(RELEASE_URL, { cache: "default" });
  invariant(response.ok, `${RELEASE_URL} returned HTTP ${response.status}`);
  invariant(new URL(response.url).origin === window.location.origin, `${RELEASE_URL} redirected cross-origin`);
  return response.json();
}

export async function loadCanonicalProjectsNewsV1Release({ onFirstPartition } = {}) {
  const release = await fetchRelease();
  invariant(release.release === "newsv1", "release contract mismatch");
  invariant(release.frozen_source?.release === "9.7", "frozen-source release mismatch");
  invariant(release.data_parent?.release === "9.1", "data-parent release mismatch");
  const model = await loadCanonicalProjectsNewsV1({ onFirstPartition });
  invariant(model.contract.release === "9.1", "canonical data contract mismatch");
  invariant(model.projects.length === release.expected.project_count, "project count mismatch");
  invariant(model.metadata.capacity_mw === release.expected.capacity_mw, "capacity mismatch");
  invariant(model.metadata.largest_mw === release.expected.largest_mw, "largest project mismatch");
  invariant(model.metadata.geometry_count === release.expected.valid_geometry_count, "valid geometry count mismatch");
  invariant(model.metadata.missing_geometry_count === release.expected.missing_geometry_count, "missing geometry count mismatch");
  return Object.freeze({
    release: Object.freeze(release),
    dataContract: model.contract,
    metadata: Object.freeze({ ...model.metadata, ui_release: "newsv1" }),
    projects: model.projects,
  });
}

Canonical Projects News v1

A JavaScript module in the data folder of PipelineNews that fetches solar, battery storage (BESS) and the Renewable Energy Planning Database (REPD) register.

renderpipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/data/canonical-projects-newsv1.js · lines 1–129 of 129 · version 2026-08-26 15:47 · pattern loadCanonicalProjectsNews (shared by 2 files)

What it does
It fetches solar, battery storage (BESS) and the REPD register. Defines 10 functions or classes, including invariant, round2, fetchJson, mapWithConcurrency, worker. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage experimental (path word 'archive'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: solar, battery storage (BESS), the REPD register.
Inputs & outputs
In: JSON file release.v9.1.json; JSON file build_manifest.json.
Downstream impact
Used directly by 1 file: Canonical Projects News v1 Release (pipelinenews). Reached from 4 other entry points, including PipelineNews — News v1 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv1/); PipelineNews — News v7 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv7/); PipelineNews — PipelineNews Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/202608251651-PipelineNews/).
What it achieves
It fetches JSON (`fetchJson`), maps concurrency (`mapWithConcurrency`) and validates partition (`validatePartition`). Defines `invariant`, `round2`, `fetchJson` and 7 more. Its code works with 1 MW.
Why it matters
Imported by Canonical Projects News v1 Release.
Application
pipelinenews · archive/202608261547-pipelinenews/newsv1/scripts/data · JavaScript module
Uses
none found
Used by
imported by Canonical Projects News v1 Release (import)
Produces
loadCanonicalProjectsNewsV1
Defines here
invariant, round2, fetchJson, mapWithConcurrency, worker, validatePartition, fetchPartition, validateProjects, loadCanonicalProjects, loadCanonicalProjectsNewsV1
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
pipelinenews@45c944c8640a9d7ae65edb51d66032ba204f3f46 archive/202608261547-pipelinenews/newsv1/scripts/data/canonical-projects-newsv1.js:1-129 · blob a381c1b4704865ea823a71c13b8de51837ba5a7a · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
const CONTRACT_URL = "contracts/release.v9.1.json";
const MANIFEST_URL = "data/v9.1/build_manifest.json";
const ALLOWED_TECHNOLOGIES = new Set(["solar", "bess", "wind_onshore", "wind_offshore"]);
const FETCH_CONCURRENCY = 4;
const FETCH_TIMEOUT_MS = 15000;
let canonicalLoadPromise = null;

function invariant(condition, message) {
  if (!condition) throw new Error(`V9.1 canonical projects: ${message}`);
}

function round2(value) {
  return Math.round((value + Number.EPSILON) * 100) / 100;
}

async function fetchJson(path) {
  const controller = new AbortController();
  const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
  try {
    const response = await fetch(path, { cache: "default", signal: controller.signal });
    invariant(response.ok, `${path} returned HTTP ${response.status}`);
    invariant(new URL(response.url).origin === window.location.origin, `${path} redirected cross-origin`);
    return await response.json();
  } finally {
    clearTimeout(timeout);
  }
}

async function mapWithConcurrency(items, task) {
  const output = new Array(items.length);
  let next = 0;
  async function worker() {
    while (next < items.length) {
      const index = next;
      next += 1;
      output[index] = await task(items[index], index);
    }
  }
  await Promise.all(Array.from({ length: Math.min(FETCH_CONCURRENCY, items.length) }, worker));
  return output;
}

function validatePartition(partition, part) {
  invariant(part.schema === "globalgrid2050.v9.project-partition.v9.1", `${partition.path} schema mismatch`);
  invariant(part.record_count === partition.record_count && part.projects.length === partition.record_count, `${partition.path} count mismatch`);
  return part.projects;
}

async function fetchPartition(partition) {
  return validatePartition(partition, await fetchJson(partition.path));
}

function validateProjects(sourceProjects) {
  const refs = new Set();
  const projectIds = new Set();
  let capacity = 0;
  let largest = 0;
  const counts = { solar: 0, bess: 0, wind_onshore: 0, wind_offshore: 0 };
  const projects = sourceProjects.map((project) => {
    invariant(typeof project.repd_ref === "string" && project.repd_ref, "missing REPD Ref");
    invariant(project.gg_project_id === `GG2050-REPD-${project.repd_ref}`, `invalid ID for ${project.repd_ref}`);
    invariant(project.identity_status === "REPD_BOUND" && project.identity_confidence === "authoritative", `unbound identity for ${project.repd_ref}`);
    invariant(ALLOWED_TECHNOLOGIES.has(project.technology), `out-of-scope technology for ${project.repd_ref}`);
    invariant(Number.isFinite(project.capacity_mw) && project.capacity_mw >= 1, `capacity below 1 MW for ${project.repd_ref}`);
    invariant(!refs.has(project.repd_ref), `duplicate REPD Ref ${project.repd_ref}`);
    invariant(!projectIds.has(project.gg_project_id), `duplicate project ID ${project.gg_project_id}`);
    refs.add(project.repd_ref);
    projectIds.add(project.gg_project_id);
    counts[project.technology] += 1;
    capacity += project.capacity_mw;
    largest = Math.max(largest, project.capacity_mw);
    return Object.freeze({ ...project });
  });
  return { projects, capacity, largest, counts };
}

async function loadCanonicalProjects(onFirstPartition) {
  const [contract, payload] = await Promise.all([fetchJson(CONTRACT_URL), fetchJson(MANIFEST_URL)]);
  invariant(contract.release === "9.1", "release contract mismatch");
  invariant(payload.schema === "globalgrid2050.v9.project-spine-build.v9.1", "project manifest schema mismatch");
  invariant(payload.release === "9.1", "project release mismatch");
  invariant(Array.isArray(payload.project_partitions) && payload.project_partitions.length > 0, "project partitions missing");
  invariant(payload.source_identity_sha256 === contract.source.identity_fixture_sha256, "identity hash mismatch");
  invariant(payload.source_coordinate_fixture_sha256 === contract.source.coordinate_fixture_sha256, "coordinate hash mismatch");
  invariant(payload.source_workbook_sha256 === contract.source.workbook_sha256, "workbook hash mismatch");

  const [firstDescriptor, ...remainingDescriptors] = payload.project_partitions;
  const firstProjects = await fetchPartition(firstDescriptor);
  const preview = validateProjects(firstProjects).projects;
  if (typeof onFirstPartition === "function") {
    onFirstPartition(Object.freeze({
      projects: Object.freeze(preview),
      loaded_count: preview.length,
      total_count: payload.project_count,
    }));
  }
  const remainingPartitions = await mapWithConcurrency(remainingDescriptors, fetchPartition);
  const partitions = [firstProjects, ...remainingPartitions];
  const sourceProjects = partitions.flat();
  invariant(sourceProjects.length === payload.project_count, "partition total mismatch");

  const { projects, capacity, largest, counts } = validateProjects(sourceProjects);

  const actual = {
    project_count: projects.length,
    capacity_mw: round2(capacity),
    largest_mw: largest,
    solar_count: counts.solar,
    bess_count: counts.bess,
    wind_onshore_count: counts.wind_onshore,
    wind_offshore_count: counts.wind_offshore,
  };
  Object.entries(contract.expected).forEach(([key, value]) => invariant(actual[key] === value, `${key} is ${actual[key]}, expected ${value}`));
  return Object.freeze({
    contract: Object.freeze(contract),
    metadata: Object.freeze({ ...payload, projects: undefined }),
    projects: Object.freeze(projects),
  });
}

export function loadCanonicalProjectsNewsV1({ onFirstPartition } = {}) {
  if (!canonicalLoadPromise) {
    canonicalLoadPromise = loadCanonicalProjects(onFirstPartition).catch((error) => {
      canonicalLoadPromise = null;
      throw error;
    });
  }
  return canonicalLoadPromise;
}

Gauges V9 2

A JavaScript module in the plugins folder of PipelineNews that updates chart (`updateChart`) and formats capacity v9 (`formatCapacityV9_2`) and largest v9 (`formatLargestV9_2`) (units: MW).

renderpipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/plugins/gauges-v9-2.js · lines 1–94 of 94 · version 2026-08-26 15:47 · pattern loadGaugeChartsNews (shared by 2 files)

What it does
It draws its content. Defines 8 functions or classes, including createGauge, updateChart, formatCapacityV9_2, formatLargestV9_2, initialiseGaugesV9_2. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage experimental (path word 'archive'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Downstream impact
Used directly by 2 files: App News v1 (pipelinenews); Projects News v1 (pipelinenews). Reached from 3 other entry points, including PipelineNews — News v1 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv1/); PipelineNews — News v7 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv7/); PipelineNews — PipelineNews Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/202608251651-PipelineNews/).
What it achieves
It creates gauge (`createGauge`), updates chart (`updateChart`) and formats capacity v9 (`formatCapacityV9_2`). Defines `createGauge`, `updateChart`, `formatCapacityV9_2` and 5 more.
Why it matters
Imported by App News v1 and Projects News v1.
Application
pipelinenews · archive/202608261547-pipelinenews/newsv1/scripts/plugins · JavaScript module
Uses
none found
Used by
imported by App News v1 (import), imported by Projects News v1 (import)
Produces
formatCapacityV9_2, formatLargestV9_2, initialiseGaugesV9_2, loadGaugeChartsNewsV1, setGaugeUniverseV9_2, updateGaugesV9_2
Defines here
createGauge, updateChart, formatCapacityV9_2, formatLargestV9_2, initialiseGaugesV9_2, loadGaugeChartsNewsV1, setGaugeUniverseV9_2, updateGaugesV9_2
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
pipelinenews@45c944c8640a9d7ae65edb51d66032ba204f3f46 archive/202608261547-pipelinenews/newsv1/scripts/plugins/gauges-v9-2.js:1-94 · blob b6c19d4766c7a90505773b521f67975b2a3a81e8 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom · domain stage: experimental · users: none · canonical: production_core
const charts = { capacity: null, projects: null, largest: null };
let universe = [];
let visible = [];
let gaugeOptions = null;
let chartLoadPromise = null;
const CHART_URL = "https://cdn.jsdelivr.net/npm/chart.js@4.5.1/dist/chart.umd.min.js";

function createGauge(canvasId, colour, options) {
  const config = {
    type: "doughnut",
    data: { datasets: [{ data: [0, 1], backgroundColor: [colour, "#222"], borderWidth: 0 }] },
    options,
  };
  if (typeof globalThis.Chart !== "function") return { data: config.data, update() {} };
  return new globalThis.Chart(document.getElementById(canvasId), config);
}

function updateChart(chart, value, maximum) {
  chart.data.datasets[0].data = [value, Math.max(maximum - value, 0)];
  chart.update();
}

export function formatCapacityV9_2(value) {
  const rounded = Math.round(((Number(value) || 0) + Number.EPSILON) * 100) / 100;
  return rounded.toLocaleString("en-GB", {
    minimumFractionDigits: 0,
    maximumFractionDigits: 2,
  });
}

export function formatLargestV9_2(value) {
  return (Number(value) || 0).toLocaleString("en-GB", { maximumFractionDigits: 2 });
}

export function initialiseGaugesV9_2() {
  gaugeOptions = {
    responsive: true,
    maintainAspectRatio: false,
    circumference: 180,
    rotation: 270,
    cutout: "80%",
    plugins: { tooltip: { enabled: false }, legend: { display: false } },
  };
  charts.capacity = createGauge("g1", "#ff00ff", gaugeOptions);
  charts.projects = createGauge("g2", "#00ffff", gaugeOptions);
  charts.largest = createGauge("g3", "#00ff88", gaugeOptions);
}

export function loadGaugeChartsNewsV1() {
  if (typeof globalThis.Chart === "function") return Promise.resolve(true);
  if (chartLoadPromise) return chartLoadPromise;
  chartLoadPromise = new Promise((resolve) => {
    const script = document.createElement("script");
    const timeout = setTimeout(() => resolve(false), 15000);
    script.src = CHART_URL;
    script.async = true;
    script.onload = () => {
      clearTimeout(timeout);
      if (typeof globalThis.Chart !== "function" || !gaugeOptions) return resolve(false);
      initialiseGaugesV9_2();
      updateGaugesV9_2(visible);
      return resolve(true);
    };
    script.onerror = () => { clearTimeout(timeout); resolve(false); };
    document.head.appendChild(script);
  });
  return chartLoadPromise;
}

export function setGaugeUniverseV9_2(projects) {
  universe = projects;
}

export function updateGaugesV9_2(projects) {
  visible = projects;
  const total = projects.reduce((sum, project) => sum + project.capacity_mw, 0);
  const largest = projects.length ? Math.max(...projects.map((project) => project.capacity_mw)) : 0;
  const universeTotal = universe.reduce((sum, project) => sum + project.capacity_mw, 0) || 1;
  const universeLargest = universe.length ? Math.max(...universe.map((project) => project.capacity_mw)) : 1;

  const capacityValue = document.getElementById("v1");
  const projectValue = document.getElementById("v2");
  const largestValue = document.getElementById("v3");
  capacityValue.textContent = formatCapacityV9_2(total);
  projectValue.textContent = projects.length.toLocaleString("en-GB");
  largestValue.textContent = formatLargestV9_2(largest);
  capacityValue.setAttribute("aria-label", `${formatCapacityV9_2(total)} megawatts filtered capacity`);
  projectValue.setAttribute("aria-label", `${projects.length.toLocaleString("en-GB")} filtered records`);
  largestValue.setAttribute("aria-label", `${formatLargestV9_2(largest)} megawatts largest single site`);

  updateChart(charts.capacity, total, universeTotal);
  updateChart(charts.projects, projects.length, universe.length || 1);
  updateChart(charts.largest, largest, universeLargest);
}

Newspaper News v1 Base

A JavaScript module in the plugins folder of PipelineNews that draws major project news and battery storage (BESS), and uses data from the GlobalGrid2050 repository.

renderpipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/plugins/newspaper-newsv1-base.js · lines 1–177 of 177 · version 2026-08-26 15:47 · pattern signalForProjectNews (shared by 2 files)

What it does
It draws major project news, battery storage (BESS), the REPD register and solar. Defines 14 functions or classes, including refreshProjects, canonicalItem, indexNewsItems, signalLabel, signalForProjectNewsV1. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage experimental (path word 'archive'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: battery storage (BESS), the REPD register, solar.
Inputs & outputs
In: data source: globalgrid2050 data; JSON file major_project_news_v9_5_1.json.
Downstream impact
Used directly by 2 files: Newspaper News v1 (pipelinenews); Projects News v1 (pipelinenews). Reached from 4 other entry points, including PipelineNews — News v1 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv1/); PipelineNews — News v7 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv7/); PipelineNews — PipelineNews Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/202608251651-PipelineNews/).
What it achieves
It refreshes projects (`refreshProjects`), indexes news (`indexNewsItems`) and draws news news v1 base (`drawNewsNewsV1Base`). Defines `refreshProjects`, `canonicalItem`, `indexNewsItems` and 11 more.
Why it matters
Imported by Newspaper News v1 and Projects News v1.
Application
pipelinenews · archive/202608261547-pipelinenews/newsv1/scripts/plugins · JavaScript module
Uses
State (import), Testcode — Pipeline (import)
Used by
imported by Newspaper News v1 (import), imported by Projects News v1 (import)
Produces
signalForProjectNewsV1, drawNewsNewsV1Base, loadNewsNewsV1Base, bindNewspaperNewsV1Base
Defines here
refreshProjects, canonicalItem, indexNewsItems, signalLabel, signalForProjectNewsV1, itemTechnology, newsMatches, drawNewsNewsV1Base, validPayload, fetchPayload, renderNews, loadNews, loadNewsNewsV1Base, bindNewspaperNewsV1Base
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
pipelinenews@45c944c8640a9d7ae65edb51d66032ba204f3f46 archive/202608261547-pipelinenews/newsv1/scripts/plugins/newspaper-newsv1-base.js:1-177 · blob 620960bdf7f657e84d75704933042f32962eee14 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
import { state } from "../core/state.js";
import { escapeHtml, isFinanceEvent, normaliseProject } from "../core/utils.js";

const NEWS_SOURCES = Object.freeze([
  ["PipelineNews release", "dist/major_project_news_v9_5_1.json"],
  ["Frozen GlobalGrid source", "https://raw.githubusercontent.com/Ventusltd/globalgrid2050/824a23cd0cf9f90a9df942f1b37a09c2dc6472b7/dist/major_project_news_v9_5_1.json"],
]);
const FETCH_TIMEOUT_MS = 15000;
let newsLoadPromise = null;

let refreshProjects = () => {};
let newsIndex = new Map();

function canonicalItem(item) {
  return item
    && item.role === "PRIMARY_MATCH"
    && item.eligible_for_news_signal === true
    && String(item.repd_ref || "")
    && item.gg_project_id === `GG2050-REPD-${item.repd_ref}`;
}

function indexNewsItems(items) {
  newsIndex = new Map();
  for (const item of items.filter(canonicalItem)) {
    const key = String(item.repd_ref);
    const previous = newsIndex.get(key);
    const candidateDate = Date.parse(String(item.published || "")) || 0;
    const previousDate = previous ? Date.parse(String(previous.published || "")) || 0 : 0;
    if (!previous || Number(item.confidence || 0) > Number(previous.confidence || 0)
      || (Number(item.confidence || 0) === Number(previous.confidence || 0) && candidateDate > previousDate)) {
      newsIndex.set(key, item);
    }
  }
}

function signalLabel(item) {
  const event = String(item.event || "PROJECT UPDATE").toUpperCase();
  if (event === "CONSENT") return { label: "APPROVED*", cls: "approved" };
  if (event === "OPERATIONAL") return { label: "OPERATIONAL*", cls: "operational" };
  if (event === "CONSTRUCTION") return { label: "CONSTRUCTION*", cls: "construction" };
  if (["FINANCIAL CLOSE", "ACQUISITION"].includes(event)) {
    return { label: event === "ACQUISITION" ? "M&A*" : "FINANCED*", cls: "finance" };
  }
  return { label: `${event}*`.slice(0, 22), cls: "" };
}

export function signalForProjectNewsV1(project) {
  const item = newsIndex.get(String(project.repd_ref));
  if (!item) return { label: "—", cls: "none", note: "no exact canonical PRIMARY_MATCH" };
  return {
    ...signalLabel(item),
    note: `canonical PRIMARY_MATCH ${Number(item.confidence || 0)}% · unverified event · ${item.published || "date unavailable"}`,
  };
}

function itemTechnology(item) {
  return String(item.canonical_technology || item.technology || "").toUpperCase();
}

function newsMatches(item) {
  const event = String(item.event || "").toUpperCase();
  const technology = itemTechnology(item);
  if (state.newsMode === "RELEVANT" && item.canonical_relevant !== true) return false;
  if (state.newsMode === "SOLAR" && technology !== "SOLAR") return false;
  if (state.newsMode === "BESS" && technology !== "BESS") return false;
  if (state.newsMode === "CONSENT" && event !== "CONSENT") return false;
  if (state.newsMode === "CONSTRUCTION" && event !== "CONSTRUCTION") return false;
  if (state.newsMode === "OPERATIONAL" && event !== "OPERATIONAL") return false;
  if (state.newsMode === "FINANCE" && !isFinanceEvent(event)) return false;
  if (state.newsQuery) {
    const haystack = normaliseProject([
      item.headline, item.canonical_project, item.project, item.operator, item.county,
      item.source, item.event, item.repd_ref, item.gg_project_id,
    ].join(" "));
    const tokens = normaliseProject(state.newsQuery).split(" ").filter(Boolean);
    if (!tokens.every((token) => haystack.includes(token))) return false;
  }
  return true;
}

export function drawNewsNewsV1Base() {
  const stories = document.getElementById("stories");
  const rows = state.newsItems.filter(newsMatches);
  if (!rows.length) {
    stories.innerHTML = '<div class="news-empty">No headlines match this newspaper filter.</div>';
    return;
  }
  stories.innerHTML = rows.map((item) => {
    const technology = itemTechnology(item);
    const articleClass = technology === "BESS" ? "bess" : "solar";
    const project = item.canonical_project || item.project || "";
    const capacity = Number(item.canonical_capacity_mw ?? item.capacity_mw ?? 0);
    const quality = item.canonical_relevant === true
      ? `<span class="news-quality relevant">RELEVANT ${Number(item.confidence || 0)}%</span> · PRIMARY_MATCH · REPD ${escapeHtml(item.repd_ref)}`
      : '<span class="news-quality unverified">DISCOVERY ONLY</span> · no project signal';
    return `<a class="story ${articleClass}" href="${escapeHtml(item.url)}" target="_blank" rel="noopener"><div class="kicker">${escapeHtml(technology)} · ${escapeHtml(item.event || "PROJECT UPDATE")} · ${escapeHtml(item.published || "")}</div><h3>${escapeHtml(item.headline || project)}</h3><p><span class="project">${escapeHtml(project)}${capacity ? ` · ${capacity.toLocaleString("en-GB")} MW` : ""  … [line shortened here: 636 characters; full line on GitHub]
  }).join("");
}

function validPayload(payload) {
  return payload
    && payload.schema === "globalgrid2050.major-project-news.v9.5.1"
    && payload.release === "9.5.1"
    && Array.isArray(payload.all_items)
    && Array.isArray(payload.canonical_items)
    && payload.all_headline_count === payload.all_items.length
    && payload.relevant_headline_count === payload.canonical_items.length
    && payload.v9_4_baseline_headline_count === 125
    && payload.all_items.every((item) => typeof item.canonical_relevant === "boolean")
    && payload.canonical_items.every(canonicalItem)
    && payload.beacon_fen_contract?.repd_ref === "13599"
    && payload.beacon_fen_contract?.official_capacity_mw === 400;
}

async function fetchPayload(label, url) {
  const target = new URL(url, window.location.href);
  const controller = new AbortController();
  const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
  try {
    const response = await fetch(target, { cache: "default", signal: controller.signal });
    if (!response.ok) throw new Error(`${label} ${response.status}`);
    const data = await response.json();
    if (!validPayload(data)) throw new Error(`${label} invalid V9.5.1 payload`);
    return { label, data };
  } finally {
    clearTimeout(timeout);
  }
}

function renderNews(payload, label) {
  state.newsItems = payload.all_items;
  indexNewsItems(payload.canonical_items);
  document.getElementById("newsMeta").textContent = `${payload.relevant_headline_count} relevant / ${payload.all_headline_count} headlines · ${payload.v9_4_baseline_headline_count} V9.4 baseline retained · ${String(payload.updated || "").slice(0, 10)} · ${label}`;
  drawNewsNewsV1Base();
  if (state.all.length) refreshProjects();
}

async function loadNews() {
  for (const [label, url] of NEWS_SOURCES) {
    try {
      const result = await fetchPayload(label, url);
      renderNews(result.data, result.label);
      return result.data;
    } catch (error) {
      console.error(`News V1 source unavailable: ${label}`, error);
    }
  }
  document.getElementById("stories").innerHTML = '<div class="news-empty">News V1 newspaper unavailable. REPD analytics below remain live.</div>';
  document.getElementById("newsMeta").textContent = "newspaper unavailable";
  return null;
}

export function loadNewsNewsV1Base() {
  if (!newsLoadPromise) {
    newsLoadPromise = loadNews().catch((error) => {
      newsLoadPromise = null;
      throw error;
    });
  }
  return newsLoadPromise;
}

export function bindNewspaperNewsV1Base(onNewsLoaded) {
  refreshProjects = onNewsLoaded;
  document.querySelectorAll("#newsTools button").forEach((button) => {
    button.onclick = () => {
      document.querySelectorAll("#newsTools button").forEach((candidate) => candidate.classList.remove("active"));
      button.classList.add("active");
      state.newsMode = button.dataset.news;
      drawNewsNewsV1Base();
    };
  });
  document.getElementById("newsSearch").oninput = (event) => {
    state.newsQuery = event.target.value.trim();
    drawNewsNewsV1Base();
  };
}

Newspaper News v1

A JavaScript module in the plugins folder of PipelineNews that draws regional news, solar and battery storage (BESS).

renderpipelinenews / archive/202608261547-pipelinenews/newsv1/scripts/plugins/newspaper-newsv1.js · lines 1–101 of 101 · version 2026-08-26 15:47 · pattern bindNewspaperNews (shared by 2 files)

What it does
It draws regional news, solar and battery storage (BESS). Defines 7 functions or classes, including queryMatches, regionalRows, drawRegional, drawNewsNewsV1, fetchCommitted. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage experimental (path word 'archive'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: solar, battery storage (BESS).
Inputs & outputs
In: JSON file regional_news.json; JSON file regional_manifest.json.
Downstream impact
Used directly by 1 file: App News v1 (pipelinenews). Reached from 3 other entry points, including PipelineNews — News v1 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv1/); PipelineNews — News v7 Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/newsv7/); PipelineNews — PipelineNews Page (pipelinenews, https://ventusltd.github.io/pipelinenews/archive/202608261547-pipelinenews/202608251651-PipelineNews/).
What it achieves
It queries matches (`queryMatches`), draws regional (`drawRegional`) and draws news news v1 (`drawNewsNewsV1`). Defines `queryMatches`, `regionalRows`, `drawRegional` and 4 more.
Why it matters
Imported by App News v1.
Application
pipelinenews · archive/202608261547-pipelinenews/newsv1/scripts/plugins · JavaScript module
Uses
State (import), Testcode — Pipeline (import), Newspaper News v1 Base (import)
Used by
imported by App News v1 (import)
Produces
drawNewsNewsV1, loadNewsNewsV1, bindNewspaperNewsV1
Defines here
queryMatches, regionalRows, drawRegional, drawNewsNewsV1, fetchCommitted, loadNewsNewsV1, bindNewspaperNewsV1
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
pipelinenews@45c944c8640a9d7ae65edb51d66032ba204f3f46 archive/202608261547-pipelinenews/newsv1/scripts/plugins/newspaper-newsv1.js:1-101 · blob af8a44d655f8180c20b7ea7974a4dca7760da044 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
import { state } from "../core/state.js";
import { escapeHtml, normaliseProject } from "../core/utils.js";
import { bindNewspaperNewsV1Base, drawNewsNewsV1Base, loadNewsNewsV1Base } from "./newspaper-newsv1-base.js";

const REGIONAL_MODES = new Set(["INTERNATIONAL", "US", "EUROPE"]);
let regionalItems = [];
let regionalManifest = null;

function queryMatches(item) {
  if (!state.newsQuery) return true;
  const haystack = normaliseProject([
    item.headline, item.source, item.technology, item.country, item.region,
  ].join(" "));
  return normaliseProject(state.newsQuery).split(" ").filter(Boolean)
    .every((token) => haystack.includes(token));
}

function regionalRows() {
  return regionalItems.filter((item) => {
    if (!queryMatches(item)) return false;
    if (state.newsMode === "US") return item.region === "US";
    if (state.newsMode === "EUROPE") return item.region === "EUROPE";
    return true;
  });
}

function drawRegional() {
  const stories = document.getElementById("stories");
  const rows = regionalRows();
  if (!rows.length) {
    stories.innerHTML = '<div class="news-empty">No build-verified regional solar or battery headlines match this filter.</div>';
    return;
  }
  stories.innerHTML = rows.map((item) => {
    const articleClass = item.technology.includes("BESS") ? "bess" : "solar";
    const region = item.region === "INTERNATIONAL_OTHER" ? "INTERNATIONAL" : item.region;
    return `<a class="story ${articleClass}" href="${escapeHtml(item.url)}" target="_blank" rel="noopener"><div class="kicker">${escapeHtml(item.technology)} · REGIONAL DISCOVERY · ${escapeHtml(item.published)}</div><h3>${escapeHtml(item.headline)}</h3><p><span class="project">${escapeHtml(region)} · ${escapeHtml(item.country)}</span>${item.source ? ` · ${escapeHtml(item.source)}` : ""}</p><span c  … [line shortened here: 600 characters; full line on GitHub]
  }).join("");
}

export function drawNewsNewsV1() {
  if (REGIONAL_MODES.has(state.newsMode)) {
    drawRegional();
    return;
  }
  if (state.newsMode === "UK") {
    state.newsMode = "RELEVANT";
    drawNewsNewsV1Base();
    state.newsMode = "UK";
    return;
  }
  drawNewsNewsV1Base();
}

async function fetchCommitted(path) {
  const url = new URL(path, import.meta.url);
  const response = await fetch(url, { cache: "default" });
  if (!response.ok) throw new Error(`${path} ${response.status}`);
  return response.json();
}

export async function loadNewsNewsV1() {
  await loadNewsNewsV1Base();
  try {
    const [regional, manifest] = await Promise.all([
      fetchCommitted("../../data/v9.7/regional_news.json"),
      fetchCommitted("../../data/v9.7/regional_manifest.json"),
    ]);
    if (regional.schema !== "globalgrid2050.regional-news.v9.7"
      || regional.release !== "9.7" || !Array.isArray(regional.articles)
      || !regional.articles.every((item) => item.project_signal_eligible === false)) {
      throw new Error("invalid committed regional artifact");
    }
    regionalItems = regional.articles;
    regionalManifest = manifest;
    const counts = regionalManifest.telemetry.by_region;
    const uk = state.newsItems.filter((item) => item.canonical_relevant === true).length;
    document.getElementById("newsMeta").textContent = `${uk} UK · ${regionalItems.length} international (${counts.US} US · ${counts.EUROPE} Europe · ${counts.INTERNATIONAL_OTHER} other) · ${state.newsItems.length} headlines · audited snapshot`;
  } catch (error) {
    regionalItems = [];
    document.getElementById("newsMeta").textContent = `${state.newsItems.length} inherited headlines · regional ledger unavailable`;
    console.error("V9.7 regional artifact unavailable", error);
  }
  drawNewsNewsV1();
}

export function bindNewspaperNewsV1(onNewsLoaded) {
  bindNewspaperNewsV1Base(onNewsLoaded);
  document.querySelectorAll("#newsTools button").forEach((button) => {
    button.onclick = () => {
      document.querySelectorAll("#newsTools button").forEach((candidate) => candidate.classList.remove("active"));
      button.classList.add("active");
      state.newsMode = button.dataset.news;
      drawNewsNewsV1();
    };
  });
  document.getElementById("newsSearch").oninput = (event) => {
    state.newsQuery = event.target.value.trim();
    drawNewsNewsV1();
  };
}