hugo: github.com/gohugoio/hugo/source Index | Files

package source

import "github.com/gohugoio/hugo/source"

Index

Package Files

dirs.go file.go filesystem.go inmemory.go lazy_file_reader.go

type ByteSource Uses

type ByteSource struct {
    Name    string
    Content []byte
}

ByteSource represents a source's name and content. It's currently only used for testing purposes.

func (*ByteSource) String Uses

func (b *ByteSource) String() string

type Dirs Uses

type Dirs struct {
    AbsStaticDirs []string
    // contains filtered or unexported fields
}

Dirs holds the source directories for a given build. In case where there are more than one of a kind, the order matters: It will be used to construct a union filesystem, so the right-most directory will "win" on duplicates. Typically, the theme version will be the first.

func NewDirs Uses

func NewDirs(fs *hugofs.Fs, cfg config.Provider, logger *jww.Notepad) (*Dirs, error)

NewDirs creates a new dirs with the given configuration and filesystem.

func (*Dirs) CreateStaticFs Uses

func (d *Dirs) CreateStaticFs() (afero.Fs, error)

CreateStaticFs will create a union filesystem with the static paths configured. Any missing directories will be logged as warnings.

func (*Dirs) IsStatic Uses

func (d *Dirs) IsStatic(filename string) bool

IsStatic returns whether the given filename is located in one of the static source dirs.

func (*Dirs) MakeStaticPathRelative Uses

func (d *Dirs) MakeStaticPathRelative(filename string) string

MakeStaticPathRelative creates a relative path from the given filename. It will return an empty string if the filename is not a member of dirs.

type File Uses

type File struct {
    Contents io.Reader
    // contains filtered or unexported fields
}

File represents a source content file. All paths are relative from the source directory base

func (*File) BaseFileName Uses

func (f *File) BaseFileName() string

BaseFileName is a filename without extension.

func (*File) Bytes Uses

func (f *File) Bytes() []byte

Bytes returns the file's content as a byte slice.

func (*File) Dir Uses

func (f *File) Dir() string

Dir gets the name of the directory that contains this file. The directory is relative to the content root.

func (*File) Ext Uses

func (f *File) Ext() string

Ext is an alias for Extension.

func (*File) Extension Uses

func (f *File) Extension() string

Extension gets the file extension, i.e "myblogpost.md" will return "md".

func (*File) Lang Uses

func (f *File) Lang() string

Lang for this page, if `Multilingual` is enabled on your site.

func (*File) LogicalName Uses

func (f *File) LogicalName() string

LogicalName is filename and extension of the file.

func (*File) Path Uses

func (f *File) Path() string

Path gets the relative path including file name and extension. The directory is relative to the content root.

func (*File) Section Uses

func (f *File) Section() string

Section is first directory below the content root.

func (*File) SetDir Uses

func (f *File) SetDir(dir string)

SetDir sets the relative directory where this file lives. TODO(bep) Get rid of this.

func (*File) String Uses

func (f *File) String() string

String returns the file's content as a string.

func (*File) TranslationBaseName Uses

func (f *File) TranslationBaseName() string

TranslationBaseName is a filename with no extension, not even the optional language extension part.

func (*File) UniqueID Uses

func (f *File) UniqueID() string

UniqueID is the MD5 hash of the file's path and is for most practical applications, Hugo content files being one of them, considered to be unique.

type Filesystem Uses

type Filesystem struct {
    Base       string
    AvoidPaths []string

    SourceSpec
    // contains filtered or unexported fields
}

func (*Filesystem) Files Uses

func (f *Filesystem) Files() []*File

func (*Filesystem) FilesByExts Uses

func (f *Filesystem) FilesByExts(exts ...string) []*File

func (*Filesystem) ShouldRead Uses

func (f *Filesystem) ShouldRead(filePath string, fi os.FileInfo) (bool, error)

type Input Uses

type Input interface {
    Files() []*File
}

type LazyFileReader Uses

type LazyFileReader struct {
    // contains filtered or unexported fields
}

LazyFileReader is an io.Reader implementation to postpone reading the file contents until it is really needed. It keeps filename and file contents once it is read.

func NewLazyFileReader Uses

func NewLazyFileReader(fs afero.Fs, filename string) (*LazyFileReader, error)

NewLazyFileReader creates and initializes a new LazyFileReader of filename. It checks whether the file can be opened. If it fails, it returns nil and an error.

func (*LazyFileReader) Filename Uses

func (l *LazyFileReader) Filename() string

Filename returns a file name which LazyFileReader keeps

func (*LazyFileReader) Read Uses

func (l *LazyFileReader) Read(p []byte) (n int, err error)

Read reads up to len(p) bytes from the LazyFileReader's file and copies them into p. It returns the number of bytes read and any error encountered. If the file is once read, it returns its contents from cache, doesn't re-read the file.

func (*LazyFileReader) Seek Uses

func (l *LazyFileReader) Seek(offset int64, whence int) (pos int64, err error)

Seek implements the io.Seeker interface. Once reader contents is consumed by Read, WriteTo etc, to read it again, it must be rewinded by this function

func (*LazyFileReader) WriteTo Uses

func (l *LazyFileReader) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes data to w until all the LazyFileReader's file contents is drained or an error occurs. If the file is once read, it just writes its read cache to w, doesn't re-read the file but this method itself doesn't try to keep the contents in cache.

type SourceSpec Uses

type SourceSpec struct {
    Cfg config.Provider
    Fs  *hugofs.Fs
    // contains filtered or unexported fields
}

SourceSpec abstracts language-specific file creation.

func NewSourceSpec Uses

func NewSourceSpec(cfg config.Provider, fs *hugofs.Fs) SourceSpec

NewSourceSpec initializes SourceSpec using languages from a given configuration.

func (SourceSpec) NewFile Uses

func (sp SourceSpec) NewFile(relpath string) *File

NewFile creates a new File pointer with the given relative path.

func (SourceSpec) NewFileFromAbs Uses

func (sp SourceSpec) NewFileFromAbs(base, fullpath string, content io.Reader) (f *File, err error)

NewFileFromAbs creates a new File pointer with the given full file path path and content.

func (SourceSpec) NewFileWithContents Uses

func (sp SourceSpec) NewFileWithContents(relpath string, content io.Reader) *File

NewFileWithContents creates a new File pointer with the given relative path and content. The language defaults to "en".

func (SourceSpec) NewFilesystem Uses

func (sp SourceSpec) NewFilesystem(base string, avoidPaths ...string) *Filesystem

Package source imports 16 packages (graph) and is imported by 20 packages. Updated 2017-11-19. Refresh now. Tools for package owners.