I’m looking to clean up my codebase. Is there a way to find any unreferenced or unused templates or content?
You can run
hugo --templateMetrics
And then look at the “count” column for each template
2 Likes
Thanks, that was really helpful! Looks like I don’t have any dead templates:
$ hugo --templateMetrics
Building sites …
Template Metrics:
cumulative average maximum
duration duration duration count template
---------- -------- -------- ----- --------
309.752533ms 1.541057ms 32.860091ms 201 post/single.html
237.765723ms 849.163µs 9.717949ms 280 partials/header.html
115.90521ms 1.783157ms 37.745882ms 65 _internal/_default/rss.xml
101.271017ms 1.716457ms 12.839154ms 59 taxonomy/tag.html
50.623538ms 180.798µs 3.5034ms 280 partials/footer.html
45.668973ms 3.805747ms 24.1706ms 12 _internal/shortcodes/highlight.html
34.676805ms 172.521µs 909.857µs 201 partials/prev_next_post.html
24.933704ms 24.933704ms 24.933704ms 1 post/list.html
19.276983ms 4.819245ms 12.849978ms 4 _default/list.html
15.248773ms 1.270731ms 3.439958ms 12 _default/single.html
14.679648ms 73.033µs 681.192µs 201 partials/post_meta.html
12.439829ms 12.439829ms 12.439829ms 1 index.html
9.312912ms 9.312912ms 9.312912ms 1 _internal/_default/sitemap.xml
7.737017ms 38.302µs 457.802µs 202 _default/li.html
6.791813ms 33.79µs 192.307µs 201 partials/disqus.html
791.299µs 791.299µs 791.299µs 1 post/plain.html
737.725µs 2.634µs 236.807µs 280 partials/googletagmanager.html
681.534µs 2.434µs 177.452µs 280 partials/nav.html
529.389µs 264.694µs 475.454µs 2 _internal/shortcodes/youtube.html
474.124µs 474.124µs 474.124µs 1 404.html
379.75µs 189.875µs 363.349µs 2 _internal/shortcodes/gist.html
189.194µs 47.298µs 140.301µs 4 partials/masthead.html
168.993µs 168.993µs 168.993µs 1 partials/contact.html
11.062µs 11.062µs 11.062µs 1 _default/robots.txt
| EN
+------------------+-----+
Pages | 346
Paginator pages | 0
Non-page files | 583
Static files | 49
Processed images | 0
Aliases | 0
Sitemaps | 1
Cleaned | 0
Total in 355 ms
2 Likes