Documentation
¶
Overview ¶
Package ogimage generates Open Graph images from Laravel Go page templates.
Index ¶
- Variables
- func HTML(content string, options ...Options) (template.HTML, error)
- func Hash(content string, options Options) string
- func ImageURL(value string) (template.HTML, error)
- type Actions
- type BrowsershotDriver
- type ClearCommand
- type CloudflareDriver
- type Config
- type Driver
- type DriverFunc
- type GenerateCommand
- type Metadata
- type Options
- type Package
- type Render
- type Screenshot
- type ScreenshotLayout
- type Service
- func (s *Service) DefaultInjectFallback(r *web.Request, source string) (string, error)
- func (s *Service) DefaultRenderScreenshot(ctx context.Context, source string) (string, error)
- func (s *Service) DefaultResponse(r *web.Request, filename string) *web.Response
- func (s *Service) Generate(ctx context.Context, filename string) error
- func (s *Service) GenerateForURL(ctx context.Context, pageURL string, format ...string) (string, error)
- func (s *Service) Metadata(ctx context.Context, hash string) (Metadata, bool, error)
- func (s *Service) Prepare(r *web.Request, source string) (string, error)
- func (s *Service) Response(r *web.Request) *web.Response
- func (s *Service) StoreMetadata(ctx context.Context, hash string, metadata Metadata) error
- func (s *Service) URL(hash, format string) string
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("ogimage: image metadata not found")
ErrNotFound means the filename is invalid or its page metadata is absent.
Functions ¶
func HTML ¶
HTML wraps already-rendered, trusted application HTML in an inert template. Escape untrusted text before passing it. The output is never compiled again.
Types ¶
type Actions ¶
type Actions struct {
Generate func(*web.Request, *Service, string) *web.Response
InjectFallback func(*web.Request, *Service, string) (string, error)
RenderScreenshot func(context.Context, *Service, string) (string, error)
}
Actions replace PHP's generate, fallback injection and screenshot rendering actions. The Default methods on Service can be called to decorate the built-in behavior.
type BrowsershotDriver ¶
type BrowsershotDriver struct {
Configure func(*browsershot.Browsershot)
}
BrowsershotDriver captures the live page preview with Node, Puppeteer and Chrome. Configure receives a fresh builder for each capture, after shared options apply.
func (BrowsershotDriver) Capture ¶
func (d BrowsershotDriver) Capture(ctx context.Context, s Screenshot) ([]byte, error)
type ClearCommand ¶
type ClearCommand struct{}
ClearCommand deletes files directly in the configured image directory.
func (*ClearCommand) Description ¶
func (*ClearCommand) Description() string
func (*ClearCommand) Name ¶
func (*ClearCommand) Name() string
type CloudflareDriver ¶
CloudflareDriver uses Cloudflare Browser Rendering without a local Chrome installation.
func (CloudflareDriver) Capture ¶
func (d CloudflareDriver) Capture(ctx context.Context, s Screenshot) ([]byte, error)
type Config ¶
type Config struct {
BaseURL string
Disk string
Path string
Width int
Height int
Format string
Quality int
PreviewParameter string
MaxAge time.Duration
MetadataTTL time.Duration
LockTimeout time.Duration
// RemoteDisk redirects image requests to the disk's public URL.
RemoteDisk bool
Driver Driver
ConfigureScreenshot func(*Screenshot)
Fallback func(*web.Request) (string, error)
ResolveURL func(*web.Request) (string, error)
Actions Actions
}
Config configures one application. Callbacks must be safe for concurrent use.
type Driver ¶
type Driver interface {
Capture(context.Context, Screenshot) ([]byte, error)
}
Driver takes a screenshot and returns encoded image bytes. Implementations must honor context cancellation and be safe for concurrent calls.
type DriverFunc ¶
type DriverFunc func(context.Context, Screenshot) ([]byte, error)
DriverFunc adapts a function to a custom screenshot driver.
func (DriverFunc) Capture ¶
func (f DriverFunc) Capture(ctx context.Context, s Screenshot) ([]byte, error)
type GenerateCommand ¶
type GenerateCommand struct{}
GenerateCommand pre-generates each trusted URL and continues after individual failures.
func (*GenerateCommand) Arguments ¶
func (*GenerateCommand) Arguments() []laravel.Argument
func (*GenerateCommand) Description ¶
func (*GenerateCommand) Description() string
func (*GenerateCommand) Name ¶
func (*GenerateCommand) Name() string
type Metadata ¶
type Metadata struct {
URL string `json:"url"`
Width int `json:"width"`
Height int `json:"height"`
}
Metadata is cached for Config.MetadataTTL unless cleared or evicted earlier.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package installs routes, web middleware, views and console commands.
type Render ¶
type Render struct{}
Render processes successful buffered HTML web responses, leaving streams and JSON untouched.
type Screenshot ¶
type Screenshot struct {
URL string
Width, Height int
Format string
Quality int
Scale float64
WaitUntil string
Delay time.Duration
}
Screenshot contains the resolved options after ConfigureScreenshot runs.
type ScreenshotLayout ¶
ScreenshotLayout is passed to the overridable og-image::screenshot view.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is immutable after registration and safe for concurrent requests.
func (*Service) DefaultInjectFallback ¶
DefaultInjectFallback adds a fallback template only when a body closing tag exists.
func (*Service) DefaultRenderScreenshot ¶
DefaultRenderScreenshot preserves the page's head and renders only template content.
func (*Service) DefaultResponse ¶
DefaultResponse generates missing images under a shared cache lock and serves them.
func (*Service) Generate ¶
Generate captures a known image once. Unknown names never trigger browser navigation.
func (*Service) GenerateForURL ¶
func (s *Service) GenerateForURL(ctx context.Context, pageURL string, format ...string) (string, error)
GenerateForURL fetches a trusted page and pre-generates its image. Never pass arbitrary visitor input. Fetching pages and browser navigation can reach private networks.
func (*Service) Prepare ¶
Prepare injects social tags and caches the page URL, or renders preview HTML. Only pass successful HTML page responses, never JSON, files or streams.
func (*Service) Response ¶
Response serves a validated filename using the configured generation action.
func (*Service) StoreMetadata ¶
StoreMetadata remembers the first page for content, without replacing earlier metadata.
