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

Hugo Pipes: Add post-render transformation support #5632

Open
bep opened this issue Jan 23, 2019 · 5 comments
Open

Hugo Pipes: Add post-render transformation support #5632

bep opened this issue Jan 23, 2019 · 5 comments
Milestone

Comments

@bep
Copy link
Member

bep commented Jan 23, 2019

@regisphilibert posted this link https://github.com/client9/csstool the forum. It strips unused CSS rules from a CSS.

I had a look at it and thought initially that it would be hard to add to the current Hugo Pipes, as the current transformers (PostCSS, SCSS etc.) does not have the information needed (e.g. public/**/*.html) for something like "CSS filtering" to work.

But we can, of course, add a concept of "delayed transformations" to Hugo pipes, so one could do something like:

{{ $css := resources.Get "scss/main.scss" | toSCSS | minify | css.Cut "**/*.html" | fingerprint }}

With the above, we delay the execution until the rendered content is available.

Note that the new namings in the above is just dropped in there without too much thought. The above would typically be a "production only" thing, as I suspect it would take more than some milliseconds to run.

@bep bep added this to the v0.55 milestone Jan 23, 2019
@bep bep changed the title Hugo Pipes: Add post-render publishing support Hugo Pipes: Add post-render transformation support Jan 23, 2019
@regisphilibert
Copy link
Member

Its awesome you're adding this to the roadmap. Couple of things:

User will need to specify (as parameter) a slice of classnames to whitelist as some classes may be added by javascript and not clearly identifiable from html files. (not sure csstools has that ability yet, but should be trivial for its author to add...)

It's not clear if csstool's algorithm is different than PurgeCSS' but the author points out it's very adapted to css frameworks and utility class system which for me is the prime use cases for css "purging".
So I'm personally fine with it but maybe others will have some reservations.

With the above, we delay the execution until the rendered content is available.

Won't the fingerprint have to be rewritten throughout the already rendered HTML files though?

css.Cut "**/*.html"

I suppose the parameter is a sensible default, it's not clear to me why people would need to change it though ? Skip a very large directory to improve build time?

Also, is the css namespace a technical requirement?

Note that the new namings in the above is just dropped in there without too much thought

Yes, Cut is a bit harsh isn't it ? I would advise against calling it PurgeCSS in case the algorithm differs too much. We could go with Prune though which sounds like Purge but is more accurate to the operation performed I think (always thought the verb purge did not really reflected the "careful" picking involved, but rather a rash cleaning).

@budparr am I missing something?

@bep
Copy link
Member Author

bep commented Jan 23, 2019

It's not clear if csstool's algorithm is different than PurgeCSS' but the author points out it's very

Note that this issue is a little on the conceptual side of it.

I suppose the parameter is a sensible default, it's not clear to me why people would need to change it though ? Skip a very large directory to improve build time?

You may want to "partition your CSS", e.g.:

{{ $blogStyles := resources.Get "scss/blog.scss" | toSCSS | minify | css.Cut "/blog/**/*.html"  }}

Won't the fingerprint have to be rewritten throughout the already rendered HTML files though?

Yes, that is a problem ... But I guess solvable somehow ...

@budparr
Copy link

budparr commented Jan 23, 2019

A welcome addition indeed.

I think it's problematic to run a tool like this on output HTML because of the overhead in terms of build-time. I run PurgeCSS on my templates to avoid that. Doesn't look like this library does that.

@regisphilibert
Copy link
Member

regisphilibert commented Jan 23, 2019

Yes I was about to say we can content with using the template files rather than the rendered html. And to this end do do we need the lib to be able to interpret go template though ?

It couldn’t read dynamically generated class names but surely it could identify the hard coded ones which represents a big percentage of the overhaul used classnames.

With a set whitelisted class this may be a sufficient approach for many.

@bep bep modified the milestones: v0.55, v0.56 Feb 1, 2019
@inwardmovement
Copy link

inwardmovement commented Feb 20, 2019

That would be a great thing.

For now I do this with gulp to perform code style rules and apply typography rules after the hugo build process, but it would be a good feature to include these kind of tasks in the hugo pipeline: one would not rely on gulp anymore.

PS. targeting public/**/*.html has the advantage to allow modifications where markdown is not effective (menus, etc.)

@bep bep modified the milestones: v0.56, v0.57 Jun 14, 2019
@bep bep modified the milestones: v0.57, v0.58 Jul 31, 2019
@bep bep modified the milestones: v0.58, v0.59 Aug 13, 2019
@bep bep modified the milestones: v0.59, v0.60 Sep 6, 2019
@bep bep modified the milestones: v0.60, v0.61 Oct 21, 2019
@bep bep modified the milestones: v0.61, v0.62, v0.63 Nov 25, 2019
@bep bep modified the milestones: v0.63, v0.64 Dec 11, 2019
@bep bep removed this from the v0.64 milestone Jan 22, 2020
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants