# Export minification and fingerprint hashes/filenames

**URL:** <https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517>\
**Category:** support\
**Tags:** pipes\
**Created:** [September 13, 2022, 6:32pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517 "2022-09-13T18:32:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rockerBOO](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rockerboo/32/17754_2.png) [@rockerBOO](https://discourse.gohugo.io/u/rockerBOO)\
**Post date:** [September 13, 2022, 6:32pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517/1 "2022-09-13T18:32:18Z")

</div>

I am currently trying to extract minification and fingerprint details during the build process to be used in other platforms. For example I want to include the minified files, including the fingerprint in adjacent properties. I want to be able to export these details to a json file or some other file to be used when building other applications in a monorepo.

```auto
<link
  rel="stylesheet"
  href="/css/main2.min.3e5c9b5cc2ff2e10f72210c82a941ac5968c57e63ef53ace839d3ba01bc552cf.css"
  integrity="sha256-PlybXML/LhD3IhDIKpQaxZaMV+Y+9TrOg507oBvFUs8="
/>

```

And my template with pipes looks like this

```auto
{{ $css := resources.Get "css/main2.css" }}
{{ $css = $css | resources.PostCSS }}
{{ if hugo.IsProduction }}
	{{ $css = $css | minify | resources.PostProcess | fingerprint "sha384" }}
{{ end }}

<link
  rel="stylesheet"
  href="{{ $css.Permalink }}"
  integrity="{{ $css.Data.Integrity }}"
/>

```

Is there a suggested way to do this? Do I need to make a custom pipe that can take the “$css” variable and extract them out?

Ideally I’d create a json file with a list of original files and their minify/fingerprint details. There are files like `resources/_gen/assets/css/main2.css_....json` but they include the minified url and fingerprint, but this is hard to extract programmatically as the filename includes hashed details in it.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [September 13, 2022, 7:07pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517/2 "2022-09-13T19:07:32Z")

</div>

Please provide an example of the desired JSON file.

---

<div class="post-metadata">

**Author:** ![rockerBOO](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rockerboo/32/17754_2.png) [@rockerBOO](https://discourse.gohugo.io/u/rockerBOO)\
**Post date:** [September 13, 2022, 7:17pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517/3 "2022-09-13T19:17:13Z")

</div>

Lets say something like this.

```auto
[{ "target": "css/main2.css", "hash": "3e5c9b5cc2ff2e10f72210c82a941ac5968c57e63ef53ace839d3ba01bc552cf", "integrity": "sha256-PlybXML/LhD3IhDIKpQaxZaMV+Y+9TrOg507oBvFUs8=" }]

```

In my resources/\_gen I have files like `main2.css_53d8db2e382030cdec351f02c8b70385.json` but I have currently 5 different of these types of files (meaning the different hashes after the css filename).

```auto
{"Target":"css/main2.min.3e5c9b5cc2ff2e10f72210c82a941ac5968c57e63ef53ace839d3ba01bc552cf.css","MediaType":"text/css","Data":{"Integrity":"sha256-PlybXML/LhD3IhDIKpQaxZaMV+Y+9TrOg507oBvFUs8="}}

```

If I were to use a file like this, how do I know which one is the current one? It seems new ones are created but I am not sure when they are made, and if I need “older” ones of these files to continue to exist.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [September 13, 2022, 7:34pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517/4 "2022-09-13T19:34:27Z")

</div>

layouts/\_default/baseof.html

```nohighlight
{{/* Build the link element */}}
{{ $css := resources.Get "css/main2.css" }}
{{ $css = $css | resources.PostCSS }}
{{ if hugo.IsProduction }}
  {{ $css = $css | minify | fingerprint "sha256" | resources.PostProcess }}
{{ end }}
<link rel="stylesheet" href="{{ $css.RelPermalink }}" integrity="{{ $css.Data.Integrity }}">

{{/* Create a json file in /public/export/stylesheet.json.html */}}
{{ $m := dict
  "Target" $css.RelPermalink
  "MediaType" "text/css"
  "Data" (dict
    "Integrity" $css.Data.Integrity
  )
}}
{{ (jsonify (dict "indent" " ") $m | resources.FromString "export/stylesheet.json.html").Publish }}

```

public/export/stylesheet.json.html

```json
{
  "Data": {
    "Integrity": "sha256-FcQqt3aNlV7AZnGV4zkQRVeCeJOxbMPnQSx258L803E="
  },
  "MediaType": "text/css",
  "Target": "/css/main2.min.15c42ab7768d955ec0667195e339104557827893b16cc3e7412c76e7c2fcd371.css"
}

```

If you try to remove the “html” extension from the exported filename, you’ll get what look like placeholders instead of data. Maybe a bug; not sure.

---

<div class="post-metadata">

**Author:** ![rockerBOO](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rockerboo/32/17754_2.png) [@rockerBOO](https://discourse.gohugo.io/u/rockerBOO)\
**Post date:** [September 13, 2022, 7:49pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517/5 "2022-09-13T19:49:36Z")

</div>

This looks great! Thanks for taking the time to help.

---

<div class="post-metadata">

**Author:** ![rockerBOO](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rockerboo/32/17754_2.png) [@rockerBOO](https://discourse.gohugo.io/u/rockerBOO)\
**Post date:** [September 13, 2022, 10:14pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517/6 "2022-09-13T22:14:48Z")

</div>

Ultimately went with this if anyone wants it. Composes all the css files in the slice together into the export with their target, file, and integrity.

```auto
{{- $cssFiles := slice "fonts/kalam/stylesheet.css" "fonts/plex/font.css" "css/main2.css" "css/main-nav-bar.css" -}}
{{- $exported := slice -}}
{{- range $cssFiles -}} 
	{{- $css := resources.Get . -}}
	{{- $css = $css | resources.PostCSS -}}
	{{- if hugo.IsProduction -}}
		{{- $css = $css | minify | fingerprint "sha384"| resources.PostProcess -}}
	{{- end -}}

	{{- $m := dict
			"file" .
			"target" $css.RelPermalink
			"mediaType" "text/css"
			"integrity" $css.Data.Integrity
	-}}
      {{- $exported = $exported | append $m -}}

	<link
		rel="stylesheet"
		href="{{ $css.Permalink }}"
		integrity="{{ $css.Data.Integrity }}"
	/>
{{- end -}}

{{- (jsonify (dict "indent" " ") $exported | resources.FromString "export/stylesheet.json.html").Publish -}}

```

Tried a few options for the export, along the lines of the `.html` thing you were saying. Going to make a bug report about it to figure out why that’s the case. I can work around the `.html` thing for now.

Thanks again.

---

<div class="post-metadata">

**Author:** ![rockerBOO](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rockerboo/32/17754_2.png) [@rockerBOO](https://discourse.gohugo.io/u/rockerBOO)\
**Post date:** [September 14, 2022, 5:46pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517/8 "2022-09-14T17:46:27Z")

</div>

[Support PostProcess for other than HTML · Issue #10269 · gohugoio/hugo · GitHub](https://github.com/gohugoio/hugo/issues/10269) bug reported and reportedly resolved.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [September 16, 2022, 5:46pm UTC](https://discourse.gohugo.io/t/export-minification-and-fingerprint-hashes-filenames/40517/9 "2022-09-16T17:46:57Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
