source

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2017 License: Apache-2.0 Imports: 16 Imported by: 194

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSource

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

func (b *ByteSource) String() string

type File

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

func (f *File) BaseFileName() string

BaseFileName is a filename without extension.

func (*File) Bytes

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

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

func (*File) Dir

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

func (f *File) Ext() string

Ext is an alias for Extension.

func (*File) Extension

func (f *File) Extension() string

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

func (*File) Lang

func (f *File) Lang() string

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

func (*File) LogicalName

func (f *File) LogicalName() string

LogicalName is filename and extension of the file.

func (*File) Path

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

func (f *File) Section() string

Section is first directory below the content root.

func (*File) SetDir

func (f *File) SetDir(dir string)

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

func (*File) String

func (f *File) String() string

String returns the file's content as a string.

func (*File) TranslationBaseName

func (f *File) TranslationBaseName() string

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

func (*File) UniqueID

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

type Filesystem struct {
	Base       string
	AvoidPaths []string

	SourceSpec
	// contains filtered or unexported fields
}

func (*Filesystem) Files

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

func (*Filesystem) FilesByExts

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

func (*Filesystem) ShouldRead added in v0.20.4

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

type Input

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

type LazyFileReader

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

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

func (l *LazyFileReader) Filename() string

Filename returns a file name which LazyFileReader keeps

func (*LazyFileReader) Read

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

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

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 added in v0.20.1

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

SourceSpec abstracts language-specific file creation.

func NewSourceSpec added in v0.20.1

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

NewSourceSpec initializes SourceSpec using languages from a given configuration.

func (SourceSpec) NewFile added in v0.20.1

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

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

func (SourceSpec) NewFileFromAbs added in v0.20.1

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 added in v0.20.1

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 added in v0.20.1

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

Jump to

Keyboard shortcuts

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