1
+ < script >
2
+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
3
+ // Only add button if we're on a tutorial page
4
+ const path = window . location . pathname ;
5
+ if ( path . includes ( '/tutorials/' ) || path . includes ( '/usage/' ) ) {
6
+ // Extract the notebook name from the URL
7
+ const pathParts = path . split ( '/' ) ;
8
+ const section = pathParts [ pathParts . length - 2 ] ;
9
+
10
+ // Create download button
11
+ const downloadBtn = document . createElement ( 'a' ) ;
12
+ downloadBtn . className = 'btn btn-primary download-notebook-btn' ;
13
+ downloadBtn . innerHTML = '<i class="bi bi-download"></i> Download as Notebook' ;
14
+
15
+ // Generate GitHub raw URL for the notebook
16
+ const baseUrl = 'https://raw.githubusercontent.com/TuringLang/docs/main' ;
17
+ const notebookPath = path . replace ( '.html' , '.ipynb' ) ;
18
+ downloadBtn . href = baseUrl + notebookPath ;
19
+ downloadBtn . download = section + '.ipynb' ;
20
+
21
+ // Insert button after title or in TOC area
22
+ const tocTitle = document . querySelector ( '.toc-title' ) ;
23
+ if ( tocTitle ) {
24
+ tocTitle . parentNode . insertBefore ( downloadBtn , tocTitle . nextSibling ) ;
25
+ } else {
26
+ const articleHeader = document . querySelector ( 'header.quarto-title-block' ) ;
27
+ if ( articleHeader ) {
28
+ articleHeader . appendChild ( downloadBtn ) ;
29
+ }
30
+ }
31
+ }
32
+ } ) ;
33
+ </ script >
34
+
35
+ < style >
36
+ .download-notebook-btn {
37
+ display : inline-block;
38
+ margin : 1rem 0 ;
39
+ padding : 0.5rem 1rem ;
40
+ background-color : var (--bs-primary );
41
+ color : white;
42
+ text-decoration : none;
43
+ border-radius : 0.25rem ;
44
+ font-size : 0.9rem ;
45
+ }
46
+
47
+ .download-notebook-btn : hover {
48
+ background-color : var (--bs-primary-dark );
49
+ color : white;
50
+ text-decoration : none;
51
+ }
52
+
53
+ .download-notebook-btn i {
54
+ margin-right : 0.5rem ;
55
+ }
56
+ </ style >
0 commit comments