File tree Expand file tree Collapse file tree 4 files changed +24
-37
lines changed Expand file tree Collapse file tree 4 files changed +24
-37
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ func Register(name string, parser ParseFunc) {
6969
7070// Doc represents an entire document.
7171type Doc struct {
72+ Root string // 根目录相对路径
7273 Title string
7374 Subtitle string
7475 Summary string
Original file line number Diff line number Diff line change @@ -486,46 +486,12 @@ function addEventListeners() {
486486
487487/* Initialization */
488488
489- function addFontStyle ( ) {
490- var el = document . createElement ( 'link' ) ;
491- el . rel = 'stylesheet' ;
492- el . type = 'text/css' ;
493-
494- //el.href =
495- // '//fonts.googleapis.com/css?family=' +
496- // 'Open+Sans:regular,semibold,italic,italicsemibold|Droid+Sans+Mono';
497- el . href = PERMANENT_URL_PREFIX + 'font.css' ;
498-
499- document . body . appendChild ( el ) ;
500- }
501-
502- function addGeneralStyle ( ) {
503- var el = document . createElement ( 'link' ) ;
504- el . rel = 'stylesheet' ;
505- el . type = 'text/css' ;
506- el . href = PERMANENT_URL_PREFIX + 'styles.css' ;
507- document . body . appendChild ( el ) ;
508-
509- var el = document . createElement ( 'meta' ) ;
510- el . name = 'viewport' ;
511- el . content = 'width=device-width,height=device-height,initial-scale=1' ;
512- document . querySelector ( 'head' ) . appendChild ( el ) ;
513-
514- var el = document . createElement ( 'meta' ) ;
515- el . name = 'mobile-web-app-capable' ;
516- el . content = 'yes' ;
517- document . querySelector ( 'head' ) . appendChild ( el ) ;
518-
519- scaleSmallViewports ( ) ;
520- }
521-
522489function handleDomLoaded ( ) {
523490 slideEls = document . querySelectorAll ( 'section.slides > article' ) ;
524491
525492 setupFrames ( ) ;
526493
527- addFontStyle ( ) ;
528- addGeneralStyle ( ) ;
494+ scaleSmallViewports ( ) ;
529495 addEventListeners ( ) ;
530496
531497 updateSlides ( ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package render
66
77import (
88 "bytes"
9+ "fmt"
910 "html/template"
1011 "os"
1112 "path/filepath"
@@ -28,6 +29,15 @@ func (p *BookRendor) renderAllTalkPages() error {
2829 return nil
2930}
3031
32+ func (p * BookRendor ) getTalkPageRoot (path string ) string {
33+ absPath := filepath .Clean (filepath .Join (p .Book .Root , filepath .Dir (path )))
34+ relPath , err := filepath .Rel (absPath , p .Book .Root )
35+ if err != nil {
36+ panic (fmt .Sprintf ("BookRendor.getTalkPageRoot(%v): %v" , path , err ))
37+ }
38+ return relPath
39+ }
40+
3141func (p * BookRendor ) renderTalkPages (path string ) error {
3242 content , err := os .ReadFile (filepath .Join (p .Book .Root , path ))
3343 if err != nil {
@@ -39,6 +49,9 @@ func (p *BookRendor) renderTalkPages(path string) error {
3949 return err
4050 }
4151
52+ // 设置根目录相对路径
53+ doc .Root = p .getTalkPageRoot (path )
54+
4255 t := template .Must (present .Template ().Parse (tmplPresent ))
4356 t = template .Must (t .Parse (tmplAction ))
4457
Original file line number Diff line number Diff line change 66 < head >
77 < title > {{.Title}}</ title >
88 < meta charset ='utf-8 '>
9+
10+ < meta name ="mobile-web-app-capable " content ="yes ">
11+ < meta name ="viewport " content ="width=device-width,height=device-height,initial-scale=1 ">
12+
13+ < link rel ="stylesheet " href ="{{.Root}}/static/present/font.css ">
14+ < link rel ="stylesheet " href ="{{.Root}}/static/present/styles.css ">
15+
916 < script >
1017 var notesEnabled = { { . NotesEnabled} } ;
1118 </ script >
12- < script src ='. /static/present/slides.js '> </ script >
19+ < script src ='{{.Root}} /static/present/slides.js '> </ script >
1320
1421 {{if .NotesEnabled}}
1522 < script >
1623 var sections = { { . Sections} } ;
1724 var titleNotes = { { . TitleNotes} }
1825 </ script >
19- < script src ='. /static/present/notes.js '> </ script >
26+ < script src ='{{.Root}} /static/present/notes.js '> </ script >
2027 {{end}}
2128 </ head >
2229
You can’t perform that action at this time.
0 commit comments