Skip to content

Commit

Permalink
feat: add chess slides + reveal render tool (#37)
Browse files Browse the repository at this point in the history
* feat: add chess slides + reveal render tool

* update action;

* xxx

* copy images

* || true

* Revert "update action;"

This reverts commit 6f76780.

* Update .github/workflows/github-pages.yml

Co-authored-by: Manfred Touron <[email protected]>

* Update cmd/reveal/template.go

Co-authored-by: Manfred Touron <[email protected]>

---------

Co-authored-by: Manfred Touron <[email protected]>
  • Loading branch information
thehowl and moul authored Oct 18, 2023
1 parent 38f9069 commit f67509e
Show file tree
Hide file tree
Showing 15 changed files with 776 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ jobs:

- uses: actions/setup-go@v4
with:
go-version: '1.20.x'
go-version: "1.20.x"

- run: go install golang.org/x/tools/cmd/present
- run: go install ./cmd/reveal

- name: convert .reveal.md files
run: reveal presentations/*/*.reveal.md

- name: start server and mirror it with wget
run: |
Expand All @@ -28,6 +32,9 @@ jobs:
# hacks: wget is missing styles.css (injected in JS)
wget --mirror http://localhost:3999/static/styles.css -P workshops --no-host-directories --page-requisites --adjust-extension --convert-links
# hacks: copy over the images
# (at time of writing, they come from rendered markdown files, which wget can't follow)
for i in presentations/*/*.{png,jpg,jpeg}; do cp $i workshops/$i; done || true
sed -i='' s@/static/@/workshops/static/@ workshops/static/slides.js
- run: find workshops/ -type f -ls
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
# Editor Leftovers
.vscode
.idea

# generated files from reveal tool
slides.html
63 changes: 63 additions & 0 deletions cmd/reveal/reveal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Command reveal allows you to generate an HTML file, rendering a
// Markdown-based reveal.js presentation.
package main

import (
"bytes"
"fmt"
"os"
"strings"

"gopkg.in/yaml.v3"
)

func main() {
var es int
for _, v := range os.Args[1:] {
if err := convertFile(v); err != nil {
fmt.Fprintf(os.Stderr, "%s: error converting: %v", err)
es = 1
}
}
os.Exit(es)
}

func convertFile(fname string) error {
mdSrc, err := os.ReadFile(fname)
if err != nil {
return err
}

parts := bytes.SplitN(mdSrc, []byte("---\n"), 3)
if len(parts[0]) != 0 {
return fmt.Errorf("invalid front matter")
}
var config combinedConfig
err = yaml.Unmarshal(parts[1], &config)
if err != nil {
return err
}
rd := config.renderData()
rd.Presentation = string(parts[2])
newFname := stripAnySuffix(fname, ".reveal.md", ".md") + ".html"
dest, err := os.Create(newFname)
if err != nil {
return err
}
defer dest.Close()
if err = tpl.Execute(dest, rd); err != nil {
return err
}

fmt.Printf("%s converted to %s\n", fname, newFname)
return nil
}

func stripAnySuffix(s string, suffixes ...string) string {
for _, suff := range suffixes {
if strings.HasSuffix(s, suff) {
return s[:len(s)-len(suff)]
}
}
return s
}
119 changes: 119 additions & 0 deletions cmd/reveal/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package main

import (
_ "embed"
"html/template"
)

// https://revealjs.com/config/
// pointers everywhere so we don't accidentally copy over stuff we don't need.
type revealConfig struct {
Controls *bool `yaml:"controls" json:"controls,omitempty"`
ControlsTutorial *bool `yaml:"controlsTutorial" json:"controlsTutorial,omitempty"`
ControlsLayout *string `yaml:"controlsLayout" json:"controlsLayout,omitempty"`
ControlsBackArrows *string `yaml:"controlsBackArrows" json:"controlsBackArrows,omitempty"`
Progress *bool `yaml:"progress" json:"progress,omitempty"`
SlideNumber *bool `yaml:"slideNumber" json:"slideNumber,omitempty"`
ShowSlideNumber *string `yaml:"showSlideNumber" json:"showSlideNumber,omitempty"`
HashOneBasedIndex *bool `yaml:"hashOneBasedIndex" json:"hashOneBasedIndex,omitempty"`
Hash *bool `yaml:"hash" json:"hash,omitempty"`
RespondToHashChanges *bool `yaml:"respondToHashChanges" json:"respondToHashChanges,omitempty"`
JumpToSlide *bool `yaml:"jumpToSlide" json:"jumpToSlide,omitempty"`
History *bool `yaml:"history" json:"history,omitempty"`
Keyboard *bool `yaml:"keyboard" json:"keyboard,omitempty"`
KeyboardCondition *string `yaml:"keyboardCondition" json:"keyboardCondition,omitempty"`
DisableLayout *bool `yaml:"disableLayout" json:"disableLayout,omitempty"`
Overview *bool `yaml:"overview" json:"overview,omitempty"`
Center *bool `yaml:"center" json:"center,omitempty"`
Touch *bool `yaml:"touch" json:"touch,omitempty"`
Loop *bool `yaml:"loop" json:"loop,omitempty"`
Rtl *bool `yaml:"rtl" json:"rtl,omitempty"`
NavigationMode *string `yaml:"navigationMode" json:"navigationMode,omitempty"`
Shuffle *bool `yaml:"shuffle" json:"shuffle,omitempty"`
Fragments *bool `yaml:"fragments" json:"fragments,omitempty"`
FragmentInURL *bool `yaml:"fragmentInURL" json:"fragmentInURL,omitempty"`
Embedded *bool `yaml:"embedded" json:"embedded,omitempty"`
Help *bool `yaml:"help" json:"help,omitempty"`
Pause *bool `yaml:"pause" json:"pause,omitempty"`
ShowNotes *bool `yaml:"showNotes" json:"showNotes,omitempty"`
AutoPlayMedia *bool `yaml:"autoPlayMedia" json:"autoPlayMedia,omitempty"`
PreloadIframes *bool `yaml:"preloadIframes" json:"preloadIframes,omitempty"`
AutoAnimate *bool `yaml:"autoAnimate" json:"autoAnimate,omitempty"`
AutoAnimateMatcher *string `yaml:"autoAnimateMatcher" json:"autoAnimateMatcher,omitempty"`
AutoAnimateEasing *string `yaml:"autoAnimateEasing" json:"autoAnimateEasing,omitempty"`
AutoAnimateDuration *int `yaml:"autoAnimateDuration" json:"autoAnimateDuration,omitempty"`
AutoAnimateUnmatched *bool `yaml:"autoAnimateUnmatched" json:"autoAnimateUnmatched,omitempty"`
AutoAnimateStyles *[]string `yaml:"autoAnimateStyles" json:"autoAnimateStyles,omitempty"`
AutoSlide *int `yaml:"autoSlide" json:"autoSlide,omitempty"`
AutoSlideStoppable *bool `yaml:"autoSlideStoppable" json:"autoSlideStoppable,omitempty"`
DefaultTiming *int `yaml:"defaultTiming" json:"defaultTiming,omitempty"`
MouseWheel *bool `yaml:"mouseWheel" json:"mouseWheel,omitempty"`
PreviewLinks *bool `yaml:"previewLinks" json:"previewLinks,omitempty"`
PostMessage *bool `yaml:"postMessage" json:"postMessage,omitempty"`
PostMessageEvents *bool `yaml:"postMessageEvents" json:"postMessageEvents,omitempty"`
FocusBodyOnPageVisibilityChange *bool `yaml:"focusBodyOnPageVisibilityChange" json:"focusBodyOnPageVisibilityChange,omitempty"`
Transition *string `yaml:"transition" json:"transition,omitempty"`
TransitionSpeed *string `yaml:"transitionSpeed" json:"transitionSpeed,omitempty"`
BackgroundTransition *string `yaml:"backgroundTransition" json:"backgroundTransition,omitempty"`
PdfMaxPagesPerSlide *int `yaml:"pdfMaxPagesPerSlide" json:"pdfMaxPagesPerSlide,omitempty"`
PdfSeparateFragments *bool `yaml:"pdfSeparateFragments" json:"pdfSeparateFragments,omitempty"`
PdfPageHeightOffset *int `yaml:"pdfPageHeightOffset" json:"pdfPageHeightOffset,omitempty"`
ViewDistance *int `yaml:"viewDistance" json:"viewDistance,omitempty"`
MobileViewDistance *int `yaml:"mobileViewDistance" json:"mobileViewDistance,omitempty"`
Display *string `yaml:"display" json:"display,omitempty"`
HideInactiveCursor *bool `yaml:"hideInactiveCursor" json:"hideInactiveCursor,omitempty"`
HideCursorTime *int `yaml:"hideCursorTime" json:"hideCursorTime,omitempty"`

Width *int `yaml:"width" json:"width,omitempty"`
Height *int `yaml:"height" json:"height,omitempty"`
Margin *float64 `yaml:"margin" json:"margin,omitempty"`
MinScale *float64 `yaml:"minScale" json:"minScale,omitempty"`
MaxScale *float64 `yaml:"maxScale" json:"maxScale,omitempty"`
}

type combinedConfig struct {
Title string `yaml:"title"`
Theme string `yaml:"theme"`
revealConfig `yaml:",inline"`
}

func (c combinedConfig) renderData() renderData {
r := renderData{
Title: c.Title,
Theme: c.Theme,
Config: c.revealConfig,
}
r.ApplyDefaults()
return r
}

type renderData struct {
Title string
Theme string
Presentation string
Config revealConfig
}

func (r *renderData) ApplyDefaults() {
if r.Title == "" {
r.Title = "Gno Presentation"
}
if r.Theme == "" {
r.Theme = "black"
}
if r.Config.Hash == nil {
r.Config.Hash = ptrTo(true)
}
if r.Config.HashOneBasedIndex == nil {
r.Config.HashOneBasedIndex = ptrTo(true)
}
}

func ptrTo[T any](v T) *T {
return &v
}

//go:embed template.html
var tplData string

var tpl = template.Must(template.New("").Parse(tplData))
45 changes: 45 additions & 0 deletions cmd/reveal/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{{ .Title }}</title>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/reveal.css"
/>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/theme/{{ .Theme }}.css"
/>
{{/* TODO: Make configurable. */}}
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/plugin/highlight/monokai.css"
/>
<style>
/* While we don't currently have a theme, make it so that our headers are not shouting. */
:root {
--r-heading-text-transform: none;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-markdown>
<textarea data-template>{{ .Presentation }}</textarea>
</section>
</div>
</div>

<script src="https://unpkg.com/[email protected]/dist/reveal.js"></script>
<script src="https://unpkg.com/[email protected]/plugin/markdown/markdown.js"></script>
<script src="https://unpkg.com/[email protected]/plugin/notes/notes.js"></script>
<script src="https://unpkg.com/[email protected]/plugin/highlight/highlight.js"></script>
<script>
Reveal.initialize(Object.assign({
plugins: [RevealMarkdown, RevealNotes, RevealHighlight],
}, {{ .Config }}));
</script>
</body>
</html>
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ require (
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f67509e

Please sign in to comment.