<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card>
<p><b>4: Shoehorning it into my setup</b></p>
<p>
After I converted the start page and the about page it was time for the main deal:
</p>
<p>
Making the script that builds my blog output everything for a wap-portal.
</p>
<p>---<br /></p>
<p>
One of these days I'll write a post about how my blog works, but here's the short form:
</p>
<p>
</p><p>The posts are written im markdown on my desktop.</p><p> (1)</p>
<p>
</p><p>A CI/CD script on my Gitea server converts the markdown into html and inserts it into two templates, one for the </p><p><a href="https://dekkia.zip/blog/post/254376b6-04e5-4f8c-bc6c-afae2a976afd.html">retro site</a></p>
<p> and one for the modern site.</p><p>
</p><p>
The script converts all images to webp and avif (modern site) and to gif (retro site)
</p>
<p>
</p><p>
Another script is called that pushes everything to the prod server
</p>
<p>
</p><p>
The whole thing is written in Javascript and runs in nodejs (I will not apologize for that). There's some more to it, but for the sake of this post that's enough information. 
</p>
<p> (1)</p>
<p> Some Posts are actually mastodon threads, which automatically get assembled into a single page. Those are plainly not supported by the wap version.</p><p>---<br /></p>
<p>
Converting images to wbmp is easy, just call a script during the image conversion already in place that does that. I won't have jpeg files available for phones that support them, but I figured that's not a big deal. 
</p>
<p>
The code that gets added to the remaining image conversion code looks a bit like that. If you looked at the script I linked earlier It'll look familiar to you.
</p>
<p>
 // var im = require('imagemagick');
im.convert([imgSrc, '-resize', '100', '-monochrome', '+dither', imgDest],
    function (err, stdout) {
        if (err) {
            console.warn(err);
        }
});
 //
</p>
<p>---<br /></p>
<p>
The More complicated part to deal with is the wml for multiple reasons. One issue I'm having is that WML pages that are to big will load on an emulator, but not on a real device. So It has to be split into multiple pages. 
</p>
<p>Another issue is that standard html has a bunch of tags wml doesn't, like </p><p>
 // li //
</p>
<p>---<br /></p>
<p>, </p><p>
 // code //
</p>
<p>---<br /></p>
<p>or </p><p>
 // hr //
</p>
<p>---<br /></p>
<p>. Some wap implementations treat them like </p><p>
 // p //
</p>
<p>---<br /></p>
<p> tags, some actually display them correctly and some throw an error.
Because it was important to me for the site to look the same on every device, I added some code to replace them with </p><p>
 // p //
</p>
<p>---<br /></p>
<p> tags and some additional text. </p><p>
 // &lt;code&gt;example&lt;/code&gt; //
</p>
<p>---<br /></p>
<p> for example turns into </p><p>
 // &lt;p&gt;//example//&lt;/p&gt; //
</p>
<p>---<br /></p>
<p>
After converting the images and the DOM-elements my code assembles everything together with a pre-made template, the same as all other versions of the website. The template for the wap-version also has links to go forward and back between the pages of each post. Right now there are no pages for the index on any version of the site. This will be something to fix in the future.
</p>
<p>
After a lot of trial and error I ended up with something that works. But the disclaimer on the start page about the wapsite being experimental will probably stay for good.
</p>
<p align="center">
<a href="3ee06abc-2737-4904-8204-fc0a70f7dcf3-2.wml">previous page</a>
<a href="3ee06abc-2737-4904-8204-fc0a70f7dcf3-4.wml">next page</a>
<a href="/blog">post index</a>
</p>
</card>
</wml>
