Generated documentation for `std` with static HTML files

The documentation generated with e.g. zig build-lib -femit-docs works by parsing Zig sources in the browser and generating docs pages on-the-fly, as an SPA. This works alright if you’re just clicking around and searching in the browser, but it means that search engines can’t find documentation about the Zig standard library, and that LLMs are very poorly equipped to assist with learning or writing Zig.

Since I personally appreciate being able to delegate things like scouring the standard library to find the API relevant to something I’m working on to an LLM, I wrote a script based on the SPA client code which, instead of generating pages on the fly, renders HTML pages similar to the documentation that can be viewed dynamically using the generated docs SPA. It’s a little janky and definitely less usable by humans than the official generated documentation, but so far I’m having success getting an LLM to find and provide accurate information about the Zig standard library by providing a link to these static HTML docs.

The static docs are here. If you provide this link to an LLM that is able to view and navigate webpages, it should be able to use this site to source accurate information about the standard library for Zig 0.14.1: Zig Documentation

The hosted HTML docs plus the script I wrote to generate them live here. Contributions to help clean up some of the jank would be very welcome: GitHub - pineapplemachine/ZigDocsHtml: Zig docs rendered as static HTML.

A “GPT” with a default prompt pointing it to the aforementioned static HTML docs is here, which will hopefully provide reliably accurate information in response to questions about Zig 0.14.1. You can expect the best results by using a so-called “Thinking” model: ChatGPT - Code assistant for Zig v0.14.1

2 Likes

I dont use AI to write code but this tool is really helpful to better understand some of the more obscure errors I get.
Will a Zig 0.15.1 be available?

2 Likes

Yep, I’ll plan on generating docs for 0.15.1 as well as soon as I have a chance. If you want them right away, though, you should also feel free to generate them yourself using the script in the repo (assuming it’s compatible, it’s possible it may need updating for 0.15.1) and make a PR to have them added to the gh-pages site. To do this you would:

1 Like

I would like to say that these instructions worked for me with 0.15.1 docs, with some changes:

  • First, do not clone that repo, it has many html files, too many, just copy the javascript file and place all them all like he says.
  • Second, the wasm module can’t access the decodeString call at line 628, so I just commented out the entire body of that logging function, like so:
   const imports = {
        js: {
            log: (level, ptr, len) => {
                // const msg = aadecodeString(ptr, len, wasmExports);
                // switch(level) {
                //     case LOG_err:
                //         console.error(msg);
                //         break;
                //     case LOG_warn:
                //         console.warn(msg);
                //         break;
                //     case LOG_info:
                //         console.info(msg);
                //         break;
                //     case LOG_debug:
                //         console.debug(msg);
                //         break;
                // }
            },
        },
    };

That got me a bunch of htmls that I sent into python’s markdownify. Tyvm for figuring this out.

1 Like