Skip to content

Commit

Permalink
docs: Enable the watch feature on themes
Browse files Browse the repository at this point in the history
  • Loading branch information
germainlefebvre4 committed Feb 12, 2025
1 parent cb9abb8 commit e9fcfc4
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 55 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ help: ## Display this help.
run:
go run ./cmd/cvwonder $(filter-out $@,$(MAKECMDGOALS))

build: ## Build
build:
go build -o cvwonder ./cmd/cvwonder
chmod +x cvwonder

test:
go test ./...

doc-install:
poetry --directory docs/ lock && poetry --directory docs/ install

doc:
poetry --directory docs/ run mkdocs serve --config-file docs/mkdocs.yml
poetry --directory docs/ run mkdocs serve --config-file mkdocs.yml

goreleser-check:
goreleaser check
Expand Down
12 changes: 6 additions & 6 deletions cmd/cvwonder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func main() {
logrus.Info("")

// Parse the CV
perserService, err := cvparser.NewParserServices()
parserService, err := cvparser.NewParserServices()
utils.CheckError(err)
content, err := perserService.ParseFile(inputFile.FullPath)
content, err := parserService.ParseFile(inputFile.FullPath)
utils.CheckError(err)

// Create render services
Expand Down Expand Up @@ -108,9 +108,9 @@ func main() {
logrus.Info()

// Parse the CV
perserService, err := cvparser.NewParserServices()
parserService, err := cvparser.NewParserServices()
utils.CheckError(err)
content, err := perserService.ParseFile(inputFile.FullPath)
content, err := parserService.ParseFile(inputFile.FullPath)
utils.CheckError(err)

// Create render services
Expand All @@ -130,9 +130,9 @@ func main() {
utils.CheckError(err)

if utils.CliArgs.Watch {
watcherService, err := watcher.NewWatcherServices()
watcherService, err := watcher.NewWatcherServices(parserService, renderService)
utils.CheckError(err)
go watcherService.ObserveFileEvents(renderService, baseDirectory, outputDir.FullPath, inputFile.FullPath, utils.CliArgs.ThemeName, utils.CliArgs.Format)
go watcherService.ObserveFileEvents(baseDirectory, outputDir.FullPath, inputFile.FullPath, utils.CliArgs.ThemeName, utils.CliArgs.Format)
}
// Serve the CV
serveService.OpenBrowser(outputDir.FullPath, inputFile.FullPath)
Expand Down
110 changes: 73 additions & 37 deletions docs/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/readthedocs/contributing/maintainer/release-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Here are the basic rules that we follow:

## Testing

The release process embedded a testing workflow to ensure everything's developped is stable and tested on several kind of environments (proc arch, kubernetes versions, crossplane versions, managed kubernetes versions, etc).
The release process embedded a testing workflow to ensure everything's developed is stable and tested on several kind of environments.

## Release

Expand Down
3 changes: 0 additions & 3 deletions docs/readthedocs/getting-started/cv.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
---
site:
url: germainlefebvre.fr

company:
name: Zatsit

Expand Down
8 changes: 8 additions & 0 deletions docs/readthedocs/themes/write-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ Which can be used in the template like this:
!!! note "Go template variable name"
Every key in the yaml file is capitalized in the Go template.
Even though the yaml file uses `person`, the Go template variable name is `Person`.

## Enable the watch feature

To enable the watch feature on CV Wonder, you have to inject an internal js script in the template. This script will automatically reload the page when the CV data or the Theme is updated.

```html
<script src="http://localhost:35729/livereload.js"></script>
```
5 changes: 2 additions & 3 deletions internal/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"fmt"
"log"

"github.com/germainlefebvre4/cvwonder/internal/cvrender"
"github.com/germainlefebvre4/cvwonder/internal/utils"

"github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus"
)

func (w *WatcherServices) ObserveFileEvents(renderService cvrender.RenderInterface, baseDirectory string, outputDirectory string, inputFilePath string, themeName string, exportFormat string) {
func (w *WatcherServices) ObserveFileEvents(baseDirectory string, outputDirectory string, inputFilePath string, themeName string, exportFormat string) {
// setup watcher
watcher, err := fsnotify.NewWatcher()
if err != nil {
Expand All @@ -31,7 +30,7 @@ func (w *WatcherServices) ObserveFileEvents(renderService cvrender.RenderInterfa
content, err := w.ParserService.ParseFile(inputFilePath)
utils.CheckError(err)

renderService.Render(content, baseDirectory, outputDirectory, inputFilePath, themeName, exportFormat)
w.RenderService.Render(content, baseDirectory, outputDirectory, inputFilePath, themeName, exportFormat)
utils.CheckError(err)
}
case err := <-watcher.Errors:
Expand Down
13 changes: 10 additions & 3 deletions internal/watcher/watcher_iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import (
)

type WatcherInterface interface {
ObserveFileEvents(renderService cvrender.RenderInterface, baseDirectory string, outputDirectory string, inputFilePath string, themeName string, exportFormat string)
ObserveFileEvents(baseDirectory string, outputDirectory string, inputFilePath string, themeName string, exportFormat string)
}

type WatcherServices struct {
ParserService cvparser.ParserInterface
RenderService cvrender.RenderInterface
}

func NewWatcherServices() (WatcherInterface, error) {
return &WatcherServices{}, nil
func NewWatcherServices(
parserService cvparser.ParserInterface,
renderService cvrender.RenderInterface,
) (WatcherInterface, error) {
return &WatcherServices{
ParserService: parserService,
RenderService: renderService,
}, nil
}

0 comments on commit e9fcfc4

Please sign in to comment.