gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.69k stars 7.45k forks source link

Advanced Math Functions for Hugo Templates #10857

Closed marcpabst closed 2 weeks ago

marcpabst commented 1 year ago

I suggest the addition of advanced math functions to the Hugo framework. These functions would be accessible in templates, enabling users to perform complex mathematical operations more easily. The proposed functions from https://pkg.go.dev/math to be added are:

math.Acos
math.Asin
math.Atan
math.Cos
math.Sin
math.Tan
math.Pi

Hugo currently supports basic arithmetic operations in templates, but lacks support for more advanced mathematical operations. By adding these functions, we can enhance Hugo's capabilities and make it more versatile for users working with complex math in their projects.

A possible use case could involve a Hugo template displays an interactive map using map tiles from an API like OpenStreetMap or Mapbox. By pulling map tiles at deploy time, we could avoid calls to external APIs by the clients. To identify the map tiles that are needed for a certain geographic area, trigonometric calculations are needed. These calculations are fairly simple but involve the above-mentioned functions.

This proposal introduces new template functions and does not modify existing functionality. As such, it is fully backwards compatible and will not impact existing projects or require any changes to existing templates.

Discussed on Discourse here: https://discourse.gohugo.io/t/more-advanced-math-functions/43539/1

raoulb commented 1 month ago

Closed by #12660

jmooring commented 2 weeks ago

Implemented in https://github.com/gohugoio/hugo/commit/9d2b5f98d0efa06d5faf1a7596a53051bc1e088c.