tecitheme 0.15.8 → 0.15.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,6 +64,10 @@
64
64
  <p class="{item.heading ? "" : "h-6"} mt-2 text-lg font-semibold tracking-tight text-gray-900">{item.heading ? item.heading : ""}</p>
65
65
 
66
66
  <p class="mt-2 text-sm">{item.text}</p>
67
+
68
+ {#if item.prompt && item.url}
69
+ <p class="text-sm {getColorStyles("text", color)} mt-2">{item.prompt} &rarr;</p>
70
+ {/if}
67
71
  </div>
68
72
  </a>
69
73
  </div>
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { onMount } from "svelte";
2
+ import { getContext, onMount } from "svelte";
3
3
  import { buildToC, makeIdString } from "../utils.js";
4
4
 
5
5
  export let data = {};
@@ -40,9 +40,11 @@
40
40
 
41
41
  onMount(async () => {
42
42
  if (data.toc) {
43
- tocBuilt = buildToC();
43
+ tocBuilt = buildToC(data.tocDepth);
44
44
  }
45
45
  });
46
+
47
+ let pageNavPresent = getContext("pageNavPresent");
46
48
  </script>
47
49
 
48
50
  <section {id}
@@ -70,7 +72,7 @@
70
72
  {#if (data.toc || data.rightRail)}
71
73
  <aside class="relative w-0 md:w-60">
72
74
  {#if data.toc}
73
- <div class="sticky top-8 flex shrink-0 flex-col">
75
+ <div class="sticky { pageNavPresent ? "top-20" : "top-8" } flex shrink-0 flex-col">
74
76
  <button
75
77
  on:click={() => {
76
78
  tocOpen = !tocOpen;
@@ -25,6 +25,7 @@
25
25
  import PartnersList from "../components/PartnersList.svelte";
26
26
  import DescriptionList from "../components/DescriptionList.svelte";
27
27
  import Carousel from "../components/Carousel.svelte";
28
+ import { setContext } from "svelte";
28
29
 
29
30
  let blocks = [
30
31
  { ref: "accordion", component: Accordion },
@@ -76,6 +77,8 @@
76
77
  }
77
78
 
78
79
  let pageNav = page_sections ? page_sections.filter(sect => sect.fieldGroup === "pageNav")[0] : undefined;
80
+
81
+ setContext("pageNavPresent", pageNav ? true : false);
79
82
  </script>
80
83
 
81
84
  <svelte:head>
package/dist/utils.d.ts CHANGED
@@ -40,7 +40,7 @@ export function getGridRowSizeStyle(num: any): "lg:grid-rows-1" | "lg:grid-rows-
40
40
  export function getGridSizeStyles(columns: any, rows: any): string;
41
41
  export function validateEmail(email: any): boolean;
42
42
  export function slugFromPath(path: any): void;
43
- export function buildToC(): boolean;
43
+ export function buildToC(tocDepth?: number): boolean;
44
44
  export function makeIdString(text: any): string;
45
45
  /**
46
46
  * Converts a simplified image source string in to the proper TECi Image src. If imageSrc is an absolute url (starts with http) it is returned unchanged
package/dist/utils.js CHANGED
@@ -364,7 +364,7 @@ export function slugFromPath(path) {
364
364
  path.match(/([\w-]+)\.(svelte\.md|md|svx)/i)?.[1] ?? null;
365
365
  }
366
366
 
367
- export function buildToC() {
367
+ export function buildToC(tocDepth = 6) {
368
368
  // Based on https://projectcodeed.blogspot.com/2020/04/an-automatic-table-of-contents.html
369
369
 
370
370
  // Get ToC div
@@ -393,32 +393,103 @@ export function buildToC() {
393
393
  let tocList = document.createElement("ul");
394
394
 
395
395
  // Find the primary content section
396
- let content = document.getElementById("content");
396
+ let content = document.getElementById("content").getHTML();
397
397
 
398
- // Get the h2 tags - ToC entries
399
- let headers = content.getElementsByTagName("h2");
398
+ let headings = [];
400
399
 
401
- if (headers.length == 0) {
402
- console.log("There are not any H2 elements in the document.");
403
- } else {
404
- // For each h2
405
- for (let i = 0; i < headers.length; i++) {
406
- // Get Heading ID
407
- let name = headers[i].id;
400
+ // Set up depth search
401
+ let headingLevels = [];
402
+ for (let i=0; i<=tocDepth; i++) {
403
+ headingLevels.push(i.toString())
404
+ }
405
+
406
+ // Look for all levels of headings
407
+ for (const level of headingLevels)
408
+ {
409
+ const regexp = new RegExp(String.raw`<h${level}([^>]*)>([^<>]*)<\/h${level}>`, "gm")
410
+ let h = Array.from(content.matchAll(regexp));
411
+
412
+ for (const tag of h)
413
+ {
414
+ let src = tag[0];
415
+ let text = tag[2];
416
+ let matches = src.match(/id="([^ ]*)"/);
417
+ if (matches) {
418
+ let tagRef = "#" + matches[1];
419
+
420
+ let data = {
421
+ src,
422
+ text,
423
+ index: tag["index"],
424
+ tagRef,
425
+ level: parseInt(level)
426
+ };
427
+
428
+ headings.push(data);
429
+ }
430
+ }
431
+ }
432
+
433
+ // Sort headings by index
434
+ headings = headings.sort((tag1, tag2) => {
435
+ if (tag1.index < tag2.index)
436
+ {
437
+ return -1;
438
+ }
439
+ else if (tag1.index > tag2.index)
440
+ {
441
+ return 1;
442
+ }
443
+ else
444
+ {
445
+ return 0;
446
+ }
447
+ });
408
448
 
449
+
450
+ // Build heading links
451
+ if (headings.length == 0) {
452
+ console.log("There are not any heading elements in the document.");
453
+ } else {
454
+ // For each heading
455
+ for (const heading of headings) {
409
456
  // list item for the entry
410
457
  let tocListItem = document.createElement("li");
458
+
459
+ // Figure out how much margin to give the heading
460
+ let margin = "";
461
+ switch (heading.level) {
462
+ case 2:
463
+ margin = "ml-0";
464
+ break;
465
+ case 3:
466
+ margin = "ml-2";
467
+ break;
468
+ case 4:
469
+ margin = "ml-3";
470
+ break;
471
+ case 5:
472
+ margin = "ml-4";
473
+ break;
474
+ case 6:
475
+ margin = "ml-6";
476
+ break;
477
+ default:
478
+ break;
479
+ }
480
+
411
481
  tocListItem.classList.add(
412
482
  "text-teci-blue-light",
413
483
  "hover:text-teci-blue-dark",
414
484
  "text-sm",
415
- "truncate"
485
+ "truncate",
486
+ margin
416
487
  );
417
488
 
418
489
  // link for the h2
419
490
  let tocEntry = document.createElement("a");
420
- tocEntry.setAttribute("href", "#" + name);
421
- tocEntry.innerText = headers[i].innerText;
491
+ tocEntry.setAttribute("href", heading.tagRef);
492
+ tocEntry.innerText = heading.text;
422
493
 
423
494
  // add link to list item list
424
495
  tocListItem.appendChild(tocEntry);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tecitheme",
3
- "version": "0.15.8",
3
+ "version": "0.15.10",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev",