tryck

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tryck is the public entry point of the tryck command line. A custom binary that compiles in extra plugins is a single call:

func main() { tryck.Main(&myplugin.Plugin{}) }

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(plugins ...plugin.Plugin)

Main runs the tryck command line with plugins compiled in next to the built-ins, and exits. A custom binary's main is one call:

func main() { tryck.Main(&myplugin.Plugin{}) }

Each plugin value is reused for every build, including each rebuild in tryck dev, so it should reset per-build state in Init. OnPageParsed and OnPageRendered run on several pages at once.

Example

A custom tryck binary is one call. It has every tryck command, with the plugins running next to the built-ins.

package main

import (
	"fmt"

	"github.com/Pinta365/tryck/pkg/plugin"
	"github.com/Pinta365/tryck/pkg/tryck"
)

// stamp adds a build stamp to the output.
type stamp struct{}

func (stamp) Name() string                               { return "stamp" }
func (stamp) Init(map[string]any, plugin.SiteInfo) error { return nil }
func (stamp) OnBuildComplete(s plugin.SiteView, out plugin.Outputs) error {
	return out.Add("stamp.txt", []byte(fmt.Sprintf("%d pages\n", len(s.Pages()))))
}

func main() {
	tryck.Main(stamp{})
}

func Run

func Run(args []string, stdout, stderr io.Writer, plugins ...plugin.Plugin) int

Run runs the command line with args (without the program name) and returns the exit code: 0 ok, 1 build errors, 2 usage or config errors.

Example

Run runs the command line in the current process and returns the exit code, which makes a plugin easy to test.

package main

import (
	"fmt"
	"io"
	"os"
	"path/filepath"

	"github.com/Pinta365/tryck/pkg/plugin"
	"github.com/Pinta365/tryck/pkg/tryck"
)

// stamp adds a build stamp to the output.
type stamp struct{}

func (stamp) Name() string                               { return "stamp" }
func (stamp) Init(map[string]any, plugin.SiteInfo) error { return nil }
func (stamp) OnBuildComplete(s plugin.SiteView, out plugin.Outputs) error {
	return out.Add("stamp.txt", []byte(fmt.Sprintf("%d pages\n", len(s.Pages()))))
}

func main() {
	dir, _ := os.MkdirTemp("", "site")
	defer os.RemoveAll(dir)
	config := filepath.Join(dir, "tryck.config.yaml")
	_ = os.WriteFile(config, []byte("site:\n  baseUrl: https://example.com/\n"), 0o644)
	_ = os.MkdirAll(filepath.Join(dir, "content"), 0o755)
	_ = os.WriteFile(filepath.Join(dir, "content", "index.md"), []byte("# Home\n"), 0o644)

	code := tryck.Run([]string{"build", "--config", config}, io.Discard, os.Stderr, stamp{})
	out, _ := os.ReadFile(filepath.Join(dir, "dist", "stamp.txt"))
	fmt.Printf("exit code %d, %s", code, out)
}
Output:
exit code 0, 1 pages

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL