ziglang / www.ziglang.org

https://ziglang.org/
MIT License
292 stars 176 forks source link

Documentation change title based on current uri hash? #218

Closed SimonLSchlee closed 1 month ago

SimonLSchlee commented 2 years ago

The documentation always uses Documentation - The Zig Programming Language as the title.

Personally I found that unfortunate, because I regularly have a lot of open tabs and all of them having the same name doesn't help me in finding the right one to switch to.

Looking at the source code of the documentation it seems to avoid any usage of javascript. Is that a deliberate choice, or are quality of life enhancements via javascript wanted?

Currently I am using a simple userscript (via tampermonkey extension) that rewrites the title:

// ==UserScript==
// @name         zig distinct documentation titles
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  rewrite documentation title
// @author       You
// @match        https://ziglang.org/documentation/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ziglang.org
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let update_title = function() {
        let h = window.location.hash.slice(1);
        if(h !== "") {
            let new_title = h.replaceAll("-", " ").replace("toc ", "");
            document.title = new_title + " - Zig";
        }
    };

    update_title();
    addEventListener('hashchange', update_title);
})();

This issue is mostly a suggestion to add something similar to the generated html file. If something like this is not wanted I will continue to use the userscript.

I just thought I should mention it, in case others would prefer a changing title too.

kristoff-it commented 2 years ago

Is that a deliberate choice, or are quality of life enhancements via javascript wanted?

It definitely used to be the case, that said, I don't see anything wrong with something that gracefully degrades. I'll keep this in mind as we plan changes to the language reference.

Also keeping this issue open as a reminder. Thanks for your comment.