Gozer — быстрый и простой генератор статических сайтов, написанный на Golang.
Примеры веб-сайтов, использующих Gozer:
Вы можете установить Gozer, сначала установив компилятор Go, а затем запустив:
go install git.sr.ht/~dvko/gozer@latest Запустите gozer new , чтобы быстро создать пустую структуру каталогов.
├── config.toml # Configuration file
├── content # Posts and pages
│ └── index.md
├── public # Static files
└── templates # Template files
└── default.html Затем запустите gozer build , чтобы создать сайт.
Любые файлы Markdown, помещенные в ваш каталог content/ , приведут к появлению HTML-страницы в вашем каталоге сборки после запуска gozer build .
Например:
content/index.md создает файл build/index.html , чтобы он был доступен через HTTP по адресу /content/about.md создает файл build/about/index.html , который доступен через HTTP по адресу /about/ . Запустите gozer без аргументов, чтобы просмотреть текст справки.
Gozer - a fast & simple static site generator
Usage: gozer [OPTIONS] <COMMAND>
Commands:
build Deletes the output directory if there is one and builds the site
serve Builds the site and starts an HTTP server on http://localhost:8080
new Creates a new site structure in the given directory
Options:
-r, --root <ROOT> Directory to use as root of project (default: .)
-c, --config <CONFIG> Path to configuration file (default: config.toml)
Каждый файл в вашем каталоге content/ должен заканчиваться на .md и иметь заголовок TOML, определяющий заголовок страницы:
+++
title = " My page title "
+++
Page content here. Шаблон по умолчанию для каждой страницы — default.html . Вы можете переопределить его, установив переменную template во вступительной части.
+++
title = " My page title "
template = " special-page.html "
+++
Page content here. Шаблоны основаны на стандартном пакете Go html/template , поэтому вы можете использовать все действия, описанные здесь.
Каждый шаблон получает следующий набор переменных:
Pages # Slice of all pages in the site
Posts # Slice of all posts in the site (any page with a date in the filename)
Site # Global site properties: Url, Title
Page # The current page: Title, Permalink, UrlPath, DatePublished, DateModified
Title # The current page title, shorthand for Page.Title
Content # The current page's HTML content.
Переменная Page является экземпляром объекта ниже:
type Page struct {
// Title of this page
Title string
// Template this page uses for rendering. Defaults to "default.html".
Template string
// Time this page was published (parsed from file name).
DatePublished time.Time
// Time this page was last modified on the filesystem.
DateModified time.Time
// The full URL to this page, including the site URL.
Permalink string
// URL path for this page, relative to site URL
UrlPath string
// Path to source file for this page, relative to content root
Filepath string
}
Чтобы отобразить список из 5 последних сообщений:
{{ range (slice .Posts 0 5) }}
<a href="{{ .Permalink }}">{{ .Title }}</a> <small>{{ .DatePublished.Format "Jan 02, 2006" }}</small><br />
{{ end }}
Разработка Gozer происходит на Sourcehut. Патчи принимаются по электронной почте.
Gozer имеет открытый исходный код под лицензией MIT.