hugo

package module
v0.0.0-...-a55c33e Latest Latest
Warning

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

Go to latest
Published: May 2, 2017 License: Apache-2.0 Imports: 26 Imported by: 0

README

hugo - a caddy plugin

Build community Go Report Card

hugo fills the gap between Hugo and the browser. Hugo is an easy and fast static website generator. This plugin fills the gap between Hugo and the end-user, providing you an web interface to manage the whole website.

Using this plugin, you won't need to have your own computer to edit posts, neither regenerate your static website, because you can do all of that just through your browser.

Requirements: you need to have the hugo executable in your PATH. You can download it from its official page.

Syntax
hugo [directory] [admin] {
    clean_public    [true|false]
    before_publish  command
    after_publish   command
    flag            name  [value]
    # other file manager compatible options
}

All of the options above are optional.

  • directory is the folder where the commands are going to be executed. By default, it is the current working directory. Default: ./.
  • admin is the path where you will find your administration interface. Default: /admin.
  • clean_public sets if the public folder should be removed before generating the website again. Default: true.
  • before_publish and after_publish allow you to set a custom command to be executed before publishing and after publishing a post/page. The placeholder {path} can be used and it will be replaced by the file path.
  • name refers to the Hugo available flags. Please use their long form without -- in the beginning. If no value is set, it will be evaluated as true.

In spite of these options, you can also use the filemanager so you can have more control about what can be acceded, the permissions of each user, and so on.

This directive should be used with root, basicauth and errors middleware to have the best experience. See the examples to know more.

Examples

If you don't already have an Hugo website, don't worry. This plugin will auto-generate it for you. But that's not everything. It is recommended that you take a look at Hugo documentation to learn more about themes, content types, and so on.

A simple Caddyfile to use with Hugo static website generator:

root      public           # the folder where Hugo generates the website
basicauth /admin user pass # protect the admin area using HTTP basic auth
hugo                       # enable the admin panel
Screenshots

capture 2 3 4

Documentation

Overview

Package hugo makes the bridge between the static website generator Hugo and the webserver Caddy, also providing an administrative user interface.

Index

Constants

View Source
const (
	AssetsURL    = "/_hugointernal"
	HugoNotFound = "It seems that you don't have 'hugo' on your PATH."
)

AssetsURL is the base url for the assets

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func RunHugo

func RunHugo(c *Config, force bool)

RunHugo is used to run the static website generator

Types

type Config

type Config struct {
	Public        string   // Public content path
	Root          string   // Hugo files path
	Hugo          string   // Hugo executable location
	Styles        string   // Admin styles path
	Args          []string // Hugo arguments
	BaseURL       string   // BaseURL of admin interface
	WebDavURL     string
	CleanPublic   bool
	AllowPublish  bool
	BeforePublish config.CommandFunc
	AfterPublish  config.CommandFunc
}

Config is a configuration for managing a particular hugo website.

type Hugo

type Hugo struct {
	Next        httpserver.Handler
	Config      *Config
	FileManager *filemanager.FileManager
}

Hugo is hugo

func (Hugo) Schedule

func (h Hugo) Schedule(w http.ResponseWriter, r *http.Request) (int, error)

Schedule schedules a post to be published later

func (Hugo) ServeHTTP

func (h Hugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.

Directories

Path Synopsis
utils

Jump to

Keyboard shortcuts

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