Hugoで一度publishしてしまったファイルをデプロイ時に消す

 2020-2-4 |  2020-5-14 |  3 min read


この記事は、1年間更新されておりません。

はじめに

hugoでデプロイする際に、よくミスって不要記事を publish してしまうことがあります。 その後再度公開を行うと、出力元のフォルダからは消えているのにもかかわらず残り続けます。

今回はそれの解決を行いました。
(今までは public 以下をスクリプトで消してた…)

TL;DR

  • hugo --cleanDestinationDirでおk

How to

ほぼほぼ TL;DR で終わっちゃってますが、個人的に TL;DR がある記事のほうが手っ取り早く答えを見つけられると思っているので記載してます。
ググってもあんまり情報がなかったので、こういうときはとりあえず、help を見ようということで見たら乗ってました ✌️
以下がhugo server -hの内容です(Version : Hugo Static Site Generator v0.58.3)。該当箇所は一応矢印で強調してます。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Hugo provides its own webserver which builds and serves the site.
While hugo server is high performance, it is a webserver with limited options.
Many run it in production, but the standard behavior is for people to use it
in development and use a more full featured server such as Nginx or Caddy.

'hugo server' will avoid writing the rendered and served content to disk,
preferring to store it in memory.

By default hugo will also watch your files for any changes you make and
automatically rebuild the site. It will then live reload any open browser pages
and push the latest content to them. As most Hugo sites are built in a fraction
of a second, you will be able to save and see your changes nearly instantly.

Usage:
  hugo server [flags]

Aliases:
  server, serve

Flags:
      --appendPort             append port to baseURL (default true)
  -b, --baseURL string         hostname (and path) to the root, e.g. http://spf13.com/
      --bind string            interface to which the server will bind (default "127.0.0.1")
  -D, --buildDrafts            include content marked as draft
  -E, --buildExpired           include expired content
  -F, --buildFuture            include content with publishdate in the future
      --cacheDir string        filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/
## ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️
      --cleanDestinationDir    remove files from destination not found in static directories
## ⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
  -c, --contentDir string      filesystem path to content directory
  -d, --destination string     filesystem path to write files to
      --disableBrowserError    do not show build errors in the browser
      --disableFastRender      enables full re-renders on changes
      --disableKinds strings   disable different kind of pages (home, RSS etc.)
      --disableLiveReload      watch without enabling live browser reload on rebuild
      --enableGitInfo          add Git revision, date and author info to the pages
      --forceSyncStatic        copy all files when static is changed.
      --gc                     enable to run some cleanup tasks (remove unused cache files) after
 the build
  -h, --help                   help for server
      --i18n-warnings          print missing translations
      --ignoreCache            ignores the cache directory
  -l, --layoutDir string       filesystem path to layout directory
      --liveReloadPort int     port for live reloading (i.e. 443 in HTTPS proxy situations) (defa
ult -1)
      --meminterval string     interval to poll memory usage (requires --memstats), valid time un
its are "ns", "us" (or "µs"), "ms", "s", "m", "h". (default "100ms")
      --memstats string        log memory usage to this file
      --minify                 minify any supported output format (HTML, XML etc.)
      --navigateToChanged      navigate to changed content file on live browser reload
      --noChmod                don't sync permission mode of files
      --noHTTPCache            prevent HTTP caching
      --noTimes                don't sync modification time of files
      --path-warnings          print warnings on duplicate target paths etc.
  -p, --port int               port on which the server will listen (default 1313)
      --renderToDisk           render to Destination path (default is render to memory & serve from there)
      --templateMetrics        display metrics about template executions
      --templateMetricsHints   calculate some improvement hints when combined with --templateMetrics
  -t, --theme strings          themes to use (located in /themes/THEMENAME/)
      --trace file             write trace to file (not useful in general)
  -w, --watch                  watch filesystem for changes and recreate as needed (default true)

Global Flags:
      --config string        config file (default is path/config.yaml|json|toml)
      --configDir string     config dir (default "config")
      --debug                debug output
  -e, --environment string   build environment
      --ignoreVendor         ignores any _vendor directory
      --log                  enable Logging
      --logFile string       log File path (if set, logging enabled automatically)
      --quiet                build in quiet mode
  -s, --source string        filesystem path to read files relative from
      --themesDir string     filesystem path to themes directory
  -v, --verbose              verbose output
      --verboseLog           verbose logging

一応該当箇所の日本語訳も書いておくと、
「スタティックなディレクトリにはないやつを出力先フォルダから消すでー」
といった感じです。そのまんまですね。

さいごに

ちゃんと、公式の、ドキュメントは、読もう 📔

参考


このエントリーをはてなブックマークに追加

comments powered by Disqus

Tags

Hugo | 7 AWS | 5 git | 5 Setting | 5 VSCode | 4 JavaScript | 3 ci | 3 css | 3 intellij | 3 markdown | 2 Homebrew | 2 技術書典7 | 2 積本処理 | 2 kaspersky | 2 SpringBoot | 2 keyboard | 2 Route53 | 2 日本語 | 2 windows | 2 Docker | 2 iCloud | 2 poem | 2 command | 2 Terminal | 2 書き方 | 2 github-actions | 2 Extention | 2 webpack | 2 RubyOnRails | 1 Utility | 1 運用 | 1 Eclipse | 1 chrome | 1 book | 1 Front | 1 scoop | 1 Tech | 1 RaspberryPi | 1 Ruby | 1 diff | 1 Extension | 1 zsh | 1 study | 1 yarn | 1 brunch | 1 Marp | 1 security | 1 docsify | 1 github-action | 1 PowerShell | 1




Archives

2020 (31)
2019 (22)
2017 (1)
2016 (3)