Kanka Automatic Table of Contents

Automatically adds a table of contents to Kanka entity pages under the Pins sidebar.

Ez a szkript összes változata. Csak azon verziók mutatása, ahol a kód változott.

  • v12 2024.09.29.

    This is a big update. Remember to update your addTopLink setting if needed. See script description for how to use the new settings that have been added.

    Functionality

    • Character sheets tend to use a lot of headers that aren’t useful for navigation, so their contents are now excluded from the ToC.
    • Headings for child entity listings (e.g. Organization members, Tag children, etc.) will now be ignored.
    • Empty heading tags will now be ignored (Summernote sometimes leaves those behind even though they aren’t visible in Visual mode).
    • For those using transclusion and my Context-Aware Classes plugin, "no-transclusion" contents will be ignored unless viewed from their source entity.
    • New setting: classExclusions to specify other classes that the script should ignore (including all descendants) when building the ToC.
    • If you reorder an entity’s posts so that the entry is no longer the first block, the ToC will now show it in the proper position instead of assuming it’s first.

    Maintenance and bug fixes

    • Removed reliance on the jQuery library for future-proofing, as Kanka aims to remove it in the future.
    • Fixed a rare bug where the script would fail if an entity had no Entry block (which can occur if you save an empty entry in Code View specifically).
    • Fixed a silent bug that occurred when clicking the Entry link (the script would try to expand the box even though it can’t be collapsed).
    • The auto-expand feature for collapsed posts now also handles Timeline eras properly.
    • Timeline eras are now recognized as 0th-level items and events as 1st-level items, rather than them all defaulting to 3rd-level. (As a result, I recommend avoiding H1s in Timeline events.)
    • Improved handling of special posts (showing attributes, relations, etc.). They use non-standard markup and weren’t being recognized as posts by the script, and also can’t be collapsed.

    Appearance

    • The ToC is now sticky by default and will follow when you scroll up and down the page. This can be turned off.
    • CSS clean up and minor tweaks: indentation between levels is now smaller; list markers have been added for levels 1-6; word break is now more aggressive, as it was meant to be originally. These changes should allow more text per line while keeping the separation between items clear.
    • In Calendars, the ToC block is now properly separated from the end of the left-hand sidebar.
    • In the rare cases where an entity has no entry, post or timeline era, an empty ToC block will no longer be added to the sidebar.

    ... And I was just going to tweak the CSS a little 🥲

  • v11 2024.09.29.
  • v11 2024.09.29.
  • v11 2023.11.04.

    Kanka 2.0 compatibility update:

    • Updated targeting rules to properly activate the script and locate headings.
    • Added an ID to the entry block, which no longer has a heading, to keep it in the ToC manually.
    • Updated the ToC box expand/collapse function and the auto-expand function for links pointing to headings inside collapsed posts.
    • Updated the ToC box’s markup and styling to match other entity sidebar boxes.
  • v10 2023.06.28.
  • v10 2023.04.25.

    Quick update to make the ToC text visible again following changes in Kanka’s CSS.

    Remember to set your addTopLink preference as desired after updating.

  • v9 2022.08.15.
    • Fixed the opening of closed posts when clicking a ToC link (they would toggle open/closed indiscriminately on every click).
    • Greatly improved handling of special characters in heading titles for better legibility of URLs and correct scrolling behaviour.
    • Ensured that the ToC does not appear when printing entities with parameters in the URL.

    Remember to set your addTopLink preference as desired after updating.

  • v8 2022.03.31.
  • v8 2022.01.10.
    • Headings that already have an ID no longer get a new one assigned by this script. This allows compatibility with Kanka 1.20 tables of contents, among other things.
    • IDs assigned by this script now include a unique number to differentiate headings with identical titles. You may still encounter issues if you use a Kanka 1.20 ToC with identical titles across different heading levels, as those are not differentiated by the library Kanka uses.
    • You can now set custom "back to top" link text instead of only true/false. If you currently have addTopLink set to true, you will need to change it to a text string instead (see description for instructions).
  • v7.2 2021.12.05.
    • Updated the markup and CSS of the TOC box to match the new sidebar design. Also adapts seamlessly to my Sidebar Box Backgrounds plugin for non-Default themes.
  • v7.1 2021.11.22.

    This is a temporary fix for the last Kanka update that changed how the sidebars are structured. More work needs to be done for styling when I have the time, but this at least restores functionality.

  • v7 2021.11.09.
    • On Timeline elements that refer to private entities, the new screenreader description for the lock icon was being picked up by the table of contents. It is now properly yeeted.
  • v6 2021.11.08.
    • Links back to the ToC have had their text changed from TOP to TOC to clarify, and a tooltip has been added for accessibility.
    • When clicking a heading that belongs to a post that is currently collapsed, the post is automatically expanded first so the page can scroll to the correct location (thanks to Ho’nehe for pointing that out).
  • v5 2021.11.06.
  • v5 2021.11.06.
    • Added the addTopLink setting to toggle the addition of "^top" links to headings.
    • Link color now matches whichever color is set for standard links by the theme.
  • v4 2021.08.23.
    • Print pages are excluded.
    • Inline tags in headings are now checked to exclude the dates in Timeline elements from the TOC. You can have them display by commenting out #tableofcontent .text-muted { display: none; } in your copy of the script, or setting it to inline in your campaign CSS.
    • Line breaks at the end of headings (often left behind undesirably by Summernote) are now removed to avoid the TOP link falling on a new line. This does not affect eventual line breaks separating the contents of the heading.
  • v2 2021.07.16.

    Added handling for Calendars, which use a single sidebar and where every date in the grid would get picked up by the TOC.

    Adding a filter to avoid modals that are hidden among some entity content, such as the "Year Switcher" in Calendars.

    Calendars are rude.

  • v1 2021.07.15.
  • v1 2021.07.15.