v0.7.9
glanceapp/glancev0.7.9Mar 29, 2025by svilenmarkov
AI Summary
The Custom API widget receives significant improvements including automatic type handling and new time-related functions.
Key Highlights
- Automatic number type handling: adding integers now results in integers.
- Added `skip-json-validation` and `.JSONLines` support for newline-separated JSON.
- Added `concat`, `now`, and `offsetNow` template functions.
- Added `Widget-Title-URL` header support for extension widgets.
New Features
- Automatic number type handling
- skip-json-validation option
- .JSONLines support
- concat function
- now function
- offsetNow function
- Widget-Title-URL header support
Full Release Notes
Another small release that's primarily focused around `custom-api` widget improvements.
## Changed
You no longer need to convert numbers to float before doing math operations with them. When adding two integers together, the result will be an integer. Adding two floats together or an integer and a float will result in a float.
Before:
```html
{{ (add (.JSON.Int "foo" | toFloat) (.JSON.Int "bar" | toFloat)) | toInt }}
```
Now:
```html
{{ add (.JSON.Int "foo") (.JSON.Int "bar") }}
```
(this is consistent for all math operations, not just addition)
## New
### `skip-json-validation` and `.JSONLines`
```yaml
- type: custom-api
url: https://api.example.com
skip-json-validation: true
```
Some API's return newline separated JSON objects instead of a single JSON array. This is not valid JSON, so the `custom-api` widget will fail to parse it. You can now set `skip-json-validation` to `true` to skip the validation step and parse the response as a list of JSON objects within your template.
```json
{"name": "Steve", "age": 30}
{"name": "Alex", "age": 25}
{"name": "John", "age": 35}
```
You can then access the JSON objects using `.JSONLines`:
```html
{{ range .JSONLines }}
{{ .String "name" }}
{{ end }}
```
### New functions
#### `concat`
```
{{ concat "foo" "bar" "baz" }}
```
will return `foobarbaz`.
(thanks @ralphocdol)
#### `now`
Returns the current time as a [`time.Time`](https://pkg.go.dev/time#Time) object.
```
{{ now }}
{{ now.Hour }}:{{ now.Minute }}:{{ now.Second }}
{{ now.Unix }}
```
```
2025-03-29 17:20:18.4905224 +0000 GMT m=+376.954385401
17:20:18
1743268818
```
This can also be used to convert time to your current timezone:
```
{{ $parsedTime := .JSON.String "date_created" | parseTime "rfc3339" }}
{{ $created := $parsedTime.In now.Location }}
{{ $created.Hour }}:{{ $created.Minute }}:{{ $created.Second }}
```
(thanks @not-first & @ralphocdol)
#### `offsetNow`
Returns the current time offset by a given amount:
```
{{ offsetNow "1h" }}
{{ now }}
{{ offsetNow "-1h" }}
```
```
2025-03-29 18:44:04.2719241 +0000 GMT m=+4178.324981601
2025-03-29 17:44:04.2719241 +0000 GMT m=+578.324981601
2025-03-29 16:44:04.2719241 +0000 GMT m=-3021.675018399
```
This can be used to check if something happened within a certain time frame:
```
{{ $created := .JSON.String "date_created" | parseTime "rfc3339" }}
{{ if ($created.After (offsetNow "-1h")) }}
Created less than 1 hour ago
{{ end }}
```
### `Widget-Title-URL` header for extension widget
The extension widget can now return a `Widget-Title-URL` header to set the link of the widget's title if it has not already been set by the user.
(thanks @not-first)
## Fixes
* The markets widget will now properly display prices of markets where the price is less than 0.01 (thanks @nsdont)