Documentation ¶
Overview ¶
Package webpack lets Go see into the generated asset paths, `Manifest.json`, and `images/responsive` folder of JSON files from Webpack.
Webpack struct implements github.com/s12chung/gostatic/go/lib/router/html.Plugin
Index ¶
- func HasResponsiveExt(originalSrc string) bool
- type Manifest
- type Responsive
- type ResponsiveImage
- type Settings
- type Webpack
- func (w *Webpack) AssetsURL() string
- func (w *Webpack) GeneratedAssetsPath() string
- func (w *Webpack) GetResponsiveImage(originalSrc string) *ResponsiveImage
- func (w *Webpack) ManifestURL(key string) string
- func (w *Webpack) ReplaceResponsiveAttrs(srcPrefix, html string) string
- func (w *Webpack) ResponsiveHTMLAttrs(originalSrc string) template.HTMLAttr
- func (w *Webpack) TemplateFuncs() template.FuncMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasResponsiveExt ¶
HasResponsiveExt returns true of the originalSrc's ext has responsive images
Types ¶
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
Manifest represents a Manifest file
func NewManifest ¶
func NewManifest(generatedPath, assetsFolder string, log logrus.FieldLogger) *Manifest
NewManifest returns a new instance of Manifest
func (*Manifest) ManifestURL ¶
ManifestURL returns the manifest URL of the file (so it returns hashed file paths that exist), given a file path key.
type Responsive ¶
type Responsive struct {
// contains filtered or unexported fields
}
Responsive handles the overview logic of responsive images.
func NewResponsive ¶
func NewResponsive(generatedPath, assetsFolder string, log logrus.FieldLogger) *Responsive
NewResponsive returns a new instance of Responsive
func (*Responsive) GetResponsiveImage ¶
func (r *Responsive) GetResponsiveImage(originalSrc string) *ResponsiveImage
GetResponsiveImage returns the ResponsiveImage of the given getResponsiveImage
type ResponsiveImage ¶
ResponsiveImage represents a ResponsiveImage
func (*ResponsiveImage) HTMLAttrs ¶
func (r *ResponsiveImage) HTMLAttrs() string
HTMLAttrs returns the HTML attributes of the ResponsiveImage for the <img> tag
func (*ResponsiveImage) PrependSrcPath ¶
func (r *ResponsiveImage) PrependSrcPath(prefix string, log logrus.FieldLogger)
PrependSrcPath prepends the given prefix to the Src and SrcSet of the ResponsiveImage
type Settings ¶
type Settings struct {
AssetsPath string `json:"assets_path,omitempty"`
}
Settings is the settings of this package
func DefaultSettings ¶
func DefaultSettings() *Settings
DefaultSettings returns the default settings of this package
type Webpack ¶
type Webpack struct {
// contains filtered or unexported fields
}
Webpack represents of a webpack generated setup
func NewWebpack ¶
func NewWebpack(generatedPath string, settings *Settings, log logrus.FieldLogger) *Webpack
NewWebpack returns a new instance of Webpack
func (*Webpack) GeneratedAssetsPath ¶
GeneratedAssetsPath returns the file path of the generated assets
func (*Webpack) GetResponsiveImage ¶
func (w *Webpack) GetResponsiveImage(originalSrc string) *ResponsiveImage
GetResponsiveImage returns the struct representation of a *ResponsiveImage given a originalSrc. originalSrc should give Webpack a filepath to the generated images folder.
If the src points to a non-responsive image, will return a *ResponsiveImage with src set as: - the result of using originalSrc as a key for webpack.ManifestURL - the given originalSrc
func (*Webpack) ManifestURL ¶
ManifestURL calls Manifest.ManifestURL
func (*Webpack) ReplaceResponsiveAttrs ¶
ReplaceResponsiveAttrs replaces the img.src HTML attrs, to responsive img.src and img.srcset attrs within the HTML string. It takes the existing img.src values as the originalSrc to call webpack.GetResponsiveImage.
You may add a srcPrefix to the img.src, so webpack.GetResponsiveImage can work.
func (*Webpack) ResponsiveHTMLAttrs ¶
ResponsiveHTMLAttrs calls GetResponsiveImage and returns the html attr (img.src and img.srcset) representation of the *ResponsiveImage
func (*Webpack) TemplateFuncs ¶
TemplateFuncs implements github.com/s12chung/gostatic/go/lib/router/html.Plugin