Closed bensulli closed 3 years ago
@Flavelius correct.
I would like to +1 this as well, since our organization is using those for our documentation.
While we understand the terminology, our specific use case would be better suited with changed terminology.
If you put the following code in the
<head>
element (Settings -> Customization -> Custom HTML Head Content), you can replace all occurrences of "books", "shelves" etc. I'm definitely not proud of this code, but hey, it works 😂 The performance is not even that bad on my machine. Because we're hacking this into the frontend using the custom HTML feature, it won't break your BookStack instance when you update. Of course this solution isn't ideal, but in my case it's good enough (for now).The dirty fix:
<script> var replace = { "shelves": "categories", "shelf": "category", "books": "topics", "book": "topic", "chapters": "sections", "chapter": "section" } var regex = new RegExp(Object.keys(replace).join("|"),"gi"); function walkText(node) { if (node.className == "tri-layout-middle") { return; } if (node.nodeType == 3) { node.data = node.data.replace(regex, function(matched) { const replaced = replace[matched.toLowerCase()]; if (matched.charAt(0) === matched.charAt(0).toUpperCase()) { return capitalizeFirstLetter(replaced); } else { return replaced; } }); } if (node.nodeType == 1 && node.nodeName != "SCRIPT") { for (var i = 0; i < node.childNodes.length; i++) { walkText(node.childNodes[i]); } } } function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } window.onload = function() { walkText(document.body); }; </script>
i think it's the simplest solution for now. is there any update that i missed?
To apply same replacements to browser tab title add this
let title = document.title.split("|").map(chunk => chunk.trim());
if(replace[title[0].toLowerCase()]){
document.title = capitalizeFirstLetter(replace[title[0].toLowerCase()]) + " | " + title[1];
}
right before line
var regex = new RegExp(Object.keys(replace).join("|"),"gi");
Also I recommend change window.onload = function(){}
to window.addEventListener('DOMContentLoaded', function(){})
because first waits for images and static resources loading and old titles blink on screen, but DOMContentLoaded
called when html DOM is ready and it's much sooner
It would be valuable to have a simple UI-accessible way to rename the types of objects in the wiki hierarchy. I wanted to change from Books -> Chapters -> Pages, to Products -> Features -> Pages. I had to change these in the localization files so it'd be nice to have a simpler way to mass-change these names.