Skip to content

Commit

Permalink
zz
Browse files Browse the repository at this point in the history
  • Loading branch information
chai2010 committed Jun 17, 2024
1 parent 4d4cf1e commit 3e9d3d0
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/render/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
//go:embed tmpl/page.html
var tmplPage string

//go:embed tmpl/talk.html
var tmplTalk string

//go:embed tmpl/print.html
var tmplPrintPage string

Expand Down
42 changes: 41 additions & 1 deletion pkg/render/page_talk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

package render

import (
"bytes"
"html/template"
"os"
"path/filepath"
"strings"

"github.com/wa-lang/mnbook/pkg/mntalk/present"
)

func (p *BookRendor) renderAllTalkPages() error {
if len(p.Book.Talks) == 0 {
return nil
Expand All @@ -18,6 +28,36 @@ func (p *BookRendor) renderAllTalkPages() error {
return nil
}

func (p *BookRendor) renderTalkPages(path string) error {
func (p *BookRendor) renderTalkPages(name string) error {
content, err := os.ReadFile(name)
if err != nil {
return err
}

doc, err := present.Parse(bytes.NewReader(content), name, 0)
if err != nil {
return err
}

var fnMap = template.FuncMap{}
t := template.Must(template.New("").Funcs(fnMap).Parse(tmplTalk))

var buf bytes.Buffer
if err = doc.Render(&buf, t); err != nil {
return err
}

relpath := name
dstAbsPath := filepath.Join(p.Book.Root, "book", relpath)
if ext := filepath.Ext(dstAbsPath); strings.EqualFold(ext, ".md") {
dstAbsPath = dstAbsPath[:len(dstAbsPath)-len(".md")]
}
dstAbsPath += ".html"

os.MkdirAll(filepath.Dir(dstAbsPath), 0777)
if err := os.WriteFile(dstAbsPath, buf.Bytes(), 0666); err != nil {
return err
}

return nil
}
107 changes: 107 additions & 0 deletions pkg/render/tmpl/talk.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{/* This is the slide template. It defines how presentations are formatted. */}

{{define "root"}}
<!DOCTYPE html>
<html>
<head>
<title>{{.Title}}</title>
<meta charset='utf-8'>
<script>
var notesEnabled = {{.NotesEnabled}};
</script>
<script src='/static/slides.js'></script>

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

<script>
// Initialize Google Analytics tracking code on production site only.
if (window["location"] && window["location"]["hostname"] == "talks.golang.org") {
var _gaq = _gaq || [];
_gaq.push(["_setAccount", "UA-11222381-6"]);
_gaq.push(["b._setAccount", "UA-49880327-6"]);
window.trackPageview = function() {
_gaq.push(["_trackPageview", location.pathname+location.hash]);
_gaq.push(["b._trackPageview", location.pathname+location.hash]);
};
window.trackPageview();
window.trackEvent = function(category, action, opt_label, opt_value, opt_noninteraction) {
_gaq.push(["_trackEvent", category, action, opt_label, opt_value, opt_noninteraction]);
_gaq.push(["b._trackEvent", category, action, opt_label, opt_value, opt_noninteraction]);
};
}
</script>
</head>

<body style='display: none'>

<section class='slides layout-widescreen'>

<article>
<h1>{{.Title}}</h1>
{{with .Subtitle}}<h3>{{.}}</h3>{{end}}
{{if not .Time.IsZero}}<h3>{{.Time.Format "2 January 2006"}}</h3>{{end}}
{{range .Authors}}
<div class="presenter">
{{range .TextElem}}{{elem $.Template .}}{{end}}
</div>
{{end}}
</article>

{{range $i, $s := .Sections}}
<!-- start of slide {{$s.Number}} -->
<article {{$s.HTMLAttributes}}>
{{if $s.Elem}}
<h3>{{$s.Title}}</h3>
{{range $s.Elem}}{{elem $.Template .}}{{end}}
{{else}}
<h2>{{$s.Title}}</h2>
{{end}}
<span class="pagenumber">{{pagenum $s 1}}</span>
</article>
<!-- end of slide {{$s.Number}} -->
{{end}}{{/* of Slide block */}}

<article>
<h3>Thank you</h3>
{{range .Authors}}
<div class="presenter">
{{range .Elem}}{{elem $.Template .}}{{end}}
</div>
{{end}}
</article>

</section>

<div id="help">
Use the left and right arrow keys or click the left and right
edges of the page to navigate between slides.<br>
(Press 'H' or navigate to hide this message.)
</div>

{{if .PlayEnabled}}
<script src='/play.js'></script>
{{end}}

<script>
(function() {
// Load Google Analytics tracking code on production site only.
if (window["location"] && window["location"]["hostname"] == "talks.golang.org") {
var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);
}
})();
</script>
</body>
</html>
{{end}}

{{define "newline"}}
<br>
{{end}}

0 comments on commit 3e9d3d0

Please sign in to comment.