webpack

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: MIT Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasResponsiveExt

func HasResponsiveExt(originalSrc string) bool

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

func (w *Manifest) ManifestURL(key string) string

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

type ResponsiveImage struct {
	Src    string `json:"src"`
	SrcSet string `json:"srcSet"`
}

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) AssetsURL

func (w *Webpack) AssetsURL() string

AssetsURL returns the URL path prefix of all your assets

func (*Webpack) GeneratedAssetsPath

func (w *Webpack) GeneratedAssetsPath() string

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

func (w *Webpack) ManifestURL(key string) string

ManifestURL calls Manifest.ManifestURL

func (*Webpack) ReplaceResponsiveAttrs

func (w *Webpack) ReplaceResponsiveAttrs(srcPrefix, html string) string

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

func (w *Webpack) ResponsiveHTMLAttrs(originalSrc string) template.HTMLAttr

ResponsiveHTMLAttrs calls GetResponsiveImage and returns the html attr (img.src and img.srcset) representation of the *ResponsiveImage

func (*Webpack) TemplateFuncs

func (w *Webpack) TemplateFuncs() template.FuncMap

TemplateFuncs implements github.com/s12chung/gostatic/go/lib/router/html.Plugin

Jump to

Keyboard shortcuts

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