Skip to content

Commit 18dd46e

Browse files
committed
table of contents
1 parent 3958beb commit 18dd46e

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Public Scripts for envoy.com

segementLaoder.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
!(function () {
2+
var analytics = (window.analytics = window.analytics || []);
3+
if (!analytics.initialize)
4+
if (analytics.invoked)
5+
window.console &&
6+
console.error &&
7+
console.error("Segment snippet included twice.");
8+
else {
9+
analytics.invoked = !0;
10+
analytics.methods = [
11+
"trackSubmit",
12+
"trackClick",
13+
"trackLink",
14+
"trackForm",
15+
"pageview",
16+
"identify",
17+
"reset",
18+
"group",
19+
"track",
20+
"ready",
21+
"alias",
22+
"debug",
23+
"page",
24+
"once",
25+
"off",
26+
"on",
27+
];
28+
analytics.factory = function (t) {
29+
return function () {
30+
var e = Array.prototype.slice.call(arguments);
31+
e.unshift(t);
32+
analytics.push(e);
33+
return analytics;
34+
};
35+
};
36+
for (var t = 0; t < analytics.methods.length; t++) {
37+
var e = analytics.methods[t];
38+
analytics[e] = analytics.factory(e);
39+
}
40+
analytics.load = function (t, e) {
41+
var n = document.createElement("script");
42+
n.type = "text/javascript";
43+
n.async = !0;
44+
n.src =
45+
"https://sgmnt.envoy.com/analytics.js/v1/" + t + "/analytics.min.js";
46+
var a = document.getElementsByTagName("script")[0];
47+
a.parentNode.insertBefore(n, a);
48+
analytics._loadOptions = e;
49+
};
50+
analytics.SNIPPET_VERSION = "4.1.0";
51+
52+
analytics.load("jmhzjAC1O7mvTJ4taVydJa9YKstvuNME");
53+
54+
// var page_path = "pages/index.html";
55+
// Turn /pages/security.html => security
56+
// var page_name = page_path.replace(/^pages\// ,'').replace(/\.html$/, '').replace(/\.md$/, '');
57+
58+
// Get the Page Title
59+
const pageNameFull = document.title.split("-")[0];
60+
// Trim the page title so you only return the first string before a dash
61+
const pageNameTrimmed = pageNameFull.trim();
62+
63+
analytics.page(
64+
"[envoy.com] " + pageNameTrimmed,
65+
(properties = { project: "envoy.com" })
66+
);
67+
}
68+
})();
69+
70+
window.metrics = {
71+
trackEvent: function (event, properties, options) {
72+
if (properties) {
73+
properties.project = "envoy.com";
74+
} else {
75+
properties = { project: "envoy.com" };
76+
}
77+
analytics.track("[envoy.com] " + event, properties, options);
78+
},
79+
};

tableOfContents.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
document.addEventListener("DOMContentLoaded", function () {
2+
const headers = document.querySelectorAll(".text-rich-text h2");
3+
const tocContainer = document.querySelector(".dynamic-page-toc-container");
4+
tocContainer.innerHTML = "";
5+
const ids = {};
6+
7+
headers.forEach(function (header, index) {
8+
let baseId = header.textContent
9+
.trim()
10+
.toLowerCase()
11+
.replace(/[^a-z0-9]+/g, "-")
12+
.replace(/^-|-$/g, "");
13+
let id = baseId;
14+
let count = 1;
15+
16+
// Ensure the ID is unique
17+
while (ids[id]) {
18+
id = `${baseId}${count}`;
19+
count++;
20+
}
21+
ids[id] = true;
22+
23+
// Assign the unique ID to the header
24+
header.id = id;
25+
26+
// Create the link for the table of contents
27+
const link = document.createElement("a");
28+
link.href = `#${id}`;
29+
link.className = "dynamic-toc-link";
30+
link.textContent = header.textContent;
31+
32+
tocContainer.appendChild(link);
33+
34+
// Add a divider after each link, except for the last one
35+
if (index < headers.length - 1) {
36+
const divider = document.createElement("div");
37+
divider.className = "dynamic-page-toc-divider";
38+
tocContainer.appendChild(divider);
39+
}
40+
});
41+
42+
if (headers.length === 0) {
43+
tocContainer.remove();
44+
}
45+
});

0 commit comments

Comments
 (0)