From 405e2361803ea287710a77cf22c317bedc5b2d07 Mon Sep 17 00:00:00 2001 From: Robyn Thiessen-Bock Date: Tue, 5 Oct 2021 22:12:18 -0400 Subject: [PATCH] Add table of contents - Add table of contents to inform, learn, and plan pages (ohi+/conduct) - Document front-matter properties in the README (including the new toc property) - Remove unused ".section" style - Rename "default-section" class to "section" - Add option to remove cards from any list page by setting `cards: false` in the front-matter Relates to: #106, #67, #30, #28 --- README.md | 7 +- assets/js/main.js | 10 +- assets/js/toc.js | 330 ++++++++++++++++++++++++ assets/scss/_common.scss | 14 +- assets/scss/partials/layout/layout.scss | 12 +- assets/scss/partials/toc.scss | 254 ++++++++++++++++++ assets/scss/style.scss | 1 + config/_default/markup.yaml | 6 +- content/ohi+/conduct/inform.md | 1 + content/ohi+/conduct/learn.md | 3 +- content/ohi+/conduct/plan.md | 1 + layouts/_default/list.html | 12 +- layouts/_default/single.html | 25 +- layouts/goals/list.html | 2 +- layouts/news/list.html | 2 +- layouts/ohi-assessment/list.html | 2 +- layouts/ohi-assessment/single.html | 2 +- layouts/ohi-conduct/list.html | 7 - layouts/partials/toc.html | 56 ++++ 19 files changed, 710 insertions(+), 37 deletions(-) create mode 100644 assets/js/toc.js create mode 100644 assets/scss/partials/toc.scss delete mode 100644 layouts/ohi-conduct/list.html create mode 100644 layouts/partials/toc.html 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