|
11 | 11 | </template>
|
12 | 12 |
|
13 | 13 | <script>
|
14 |
| - require.config({ |
15 |
| - paths: { |
16 |
| - 'js-yaml': 'https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min' |
17 |
| - } |
18 |
| - }); |
| 14 | + // First, load RequireJS if it's not already loaded |
| 15 | + if (typeof require === 'undefined') { |
| 16 | + const requireScript = document.createElement('script'); |
| 17 | + requireScript.src = 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js'; |
| 18 | + requireScript.onload = function() { |
| 19 | + initAuthorReveal(); |
| 20 | + }; |
| 21 | + document.head.appendChild(requireScript); |
| 22 | + } else { |
| 23 | + initAuthorReveal(); |
| 24 | + } |
| 25 | + |
| 26 | + function initAuthorReveal() { |
| 27 | + require.config({ |
| 28 | + paths: { |
| 29 | + 'js-yaml': 'https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min' |
| 30 | + } |
| 31 | + }); |
19 | 32 |
|
20 |
| - require(['js-yaml'], function (jsyaml) { |
| 33 | + require(['js-yaml'], function (jsyaml) { |
21 | 34 | // Function to get last name from full name
|
22 | 35 | function getLastName(fullName) {
|
23 | 36 | const nameParts = fullName.trim().split(' ');
|
|
39 | 52 | const authorYamlPath = baseUrl + '/authors.yml';
|
40 | 53 |
|
41 | 54 | const response = await fetch(authorYamlPath);
|
| 55 | + if (!response.ok) { |
| 56 | + throw new Error(`HTTP error! status: ${response.status}`); |
| 57 | + } |
| 58 | + |
42 | 59 | const yamlText = await response.text();
|
43 | 60 | window.authorData = jsyaml.load(yamlText);
|
44 | 61 | initializeAuthors();
|
|
50 | 67 | function initializeAuthors() {
|
51 | 68 | // Find the quarto-title-meta div
|
52 | 69 | const titleMeta = document.querySelector('.quarto-title-meta');
|
53 |
| - if (!titleMeta) return; |
| 70 | + if (!titleMeta) { |
| 71 | + return; |
| 72 | + } |
54 | 73 |
|
55 | 74 | // Get template content
|
56 | 75 | const template = document.getElementById('authors-template');
|
| 76 | + if (!template) { |
| 77 | + return; |
| 78 | + } |
57 | 79 | const authorsSection = template.content.cloneNode(true);
|
58 | 80 |
|
59 | 81 | // Get the authors content div from the cloned template
|
|
114 | 136 | const toggle = document.querySelector('.authors-toggle');
|
115 | 137 | const content = document.querySelector('.authors-content');
|
116 | 138 |
|
| 139 | + if (!toggle || !content) { |
| 140 | + return; |
| 141 | + } |
| 142 | + |
117 | 143 | toggle.addEventListener('click', () => {
|
118 | 144 | const isExpanded = toggle.getAttribute('aria-expanded') === 'true';
|
119 | 145 | toggle.setAttribute('aria-expanded', !isExpanded);
|
|
132 | 158 | } else {
|
133 | 159 | loadAuthorData();
|
134 | 160 | }
|
135 |
| - }); |
| 161 | + }); |
| 162 | + } |
136 | 163 | </script>
|
0 commit comments