Hugo Modules

Матеріал з Wiki.Zina
Версія від 11:44, 22 березня 2020, створена Romych (обговорення | внесок)
(різн.) ← Попередня версія | Поточна версія (різн.) | Новіша версія → (різн.)
Перейти до навігації Перейти до пошуку

←Hugo

Работает плохо. Ждем, когда появится проверенная инструкция.

Кеш модулей

[ред. | ред. код]

При скачивании модулей они сохраняются в кеш /tmp/hugo_cache.

Путь к нему можно узнать так:

printenv | grep hugo
OLDPWD=/tmp/hugo_cache

Подробнее: https://gohugo.io/getting-started/configuration/#configure-file-caches

hugo-mod-bootstrap-scss-v4

[ред. | ред. код]

Инициализируем модуль:

hugo mod init github.com/gohugoio/hugo-mod-bootstrap-scss-v4

Добавим в config.toml:

[module]
[[module.imports]]
path = "github.com/gohugoio/hugo-mod-bootstrap-scss-v4"

Запустим Hugo и проверим кеш — там появится файл:

/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/gohugoio/hugo-bootstrap-scss-v4@v0.0.0-20200224171633-fc89315b7997/assets/scss/bootstrap/_vendor/_rfs.scss

Создадим папку:

mkdir -p assets/scss/bootstrap

Создадим файл стилей и в нем импортируем стили Bootstrap:

vim assets/scss/main.scss
@import "bootstrap/bootstrap";
$not-so-white: FloralWhite;
body {
  background-color: $not-so-white;
}

Подключите компиляцию CSS в основной шаблон layouts/_default/baseof.html:

  {{ $style := resources.Get "scss/main.scss" | toCSS }}
  <link rel="stylesheet" href="{{ $style.RelPermalink }}">

bep/my-modular-site

[ред. | ред. код]

На примере https://github.com/bep/my-modular-site

hugo mod init github.com/bep/my-modular-site

После запуска Hugo будут скачаны все модули, указанные в config.toml:

[[module.imports]]
    path="github.com/bep/hugotestmods/mymounts"
    disabled=false
[[module.imports.mounts]]
    source="myassets/subfolder"
    target="assets/images"
[[module.imports.mounts]]
    source="mydata/subfolder"
    target="data/datakey"
[[module.imports]]
    path="github.com/bep/hugotestmods/mypartials"
    disable=false
[[module.imports]]
    path="github.com/spf13/hyde"
    disable=false
[[module.imports]]
    path="github.com/bep/hugo-fresh"
    disable=true   
[[module.imports]]
    path="in-themesdir"

Пример монтирования

[ред. | ред. код]

https://github.com/bep/hugotestmods/tree/master/mypartials/static/images — это папка с картинками

Импортируется как модуль здесь:

[module]
[[module.imports]]
    path="github.com/bep/hugotestmods/mypartials"

Загружается сюда:

/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/bep/hugotestmods/mypartials@v1.0.7/static/images$ 

Монтируется сюда (виртуально):

static/images

Создание собственного модуля

[ред. | ред. код]

Создадим модуль, который будет монтировать произвольный репозиторий GitHub.

Добавим в config.toml строки:

[module]
 [[module.imports]]
   path = "github.com/twbs/bootstrap"

Инициализируем модуль:

hugo mod init test-bootstrap

Будет создан файл go.mod.

Ссылки

[ред. | ред. код]