diff --git a/README.md b/README.md index de1d31e33..88262fbae 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,10 @@ add-ons called "shortcodes". Content markdown files also use metadata at the sta Front-matter is located at the top of each markdown file, between two `---` separators, in `yaml` format. The properties common to all pages are: -- title -- name -- bg_image +- `title`: The full title of the page to show in the page header. +- `name`: The short name of the page to use in menus, etc. May be the same as title. +- `bg_image`: The image to use in the page's header +- `toc`: Set to `true` to add a table of contents to the page. The page will use a 2-col layout instead of a 3-col layout. This only works for single pages (pages that aren't named `index.md` or `_index.md`) ## Shortcodes diff --git a/assets/js/main.js b/assets/js/main.js index dc8a5455c..bcc134e2d 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -8,8 +8,10 @@ import params from '@params' // Functions for the main navigation menu. import nav from './partials/nav/nav.js' - +// Data visualizations import dataviz from './data-viz/dataviz.js' +// Table of contents +import toc from './toc.js'; // What to do when the DOM has loaded async function callback() { @@ -17,7 +19,11 @@ async function callback() { // Enable the navigation functions nav.init(); - dataviz.init(); + // Render any data visualizations that are on the page + dataviz.init(); + + // Set up the table of contents functions, if there is a TOC. + toc.init(); }; diff --git a/assets/js/toc.js b/assets/js/toc.js new file mode 100644 index 000000000..1f23b2a61 --- /dev/null +++ b/assets/js/toc.js @@ -0,0 +1,330 @@ +// parameters imported from the baseof.html template which builds the JS +import * as params from '@params' + +/** + * CSS Selector strings to select HTML elements that make up the TOC + * @typedef {Object} TOCSelectors + * @property {string} mainContainer The entire block (including TOC & content) + * @property {string} toc The table of contents + * @property {string} content The contents that the TOC refers to (i.e. the text with ids) + * @property {string} tocContainer The element that doesn't get affixed but that contains + * the TOC + * @property {string} list The