Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PostProcess for other than HTML #10269

Closed
rockerBOO opened this issue Sep 13, 2022 · 2 comments · Fixed by #10276
Closed

Support PostProcess for other than HTML #10269

rockerBOO opened this issue Sep 13, 2022 · 2 comments · Fixed by #10276
Assignees
Milestone

Comments

@rockerBOO
Copy link

rockerBOO commented Sep 13, 2022

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.102.3+extended linux/amd64 BuildDate=unknown

Does this issue reproduce with the latest release?

Yes

I'm trying to export a json list which includes minified hashed file paths and integrity. Thanks to some help from the discourse I have the following.

{{- $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 -}}

The issue is I want a .json file exported but if I do export/stylesheet.json in the last part it gets exported as the following.

[
  {
    "file": "fonts/kalam/stylesheet.css",
    "integrity": "__h_pp_l1_1_Data.Integrity__e=",
    "mediaType": "text/css",
    "target": "__h_pp_l1_1_RelPermalink__e="
  },
  {
    "file": "fonts/plex/font.css",
    "integrity": "__h_pp_l1_2_Data.Integrity__e=",
    "mediaType": "text/css",
    "target": "__h_pp_l1_2_RelPermalink__e="
  },
  {
    "file": "css/main2.css",
    "integrity": "__h_pp_l1_3_Data.Integrity__e=",
    "mediaType": "text/css",
    "target": "__h_pp_l1_3_RelPermalink__e="
  },
  {
    "file": "css/main-nav-bar.css",
    "integrity": "__h_pp_l1_4_Data.Integrity__e=",
    "mediaType": "text/css",
    "target": "__h_pp_l1_4_RelPermalink__e="
  }
]

Putting it as export/stylesheet.json.html exports it like

[
  {
    "file": "fonts/kalam/stylesheet.css",
    "integrity": "sha384-heMu9jHo5hB1ouw+RXbp8qkdluBNx6pMPK7Jpgkd9zKcxHcZqoP1Ouh+fP/k4W8q",
    "mediaType": "text/css",
    "target": "/fonts/kalam/stylesheet.min.85e32ef631e8e61075a2ec3e4576e9f2a91d96e04dc7aa4c3caec9a6091df7329cc47719aa83f53ae87e7cffe4e16f2a.css"
  },
  {
    "file": "fonts/plex/font.css",
    "integrity": "sha384-Q9Y7k8u6w97eFtjK6q5zuQ5F9sw6fCGpsj2POuacWoBdDgMHTSKcot98QRqN50cf",
    "mediaType": "text/css",
    "target": "/fonts/plex/font.min.43d63b93cbbac3dede16d8caeaae73b90e45f6cc3a7c21a9b23d8f3ae69c5a805d0e03074d229ca2df7c411a8de7471f.css"
  },
  {
    "file": "css/main2.css",
    "integrity": "sha384-FSCthKNDMOyBvZXMJ3GBgYRGhN0jf5NjWsF3knZKxtKYx5HJtTqYy5uONpokomnU",
    "mediaType": "text/css",
    "target": "/css/main2.min.1520ad84a34330ec81bd95cc27718181844684dd237f93635ac17792764ac6d298c791c9b53a98cb9b8e369a24a269d4.css"
  },
  {
    "file": "css/main-nav-bar.css",
    "integrity": "sha384-NsBVxX8l5JHeeK30przJ835+wvUGrateSt88mozwujjBcDABfkstnhhzZpumtUYZ",
    "mediaType": "text/css",
    "target": "/css/main-nav-bar.min.36c055c57f25e491de78adf4a6bcc9f37e7ec2f506adab5e4adf3c9a8cf0ba38c17030017e4b2d9e1873669ba6b54619.css"
  }
]

Same thing happens for export/stylesheet.json.json

Expectation

I'd expect publishing as export/stylesheet.json would export the values and not a "placeholder" variables.


Thank you

@bep
Copy link
Member

bep commented Sep 14, 2022

Hey, I was about to say that this isn't fixable, but I guess it is. I suspect we have a hardcoded thing where we only consider HTML output format in the replacement step.

This i a reminder that we have issue #8086 -- which would make all of this much nicer.

@bep bep added this to the v0.103.0 milestone Sep 14, 2022
@bep bep changed the title Publish json from resources.FromString to .json file outputs placeholder values Allow PostProcess of other output formats than HTML Sep 14, 2022
@bep bep self-assigned this Sep 14, 2022
@bep bep changed the title Allow PostProcess of other output formats than HTML Support PostProcess for other than HTML Sep 14, 2022
bep added a commit to bep/hugo that referenced this issue Sep 14, 2022
bep added a commit to bep/hugo that referenced this issue Sep 14, 2022
bep added a commit to bep/hugo that referenced this issue Sep 14, 2022
bep added a commit to bep/hugo that referenced this issue Sep 14, 2022
bep added a commit to bep/hugo that referenced this issue Sep 14, 2022
bep added a commit that referenced this issue Sep 14, 2022
bep added a commit that referenced this issue Sep 14, 2022
@github-actions
Copy link

github-actions bot commented Oct 6, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants