2020-12-04 15:28:02 +00:00
|
|
|
// Copyright © 2019 Peter Kurfer peter.kurfer@googlemail.com
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package rendering
|
|
|
|
|
|
|
|
import (
|
2021-11-12 12:08:56 +00:00
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-12-04 15:28:02 +00:00
|
|
|
"github.com/bmatcuk/doublestar/v2"
|
2020-12-06 11:18:42 +00:00
|
|
|
"github.com/imdario/mergo"
|
2020-12-04 15:28:02 +00:00
|
|
|
"github.com/spf13/viper"
|
2021-11-15 14:23:10 +00:00
|
|
|
|
|
|
|
"github.com/baez90/goveal/internal/encoding"
|
2020-12-06 11:18:42 +00:00
|
|
|
)
|
|
|
|
|
2021-11-12 12:08:56 +00:00
|
|
|
var defaultParams = RevealParams{
|
|
|
|
Theme: "white",
|
|
|
|
CodeTheme: "vs",
|
|
|
|
Transition: "None",
|
|
|
|
NavigationMode: "default",
|
|
|
|
HorizontalSeparator: "===",
|
|
|
|
VerticalSeparator: "---",
|
|
|
|
SlideNumberVisibility: "all",
|
|
|
|
SlideNumberFormat: "h.v",
|
|
|
|
StyleSheets: make([]string, 0),
|
|
|
|
FilesToMonitor: make([]string, 0),
|
|
|
|
}
|
2020-12-04 15:28:02 +00:00
|
|
|
|
|
|
|
type RevealParams struct {
|
2021-11-15 14:23:10 +00:00
|
|
|
Theme string `mapstructure:"theme"`
|
|
|
|
CodeTheme string `mapstructure:"codeTheme"`
|
|
|
|
Transition string `mapstructure:"transition"`
|
|
|
|
NavigationMode string `mapstructure:"navigationMode"`
|
|
|
|
HorizontalSeparator string `mapstructure:"horizontalSeparator"`
|
|
|
|
VerticalSeparator string `mapstructure:"verticalSeparator"`
|
|
|
|
SlideNumberVisibility string `mapstructure:"slideNumberVisibility"`
|
|
|
|
SlideNumberFormat string `mapstructure:"slideNumberFormat"`
|
|
|
|
StyleSheets []string `mapstructure:"stylesheets"`
|
|
|
|
FilesToMonitor []string `mapstructure:"filesToMonitor"`
|
|
|
|
WorkingDirectory string `mapstructure:"working-dir"`
|
|
|
|
LineEnding encoding.LineEnding `mapstructure:"-"`
|
2020-12-04 15:28:02 +00:00
|
|
|
}
|
|
|
|
|
2020-12-06 11:18:42 +00:00
|
|
|
func (params *RevealParams) Load() error {
|
2020-12-04 15:28:02 +00:00
|
|
|
_ = viper.Unmarshal(params)
|
|
|
|
expandGlobs(params)
|
2020-12-06 11:18:42 +00:00
|
|
|
return mergo.Merge(params, &defaultParams)
|
2020-12-04 15:28:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func expandGlobs(params *RevealParams) {
|
|
|
|
var allFiles []string
|
|
|
|
|
|
|
|
for _, f := range params.FilesToMonitor {
|
|
|
|
var err error
|
|
|
|
|
2020-12-06 11:18:42 +00:00
|
|
|
f, err = filepath.Abs(f)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-12-04 15:28:02 +00:00
|
|
|
var matches []string
|
|
|
|
if matches, err = doublestar.Glob(f); err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-12-06 11:18:42 +00:00
|
|
|
|
|
|
|
for idx := range matches {
|
|
|
|
if relative, err := filepath.Rel(params.WorkingDirectory, matches[idx]); err != nil {
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
matches[idx] = path.Join("/", relative)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 15:28:02 +00:00
|
|
|
allFiles = append(allFiles, matches...)
|
|
|
|
}
|
|
|
|
params.FilesToMonitor = allFiles
|
|
|
|
}
|