slate icon indicating copy to clipboard operation
slate copied to clipboard

Add option to disable dynamic ToC titles

Open wlanni opened this issue 7 years ago • 1 comments

Operating system: Any Last upstream commit (run git log --author="Robert Lord" | head -n 1): commit cf29f6786c288b6111239b8e8b211f8ae2fbc4c3 Browser version(s): Any Ruby version (run ruby -v): ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32]


We started seeing either an 'undefined' or a blank space in our page titles, as some of the headers have nested html, and the Slate code is apparently having difficulty reading the text out of the embedded code. image

We figured we would hard code the page title, and remove the data-title attributes. This results in an 'undefined' in the title: image

We then reset our title in the html.md.erb to the full static title we wish to see, and the result is then an 'undefined' followed by a hyphen followed by that full title.

We got around this finally by setting the data-title in the layout.erb to the static text we wanted, but this seems like a lot of overhead for a simple static title. Much simpler to have just removed the code out of the title tag in the layout.erb, or enabled a switch somewhere to use a static title defined in the html.md.erb.

I dug into the javascript to track it down. In javascripts/app/_toc.js line 88 the document.title is set to the $best object's title attribute, with a hardcoded hyphen, then the original title.

// TODO remove classnames
document.title = $best.data("title") + " – " + originalTitle;

There's no null/empty functionality here, which explains the issue. Normally, I'd expect to see a case for an undefined property and handle it, and that's missing here. Something to the effect of:

document.title = ( typeof $best.data("title") !== 'undefined' || $best.data("title") !== '' ) ? $best.data("title") + "-" + originalTitle : originalTitle;

Something would still need to be done with the

tag in the layout.erb, though, as I still see an undefined even with the above code. I am probably missing something later, and I don't have the time to track this down at the moment, unfortunately-- my work around works for us and we're moving on. <p>Basically, there's no way to set a static title without going through if we remove the data-title attribute in the layout.erb, and it would be great if there was, as well as null/empty error handling.</p>

wlanni avatar Jun 06 '18 22:06 wlanni

Actually going to reopen this — we've fixed the undefined problem (hopefully) but still would be nice to have some predictable way to disable dynamic titling.

lord avatar Jul 05 '18 23:07 lord