Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add template slide option #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ cover.out
original.css
.vscode/
dist/
/revealgo
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ Available options:
-p, --port TCP port number of this server (default: 3000)
--theme Slide theme or original css file name. default themes:
beige, black, blood, league, moon, night, serif, simple, sky, solarized, and white (default: black.css)
--template Custom HTML template file name. default template: slide
--disable-auto-open Disable automatic opening of the browser
--transition Transition effect for slides: default, cube, page, concave, zoom, linear, fade, none (default: default)
--separator Horizontal slide separator characters (default: ^---)
--vertical-separator Vertical slide separator characters (default: ^___)
--multiplex Enable slide multiplex
--multiplex Enable slide multiplexing
-v, --version Show the version
```

### Screenshots
Expand All @@ -59,7 +62,7 @@ Open the server address with your web browser:

![Slides](https://cloud.githubusercontent.com/assets/10682/12741672/f9cda548-c9c1-11e5-9c21-fcaf1af3cdf4.png)

### Sample Makrdown
### Sample Markdown

```text
## This is an H2 Title
Expand Down Expand Up @@ -111,6 +114,14 @@ $ curl http://localhost:3000/ > slide.html

Edit `slide.html`, and then open `http://localhost:3000/slide.html` with your browser. A slide with the modified configurations will come up.

### Customize Slide template

A custom `slide.html` can also be provided using the `--template` option, or putting a `slide.html` next to your custom theme file.
This allows you to use templating within your `slide.html`

You could use the `slide.html` output from your localhost, or grab a copy of the orignal asset to use as the base.
This can be obtained from: <https://github.com/yusukebe/revealgo/blob/master/assets/templates/slide.html>

### Using slide multiplex

> The multiplex plugin allows your audience to follow the slides of the
Expand Down
9 changes: 9 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type CLI struct {
type CLIOptions struct {
Port int `short:"p" long:"port" description:"TCP port number of this server" default:"3000"`
Theme string `long:"theme" description:"Slide theme or original css file name. default themes: beige, black, blood, league, moon, night, serif, simple, sky, solarized, and white" default:"black.css"`
Template string `long:"template" description:"Custom HTML template file name. default template: slide"`
DisableAutoOpen bool `long:"disable-auto-open" description:"Disable automatic opening of the browser"`
Transition string `long:"transition" description:"Transition effect for slides: default, cube, page, concave, zoom, linear, fade, none" default:"default"`
Separator string `long:"separator" description:"Horizontal slide separator characters" default:"^---"`
Expand Down Expand Up @@ -79,14 +80,22 @@ func (cli *CLI) serve(args []string) {
originalTheme = true
}

_, err = os.Stat(opts.Template)
originalTemplate := false
if err == nil {
originalTemplate = true
}

server := Server{
port: opts.Port,
}
param := ServerParam{
Path: args[0],
Theme: addExtention(opts.Theme, "css"),
Template: addExtention(opts.Template, "html"),
Transition: opts.Transition,
OriginalTheme: originalTheme,
OriginalTemplate: originalTemplate,
DisableAutoOpen: opts.DisableAutoOpen,
Separator: opts.Separator,
VerticalSeparator: opts.VerticalSeparator,
Expand Down
23 changes: 22 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"text/template"

Expand Down Expand Up @@ -36,6 +37,8 @@ type ServerParam struct {
Path string
Theme string
OriginalTheme bool
Template string
OriginalTemplate bool
DisableAutoOpen bool
Transition string
Separator string
Expand Down Expand Up @@ -144,7 +147,25 @@ func contentHandler(params ServerParam, h http.Handler) http.Handler {
return
}

tmpl, err := template.New("slide template").Parse(slideTemplate)
useTemplate := slideTemplate

if params.OriginalTemplate || params.OriginalTheme {
var errOpenTempl error
var templByteStream []byte
if params.Template != ".html" {
templByteStream, errOpenTempl = os.ReadFile(params.Template)
} else {
tryTemplateFile := fmt.Sprintf("%s/slide.html", filepath.Dir(params.Theme))
templByteStream, errOpenTempl = os.ReadFile(tryTemplateFile)
}
if errOpenTempl != nil {
log.Printf("error:%v", errOpenTempl)
http.NotFound(w, r)
return
}
useTemplate = string(templByteStream)
}
tmpl, err := template.New("slide template").Parse(useTemplate)
if err != nil {
log.Printf("error:%v", err)
http.NotFound(w, r)
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package revealgo

var Version string = "v1.2.2"
var Version string = "v1.3.0"