Skip to content

Commit

Permalink
talk支持放子目录
Browse files Browse the repository at this point in the history
  • Loading branch information
chai2010 committed Nov 1, 2024
1 parent 7c9e57b commit 294d736
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 37 deletions.
1 change: 1 addition & 0 deletions pkg/present/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func Register(name string, parser ParseFunc) {

// Doc represents an entire document.
type Doc struct {
Root string // 根目录相对路径
Title string
Subtitle string
Summary string
Expand Down
36 changes: 1 addition & 35 deletions pkg/render/_static/static/present/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,46 +486,12 @@ function addEventListeners() {

/* Initialization */

function addFontStyle() {
var el = document.createElement('link');
el.rel = 'stylesheet';
el.type = 'text/css';

//el.href =
// '//fonts.googleapis.com/css?family=' +
// 'Open+Sans:regular,semibold,italic,italicsemibold|Droid+Sans+Mono';
el.href = PERMANENT_URL_PREFIX + 'font.css';

document.body.appendChild(el);
}

function addGeneralStyle() {
var el = document.createElement('link');
el.rel = 'stylesheet';
el.type = 'text/css';
el.href = PERMANENT_URL_PREFIX + 'styles.css';
document.body.appendChild(el);

var el = document.createElement('meta');
el.name = 'viewport';
el.content = 'width=device-width,height=device-height,initial-scale=1';
document.querySelector('head').appendChild(el);

var el = document.createElement('meta');
el.name = 'mobile-web-app-capable';
el.content = 'yes';
document.querySelector('head').appendChild(el);

scaleSmallViewports();
}

function handleDomLoaded() {
slideEls = document.querySelectorAll('section.slides > article');

setupFrames();

addFontStyle();
addGeneralStyle();
scaleSmallViewports();
addEventListeners();

updateSlides();
Expand Down
13 changes: 13 additions & 0 deletions pkg/render/slide.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package render

import (
"bytes"
"fmt"
"html/template"
"os"
"path/filepath"
Expand All @@ -28,6 +29,15 @@ func (p *BookRendor) renderAllTalkPages() error {
return nil
}

func (p *BookRendor) getTalkPageRoot(path string) string {
absPath := filepath.Clean(filepath.Join(p.Book.Root, filepath.Dir(path)))
relPath, err := filepath.Rel(absPath, p.Book.Root)
if err != nil {
panic(fmt.Sprintf("BookRendor.getTalkPageRoot(%v): %v", path, err))
}
return relPath
}

func (p *BookRendor) renderTalkPages(path string) error {
content, err := os.ReadFile(filepath.Join(p.Book.Root, path))
if err != nil {
Expand All @@ -39,6 +49,9 @@ func (p *BookRendor) renderTalkPages(path string) error {
return err
}

// 设置根目录相对路径
doc.Root = p.getTalkPageRoot(path)

t := template.Must(present.Template().Parse(tmplPresent))
t = template.Must(t.Parse(tmplAction))

Expand Down
11 changes: 9 additions & 2 deletions pkg/render/tmpl/present.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
<head>
<title>{{.Title}}</title>
<meta charset='utf-8'>

<meta name="mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

<link rel="stylesheet" href="{{.Root}}/static/present/font.css">
<link rel="stylesheet" href="{{.Root}}/static/present/styles.css">

<script>
var notesEnabled = {{.NotesEnabled}};
</script>
<script src='./static/present/slides.js'></script>
<script src='{{.Root}}/static/present/slides.js'></script>

{{if .NotesEnabled}}
<script>
var sections = {{.Sections}};
var titleNotes = {{.TitleNotes}}
</script>
<script src='./static/present/notes.js'></script>
<script src='{{.Root}}/static/present/notes.js'></script>
{{end}}
</head>

Expand Down

0 comments on commit 294d736

Please sign in to comment.