<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Sampon projektit]]></title><description><![CDATA[Sampon projektit]]></description><link>https://sampomannila.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 11:36:38 GMT</lastBuildDate><atom:link href="https://sampomannila.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[One PHP file on a static site: fetching reference rates without making the page fragile]]></title><description><![CDATA[Laskuri.org is a static site of Finnish calculators. Everything runs in the browser, with one exception: the loan calculator pre-fills the current Euribor…]]></description><link>https://sampomannila.hashnode.dev/one-php-file-on-a-static-site-fetching-reference-rates-without-making-the-page-fragile</link><guid isPermaLink="true">https://sampomannila.hashnode.dev/one-php-file-on-a-static-site-fetching-reference-rates-without-making-the-page-fragile</guid><dc:creator><![CDATA[Sampo Mannila]]></dc:creator><pubDate>Thu, 12 Nov 2026 13:59:48 GMT</pubDate><content:encoded><![CDATA[<p><a href="https://laskuri.org/">Laskuri.org</a> is a static site of Finnish calculators. Everything runs in the browser, with one exception: the <a href="https://laskuri.org/lainalaskuri/">loan calculator</a> pre-fills the current Euribor reference rate, and that number has to come from somewhere.</p>
<p>It comes from one PHP file of about 120 lines. This post is about what is in it, because most of those lines are not about fetching.</p>
<p>(The calculation itself is a separate story. I wrote about the money math on DEV: <a href="https://dev.to/sampomannila/money-math-in-plain-javascript-lessons-from-building-a-loan-calculator-3d6b">Money math in plain JavaScript</a>.)</p>
<h2>Why a server at all</h2>
<p>The Bank of Finland publishes the daily rates as an XML report. We did not want every visitor's browser to request and parse that report, and we wanted one place to decide whether today's data is good enough to show. So the endpoint fetches the report, checks it, caches a small JSON file and serves that.</p>
<h2>Picking the right number</h2>
<p>The report lists more than one three-month rate: one on an ACT/360 day count and one on ACT/365. They differ in the second decimal, which is enough to be wrong. The parser matches the exact label and stops if it ever sees the same tenor twice:</p>
<pre><code class="language-php">if (!preg_match('/^(3|6|12) kk \(tod\.pv\/360\)$/u', trim((string)$rate['name']), $m)) continue;
// ...
if (isset($data['rates'][$m[1]])) throw new RuntimeException('Ambiguous rate');
</code></pre>
<p>It also takes the observation date from the data, not the time the report was generated. Users see that date next to the rate, so it has to mean what it says.</p>
<h2>Treat the upstream as untrusted</h2>
<p>The source is a central bank, and the code still assumes nothing:</p>
<ul>
<li>The response is capped at 128 KB, redirects are not followed and TLS is verified.</li>
<li>XML with a <code>DOCTYPE</code> or <code>ENTITY</code> declaration is rejected before parsing, and the parser runs with network access disabled.</li>
<li>A parsed result is valid only if all three tenors are present, each date is a real calendar date, no date is in the future or more than seven days old, and each value is between −10 and 50 percent.</li>
</ul>
<p>The same validation runs again when the cache file is read, and a JavaScript version of it runs in the browser before the number reaches the form. Three checks for one number sounds excessive until the day the report format changes.</p>
<h2>A cache that remembers failure</h2>
<p>The cached file is good for six hours. After that the next request refreshes it, and three details keep that from going wrong.</p>
<p><strong>Only one request refreshes.</strong> A non-blocking file lock decides who does the work. Everyone else gets the previous data immediately, marked with <code>refresh_failed</code>, so the page can say the quote is not the latest.</p>
<p><strong>A failed attempt is not repeated at once.</strong> The lock file stores the time of the last attempt. If the upstream was down a minute ago, the endpoint does not ask again for five minutes.</p>
<p><strong>The date never goes backwards.</strong> If the upstream briefly serves an older report, the new data is discarded:</p>
<pre><code class="language-php">foreach (['3','6','12'] as $tenor) {
    if ($cached &amp;&amp; $fresh['rates'][$tenor]['date'] &lt; $cached['rates'][$tenor]['date'])
        throw new RuntimeException('Older snapshot');
}
</code></pre>
<p>The new file is written to a temporary name and renamed into place, so a reader never sees half a file.</p>
<h2>The page works without it</h2>
<p>The calculator does not wait for the endpoint. A snapshot of the rates is embedded in the HTML when the site is built, so the form has a dated value on first paint. The request to the endpoint has a timeout. If it fails, the page keeps the snapshot and says so. If there is no usable snapshot either, the user gets an example rate and a note asking them to type their own. The rate field is editable in every case, because a loan offer has its own margin anyway.</p>
<h2>Tests</h2>
<p>The PHP side is tested with a synthetic report that keeps the real structure, including both day-count variants, and covers the rollback protection and lock contention. The browser side is tested in Node against the same messages the user sees.</p>
<h2>What I would keep</h2>
<ul>
<li>Validate the data where it enters, where it is stored and where it is shown.</li>
<li>Let one request refresh and give everyone else stale data with a flag.</li>
<li>Remember failures, not only successes.</li>
<li>Ship a fallback value with the page, and make the input editable.</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Running sixteen static sites from one GitHub repository with AI agents]]></title><description><![CDATA[We publish a network of Finnish-language guide and comparison sites. Until this autumn most of them ran on WordPress, each with its own plugins, logins and…]]></description><link>https://sampomannila.hashnode.dev/running-sixteen-static-sites-from-one-github-repository-with-ai-agents</link><guid isPermaLink="true">https://sampomannila.hashnode.dev/running-sixteen-static-sites-from-one-github-repository-with-ai-agents</guid><dc:creator><![CDATA[Sampo Mannila]]></dc:creator><pubDate>Wed, 11 Nov 2026 11:50:59 GMT</pubDate><content:encoded><![CDATA[<p>We publish a network of Finnish-language guide and comparison sites. Until this autumn most of them ran on WordPress, each with its own plugins, logins and update schedule. Since September 2026 we have moved them one by one into a single GitHub repository, and AI coding agents now do most of the maintenance. This is a short account of how that is set up and what we learned.</p>
<h2>One repository, one route to production</h2>
<p>Every site lives in its own folder in the same repository. Content is stored as JSON files, a small Python builder turns it into plain HTML, and a second script checks the result before anything is published. There is no database and no CMS on the server.</p>
<p>Publishing goes through one shared GitHub Actions workflow. To publish, a small request file is changed to name the site and the exact source commit. When that change reaches the main branch, the workflow builds the site, uploads the files, switches the live folder to the new version and keeps the previous one for rollback. It then reads the changed pages back from the live site and writes a summary of what it checked.</p>
<p>The important part is that there is only one way to production. Nobody uploads files by hand, and the workflow run is the record of what was published and when.</p>
<h2>Instructions are part of the repository</h2>
<p>Two different AI agents work in the repository. Both read the same instruction file at the root, a short status page, and a handoff note for each site. The instruction file says how much checking a change needs, when dates may be updated, how partner links and offers are handled, and when to stop and ask.</p>
<p>These files matter more than any prompt. An agent starts every task with no memory of the previous one, so whatever is not written down in the repository does not exist for it. When something goes wrong, the fix is usually a change to the instructions as well as to the code.</p>
<h2>What the agents do</h2>
<p>A typical task is a sentence from me: update an offer from a partner across the sites that list it, add an article, fix a slow page. The agent finds the source, makes the change on a branch, runs the build and checks, opens a pull request, merges it when the checks pass and follows the deployment until the page is live. I get back a short report and a link.</p>
<p>Larger jobs follow the same route. Moving a site from WordPress meant reading the old content and redirects, rebuilding the pages as static files, and verifying every old address before the switch.</p>
<p>In a little over two months the repository has passed four hundred merged pull requests.</p>
<h2>Guardrails that turned out to matter</h2>
<ul>
<li><strong>Partner links are data, not text.</strong> Each partner link is defined once, and the build fails if a page links to a partner that has been removed.</li>
<li><strong>Dates are not build times.</strong> A page's published and updated dates come from its own record. A technical redeploy does not make old content look new.</li>
<li><strong>Access is temporary.</strong> Each deployment creates its own short-lived access to the server and removes it afterwards, also when the run fails.</li>
<li><strong>Failures stop the run.</strong> If the live site differs from what the workflow expects, it stops instead of overwriting.</li>
</ul>
<h2>What went wrong</h2>
<p>Not everything worked the first time. One deployment stopped because uploading files one at a time hit a fixed time limit once a site had grown past three hundred files. Nothing was published, which is what should happen, but it showed that the limit had been invisible until then. The fix was to publish fewer files, and the note about the remaining headroom went into the site's handoff file.</p>
<p>Agents also tend to over-check. Early on, a one-line text change could trigger a full round of browser tests and backups. We rewrote the instructions so that the amount of verification follows the size of the change.</p>
<h2>What I would tell someone starting</h2>
<p>Keep the sites boring: static files, content in version control, one build script per site. Put the rules where the agent will read them. Make one route to production and let the workflow keep the record. The agents are useful because the repository is strict, not the other way round.</p>
]]></content:encoded></item></channel></rss>