File size: 3,170 Bytes
fee9c1e
 
 
 
 
 
 
 
 
 
 
 
e0ad823
fee9c1e
e0ad823
 
fee9c1e
 
 
 
 
 
 
 
fc7711a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e329457
fc7711a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e0ad823
fc7711a
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
interface Props {
  citationText: string;
  bibtex: string;
}
const { citationText, bibtex } = Astro.props as Props;
---
<footer class="distill-footer">
  <div class="footer-inner">
    <section class="citation-block">
      <h3>Citation</h3>
      <p>For attribution in academic contexts, please cite this work as</p>
      <pre class="citation short">{citationText}</pre>

      <p>BibTeX citation</p>
      <pre class="citation long">{bibtex}</pre>
    </section>
    <section class="references-block">
      <slot />
    </section>
  </div>
</footer>


<script is:inline>
  (() => {
    const getFooter = () => document.currentScript?.closest('footer') || document.querySelector('footer.distill-footer');
    const footer = getFooter();
    if (!footer) return;
    const target = footer.querySelector('.references-block');
    if (!target) return;

    const contentRoot = document.querySelector('section.content-grid main') || document.querySelector('main') || document.body;

    const findFirstOutsideFooter = (selectors) => {
      for (const sel of selectors) {
        const el = contentRoot.querySelector(sel);
        if (el && !footer.contains(el)) return el;
      }
      return null;
    };

    const ensureHeading = (text) => {
      const exists = Array.from(target.children).some((c) => c.tagName === 'H3' && c.textContent.trim().toLowerCase() === text.toLowerCase());
      if (!exists) {
        const h = document.createElement('h3');
        h.textContent = text;
        target.appendChild(h);
      }
    };

    const moveIntoFooter = (element, headingText) => {
      if (!element) return false;
      if (element.classList.contains('footnotes')) {
        const hr = element.querySelector('hr');
        if (hr) hr.remove();
      }
      // Remove an eventual heading already included inside the block (avoid duplicates)
      const firstHeading = element.querySelector(':scope > h1, :scope > h2, :scope > h3');
      if (firstHeading) {
        const txt = (firstHeading.textContent || '').trim().toLowerCase();
        const targetTxt = headingText.trim().toLowerCase();
        if (txt === targetTxt || txt.includes('reference') || txt.includes('bibliograph')) {
          firstHeading.remove();
        }
      }
      ensureHeading(headingText);
      target.appendChild(element);
      return true;
    };

    const run = () => {
      const referencesEl = findFirstOutsideFooter(['#references', '.references', '.bibliography']);
      const footnotesEl = findFirstOutsideFooter(['.footnotes']);
      const movedRefs = moveIntoFooter(referencesEl, 'References');
      const movedNotes = moveIntoFooter(footnotesEl, 'Footnotes');
      return movedRefs || movedNotes;
    };

    // Try now; if not found yet, try again on DOM ready
    const done = run();
    if (!done) {
      const onReady = () => run();
      if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', onReady, { once: true });
      } else {
        setTimeout(onReady, 0);
      }
    }

    // Resize on window changes (e.g., fonts, layout)
    // No textarea auto-resize needed for <pre> blocks
  })();
</script>