diff --git a/.dockerignore b/.dockerignore index 8708dce..1f9515c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,6 +5,7 @@ # Only add necessary files to the Docker build context (Dockerfiles are always included implicitly) !/build/ !/internal/ +!/pkg/ !/go.mod !/go.sum !main.go diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..bdd4fe6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,37 @@ +name: Bug report +description: Let us know if something isn't working as expected +labels: ["bug report"] +body: + - type: markdown + attributes: + value: | + > [!NOTE] + > + > Do not prefix your title with "[BUG]", "[Bug report]", etc., a label will be added automatically. + + If you're unsure whether you're experiencing a bug or not, consider using the [Discussions](https://github.com/glanceapp/glance/discussions) or [Discord](https://discord.com/invite/7KQ7Xa9kJd) to ask for help. + + Please include only the information you think is relevant to the bug: + + * How did you install Glance? (Docker container, manual binary install, etc) + * Which version of Glance are you using? + * Include the relevant parts of your `glance.yml` if applicable (widget, data source, properties used, etc) + * Include any relevant logs or screenshots if applicable + * Is the issue specific to a certain browser or OS? + * Steps to reliably reproduce the issue + * Are you hosting Glance on a VPS? + * Anything else you think might be relevant + + **No need to copy the above list into your description, it's just a guide to help you provide the most useful information.** + + - type: textarea + id: description + validations: + required: true + attributes: + label: Description + + - type: markdown + attributes: + value: | + Thank you for taking the time to submit a bug report. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..e8c34af --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Discussions + url: https://github.com/glanceapp/glance/discussions + about: For help, feedback, guides, resources and more + - name: Discord + url: https://discord.com/invite/7KQ7Xa9kJd + about: Much like the discussions but more chatty diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..d8f5343 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,33 @@ +name: Feature request +description: Share your ideas for new features or improvements +labels: ["feature request"] +body: + - type: markdown + attributes: + value: | + > [!NOTE] + > + > Do not prefix your title with "[REQUEST]", "[Feature request]", etc., a label will be added automatically. + + Please provide a detailed description of what the feature would do and what it would look like: + + * What problem would this feature solve? + * Are there any potential downsides to this feature? + * If applicable, what would the configuration for this feature look like? + * Are there any existing examples of this feature in other software? + * If applicable, include any external documentation required to implement this feature + * Anything else you think might be relevant + + **No need to copy the above list into your description, it's just a guide to help you provide the most useful information.** + + - type: textarea + id: description + validations: + required: true + attributes: + label: Description + + - type: markdown + attributes: + value: | + Thank you for taking the time to submit your idea. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 22b3d05..690586f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,7 +1 @@ - + diff --git a/.gitignore b/.gitignore index e466992..2cd84fc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /build /playground /.idea -glance*.yml +/glance*.yml diff --git a/Dockerfile b/Dockerfile index b89541a..0c4cc63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM golang:1.23.1-alpine3.20 AS builder +FROM golang:1.24.2-alpine3.21 AS builder WORKDIR /app COPY . /app RUN CGO_ENABLED=0 go build . -FROM alpine:3.20 +FROM alpine:3.21 WORKDIR /app COPY --from=builder /app/glance . diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser index eaf8336..bbfa8ad 100644 --- a/Dockerfile.goreleaser +++ b/Dockerfile.goreleaser @@ -1,4 +1,4 @@ -FROM alpine:3.20 +FROM alpine:3.21 WORKDIR /app COPY glance . diff --git a/README.md b/README.md index da6fb58..ca16c49 100644 --- a/README.md +++ b/README.md @@ -1,114 +1,436 @@
What if you could see everything at a...
Install • Configuration • Preconfigured pages • Themes • Discord
+Install • Configuration • Discord • Sponsor
+Community widgets • Preconfigured pages • Themes
- + -### Features -#### Various widgets +## Features +### Various widgets * RSS feeds * Subreddit posts -* Weather -* Bookmarks -* Hacker News -* Lobsters -* Latest YouTube videos from specific channels -* Clock -* Calendar -* Stocks -* iframe -* Twitch channels & top games -* GitHub releases -* Repository overview -* Docker containers -* Site monitor -* Search box +* Hacker News posts +* Weather forecasts +* YouTube channel uploads +* Twitch channels +* Market prices +* Docker containers status +* Server stats +* Custom widgets +* [and many more...](docs/configuration.md) -#### Themeable - +### Fast and lightweight +* Low memory usage +* Few dependencies +* Minimal vanilla JS +* Single <20mb binary available for multiple OSs & architectures and just as small Docker container +* Uncached pages usually load within ~1s (depending on internet speed and number of widgets) -#### Optimized for mobile devices - +### Tons of customizability +* Different layouts +* As many pages/tabs as you need +* Numerous configuration options for each widget +* Multiple styles for some widgets +* Custom CSS -#### Fast and lightweight -* Minimal JS, no bloated frameworks -* Very few dependencies -* Single, easily distributed <15mb binary and just as small docker container -* All requests are parallelized, uncached pages usually load within ~1s (depending on internet speed and number of widgets) +### Optimized for mobile devices +Because you'll want to take it with you on the go. -### Configuration -Checkout the [configuration docs](docs/configuration.md) to learn more. A [preconfigured page](docs/configuration.md#preconfigured-page) is also available to get you started quickly. + -### Installation -> [!CAUTION] -> -> The project is under active development, expect things to break every once in a while. +### Themeable +Easily create your own theme by tweaking a few numbers or choose from one of the [already available themes](docs/themes.md). -#### Manual -Checkout the [releases page](https://github.com/glanceapp/glance/releases) for available binaries. You can place the binary inside `/opt/glance/` and have it start with your server via a [systemd service](https://linuxhandbook.com/create-systemd-services/). To specify a different path for the config file use the `--config` option: + + +Powered by Glance
logo-url: /assets/logo.png favicon-url: /assets/logo.png + app-name: "My Dashboard" + app-icon-url: "/assets/app-icon.png" + app-background-color: "#151519" ``` ### Properties @@ -205,6 +287,9 @@ branding: | logo-text | string | no | G | | logo-url | string | no | | | favicon-url | string | no | | +| app-name | string | no | Glance | +| app-icon-url | string | no | Glance's default icon | +| app-background-color | string | no | Glance's default background color | #### `hide-footer` Hides the footer when set to `true`. @@ -221,6 +306,15 @@ Specify a URL to a custom image to use instead of the "G" found in the navigatio #### `favicon-url` Specify a URL to a custom image to use for the favicon. +#### `app-name` +Specify the name of the web app shown in browser tab and PWA. + +#### `app-icon-url` +Specify URL for PWA and browser tab icon (512x512 PNG). + +#### `app-background-color` +Specify background color for PWA. Must be a valid CSS color. + ## Theme Theming is done through a top level `theme` property. Values for the colors are in [HSL](https://giggster.com/guide/basics/hue-saturation-lightness/) (hue, saturation, lightness) format. You can use a color picker [like this one](https://hslpicker.com/) to convert colors from other formats to HSL. The values are separated by a space and `%` is not required for any of the numbers. @@ -248,7 +342,7 @@ theme: negative-color: 347 87 44 ``` -### Themes +### Available themes If you don't want to spend time configuring your own theme, there are [several available themes](themes.md) which you can simply copy the values for. ### Properties @@ -351,23 +445,29 @@ pages: ### Properties | Name | Type | Required | Default | | ---- | ---- | -------- | ------- | -| title | string | yes | | +| name | string | yes | | | slug | string | no | | | width | string | no | | +| desktop-navigation-width | string | no | | | center-vertically | boolean | no | false | | hide-desktop-navigation | boolean | no | false | | expand-mobile-page-navigation | boolean | no | false | | show-mobile-header | boolean | no | false | | columns | array | yes | | -#### `title` +#### `name` The name of the page which gets shown in the navigation bar. #### `slug` The URL friendly version of the title which is used to access the page. For example if the title of the page is "RSS Feeds" you can make the page accessible via `localhost:8080/feeds` by setting the slug to `feeds`. If not defined, it will automatically be generated from the title. #### `width` -The maximum width of the page on desktop. Possible values are `slim` and `wide`. +The maximum width of the page on desktop. Possible values are `default`, `slim` and `wide`. + +#### `desktop-navigation-width` +The maximum width of the desktop navigation. Useful if you have a few pages that use a different width than the rest and don't want the navigation to jump abruptly when going to and away from those pages. Possible values are `default`, `slim` and `wide`. + +Here are the pixel equivalents for each value: * default: `1600px` * slim: `1100px` @@ -526,9 +626,22 @@ Example: | thumbnail-height | float | no | 10 | | card-height | float | no | 27 | | limit | integer | no | 25 | +| preserve-order | bool | no | false | | single-line-titles | boolean | no | false | | collapse-after | integer | no | 5 | +##### `limit` +The maximum number of articles to show. + +##### `collapse-after` +How many articles are visible before the "SHOW MORE" button appears. Set to `-1` to never collapse. + +##### `preserve-order` +When set to `true`, the order of the articles will be preserved as they are in the feeds. Useful if a feed uses its own sorting order which denotes the importance of the articles. If you use this property while having a lot of feeds, it's recommended to set a `limit` to each individual feed since if the first defined feed has 15 articles, the articles from the second feed will start after the 15th article in the list. + +##### `single-line-titles` +When set to `true`, truncates the title of each post if it exceeds one line. Only applies when the style is set to `vertical-list`. + ##### `style` Used to change the appearance of the widget. Possible values are: @@ -571,9 +684,13 @@ An array of RSS/atom feeds. The title can optionally be changed. | title | string | no | the title provided by the feed | | | hide-categories | boolean | no | false | Only applicable for `detailed-list` style | | hide-description | boolean | no | false | Only applicable for `detailed-list` style | +| limit | integer | no | | | | item-link-prefix | string | no | | | | headers | key (string) & value (string) | no | | | +###### `limit` +The maximum number of articles to show from that specific feed. Useful if you have a feed which posts a lot of articles frequently and you want to prevent it from excessively pushing down articles from other feeds. + ###### `item-link-prefix` If an RSS feed isn't returning item links with a base domain and Glance has failed to automatically detect the correct domain you can manually add a prefix to each link with this property. @@ -588,15 +705,6 @@ Optionally specify the headers that will be sent with the request. Example: User-Agent: Custom User Agent ``` -##### `limit` -The maximum number of articles to show. - -##### `single-line-titles` -When set to `true`, truncates the title of each post if it exceeds one line. Only applies when the style is set to `vertical-list`. - -##### `collapse-after` -How many articles are visible before the "SHOW MORE" button appears. Set to `-1` to never collapse. - ### Videos Display a list of the latest videos from specific YouTube channels. @@ -617,20 +725,16 @@ Preview: | Name | Type | Required | Default | | ---- | ---- | -------- | ------- | | channels | array | yes | | +| playlists | array | no | | | limit | integer | no | 25 | | style | string | no | horizontal-cards | +| collapse-after | integer | no | 7 | | collapse-after-rows | integer | no | 4 | | include-shorts | boolean | no | false | | video-url-template | string | no | https://www.youtube.com/watch?v={VIDEO-ID} | ##### `channels` -A list of channel or playlist IDs. To specify a playlist, use the `playlist:` prefix like such: - -```yaml -channels: - - playlist:PL8mG-RkN2uTyZZ00ObwZxxoG_nJbs3qec - - playlist:PL8mG-RkN2uTxTK4m_Vl2dYR9yE41kRdBg -``` +A list of channels IDs. One way of getting the ID of a channel is going to the channel's page and clicking on its description: @@ -640,14 +744,32 @@ Then scroll down and click on "Share channel", then "Copy channel ID":  +##### `playlists` + +A list of playlist IDs: + +```yaml +- type: videos + playlists: + - PL8mG-RkN2uTyZZ00ObwZxxoG_nJbs3qec + - PL8mG-RkN2uTxTK4m_Vl2dYR9yE41kRdBg +``` + ##### `limit` The maximum number of videos to show. +##### `collapse-after` +Specify the number of videos to show when using the `vertical-list` style before the "SHOW MORE" button appears. + ##### `collapse-after-rows` Specify the number of rows to show when using the `grid-cards` style before the "SHOW MORE" button appears. ##### `style` -Used to change the appearance of the widget. Possible values are `horizontal-cards` and `grid-cards`. +Used to change the appearance of the widget. Possible values are `horizontal-cards`, `vertical-list` and `grid-cards`. + +Preview of `vertical-list`: + + Preview of `grid-cards`: @@ -762,7 +884,10 @@ Display a list of posts from a specific subreddit. > [!WARNING] > -> Reddit does not allow unauthorized API access from VPS IPs, if you're hosting Glance on a VPS you will get a 403 response. As a workaround you can route the traffic from Glance through a VPN or your own HTTP proxy using the `request-url-template` property. +> Reddit does not allow unauthorized API access from VPS IPs, if you're hosting Glance on a VPS you will get a 403 +> response. As a workaround you can either [register an app on Reddit](https://ssl.reddit.com/prefs/apps/) and use the +> generated ID and secret in the widget configuration to authenticate your requests (see `app-auth` property), use a proxy +> (see `proxy` property) or route the traffic from Glance through a VPN. Example: @@ -782,10 +907,12 @@ Example: | collapse-after | integer | no | 5 | | comments-url-template | string | no | https://www.reddit.com/{POST-PATH} | | request-url-template | string | no | | +| proxy | string or multiple parameters | no | | | sort-by | string | no | hot | | top-period | string | no | day | | search | string | no | | | extra-sort-by | string | no | | +| app-auth | object | no | | ##### `subreddit` The subreddit for which to fetch the posts from. @@ -843,7 +970,7 @@ r/selfhosted/comments/bsp01i/welcome_to_rselfhosted_please_read_this_first/ `{SUBREDDIT}` - the subreddit name ##### `request-url-template` -A custom request url that will be used to fetch the data instead. This is useful when you're hosting Glance on a VPS and Reddit is blocking the requests, and you want to route it through an HTTP proxy. +A custom request URL that will be used to fetch the data. This is useful when you're hosting Glance on a VPS where Reddit is blocking the requests and you want to route them through a proxy that accepts the URL as either a part of the path or a query parameter. Placeholders: @@ -854,6 +981,29 @@ https://proxy/{REQUEST-URL} https://your.proxy/?url={REQUEST-URL} ``` +##### `proxy` +A custom HTTP/HTTPS proxy URL that will be used to fetch the data. This is useful when you're hosting Glance on a VPS where Reddit is blocking the requests and you want to bypass the restriction by routing the requests through a proxy. Example: + +```yaml +proxy: http://user:pass@proxy.com:8080 +proxy: https://user:pass@proxy.com:443 +``` + +Alternatively, you can specify the proxy URL as well as additional options by using multiple parameters: + +```yaml +proxy: + url: http://proxy.com:8080 + allow-insecure: true + timeout: 10s +``` + +###### `allow-insecure` +When set to `true`, allows the use of insecure connections such as when the proxy has a self-signed certificate. + +###### `timeout` +The maximum time to wait for a response from the proxy. The value is a string and must be a number followed by one of s, m, h, d. Example: `10s` for 10 seconds, `1m` for 1 minute, etc + ##### `sort-by` Can be used to specify the order in which the posts should get returned. Possible values are `hot`, `new`, `top` and `rising`. @@ -870,6 +1020,17 @@ Can be used to specify an additional sort which will be applied on top of the al The `engagement` sort tries to place the posts with the most points and comments on top, also prioritizing recent over old posts. +##### `app-auth` +```yaml +widgets: + - type: reddit + subreddit: technology + app-auth: + name: ${REDDIT_APP_NAME} + id: ${REDDIT_APP_CLIENT_ID} + secret: ${REDDIT_APP_SECRET} +``` + ### Search Widget Display a search bar that can be used to search for specific terms on various search engines. @@ -907,6 +1068,7 @@ Preview: | search-engine | string | no | duckduckgo | | new-tab | boolean | no | false | | autofocus | boolean | no | false | +| target | string | no | _blank | | placeholder | string | no | Type here to search… | | bangs | array | no | | @@ -917,6 +1079,10 @@ Either a value from the table below or a URL to a custom search engine. Use `{QU | ---- | --- | | duckduckgo | `https://duckduckgo.com/?q={QUERY}` | | google | `https://www.google.com/search?q={QUERY}` | +| bing | `https://www.bing.com/search?q={QUERY}` | +| perplexity | `https://www.perplexity.ai/search?q={QUERY}` | +| kagi | `https://kagi.com/search?q={QUERY}` | +| startpage | `https://www.startpage.com/search?q={QUERY}` | ##### `new-tab` When set to `true`, swaps the shortcuts for showing results in the same or new tab, defaulting to showing results in a new tab. @@ -924,6 +1090,9 @@ When set to `true`, swaps the shortcuts for showing results in the same or new t ##### `autofocus` When set to `true`, automatically focuses the search input on page load. +##### `target` +The target to use when opening the search results in a new tab. Possible values are `_blank`, `_self`, `_parent` and `_top`. + ##### `placeholder` When set, modifies the text displayed in the input field before typing. @@ -1006,65 +1175,348 @@ Example: ``` ### Split Column - -Splits a full sized column in half, allowing you to place widgets side by side. This is converted to a single column on mobile devices or if not enough width is available. Widgets are defined using a `widgets` property exactly as you would on a page column. +Splits a full sized column in half, allowing you to place widgets side by side horizontally. This is converted to a single column on mobile devices or if not enough width is available. Widgets are defined using a `widgets` property exactly as you would on a page column. -Example of a full page with an effective 4 column layout using two split column widgets inside of two full sized columns: +Two widgets side by side in a `full` column: + +glance.ymlglance.ymlglance.ymlglance.ymlglance.yml{{ .JSON.String "text" }}
+``` +glance.ymlglance.yml{{ .JSON.String "text" }}
+{{ (.Subrequest "another-one").JSON.String "text" }}
+``` + +The subrequests support all the same properties as the main request, except for `subrequests` itself, so you can use `headers`, `parameters`, etc. + +`(.Subrequest "key")` can be a little cumbersome to write, so you can define a variable to make it easier: + +```yaml + template: | + {{ $anotherOne := .Subrequest "another-one" }} +{{ $anotherOne.JSON.String "text" }}
+``` + +You can also access the `.Response` property of a subrequest as you would with the main request: + +```yaml + template: | + {{ $anotherOne := .Subrequest "another-one" }} +{{ $anotherOne.Response.StatusCode }}
+``` + +> [!NOTE] +> +> Setting this property will override any query parameters that are already in the URL. + +```yaml +parameters: + param1: value1 + param2: + - item1 + - item2 +``` ### Extension Display a widget provided by an external source (3rd party). If you want to learn more about developing extensions, checkout the [extensions documentation](extensions.md) (WIP). @@ -1083,6 +1535,7 @@ Display a widget provided by an external source (3rd party). If you want to lear | url | string | yes | | | fallback-content-type | string | no | | | allow-potentially-dangerous-html | boolean | no | false | +| headers | key & value | no | | | parameters | key & value | no | | ##### `url` @@ -1091,6 +1544,14 @@ The URL of the extension. **Note that the query gets stripped from this URL and ##### `fallback-content-type` Optionally specify the fallback content type of the extension if the URL does not return a valid `Widget-Content-Type` header. Currently the only supported value for this property is `html`. +##### `headers` +Optionally specify the headers that will be sent with the request. Example: + +```yaml +headers: + x-api-key: ${SECRET_KEY} +``` + ##### `allow-potentially-dangerous-html` Whether to allow the extension to display HTML. @@ -1224,10 +1685,12 @@ Properties for each site: | title | string | yes | | | url | string | yes | | | check-url | string | no | | +| error-url | string | no | | | icon | string | no | | | allow-insecure | boolean | no | false | | same-tab | boolean | no | false | | alt-status-codes | array | no | | +| basic-auth | object | no | | `title` @@ -1235,12 +1698,16 @@ The title used to indicate the site. `url` -The public facing URL of a monitored service, the user will be redirected here. If `check-url` is not specified, this is used as the status check. +The URL of the monitored service, which must be reachable by Glance, and will be used as the link to go to when clicking on the title. If `check-url` is not specified, this is used as the status check. `check-url` The URL which will be requested and its response will determine the status of the site. If not specified, the `url` property is used. +`error-url` + +If the monitored service returns an error, the user will be redirected here. If not specified, the `url` property is used. + `icon` Optional URL to an image which will be used as the icon for the site. Can be an external URL or internal via [server configured assets](#assets-path). You can also directly use [Simple Icons](https://simpleicons.org/) via a `si:` prefix or [Dashboard Icons](https://github.com/walkxcode/dashboard-icons) via a `di:` prefix: @@ -1272,6 +1739,16 @@ alt-status-codes: - 403 ``` +`basic-auth` + +HTTP Basic Authentication credentials for protected sites. + +```yaml +basic-auth: + usename: your-username + password: your-password +``` + ### Releases Display a list of latest releases for specific repositories on Github, GitLab, Codeberg or Docker Hub. @@ -1314,7 +1791,7 @@ repositories: - codeberg:redict/redict ``` -Official images on Docker Hub can be specified by ommiting the owner: +Official images on Docker Hub can be specified by omitting the owner: ```yaml repositories: @@ -1323,7 +1800,7 @@ repositories: - dockerhub:alpine ``` -You can also specify specific tags for Docker Hub images: +You can also specify exact tags for Docker Hub images: ```yaml repositories: @@ -1331,6 +1808,17 @@ repositories: - dockerhub:nginx:stable-alpine ``` +To include prereleases you can specify the repository as an object and use the `include-prereleases` property: + +**Note: This feature is currently only available for GitHub repositories.** + +```yaml +repositories: + - gitlab:inkscape/inkscape + - repository: glanceapp/glance + include-prereleases: true + - codeberg:redict/redict +``` ##### `show-source-icon` Shows an icon of the source (GitHub/GitLab/Codeberg/Docker Hub) next to the repository name when set to `true`. @@ -1345,7 +1833,7 @@ services: glance: image: glanceapp/glance environment: - - GITHUB_TOKEN:docker-compose.ymlSuccess!
+{{ else }} +Failed to fetch data
+{{ end }} +``` + +You can also access the response headers: + +```html +{{ .String "name" }} is {{ .Int "age" }} years old
+{{ end }} +``` + +Output: + +```html +Steve is 30 years old
+Alex is 25 years old
+John is 35 years old
+``` + +For other ways of selecting data from a JSON Lines response, have a look at the docs for [tidwall/gjson](https://github.com/tidwall/gjson/tree/master?tab=readme-ov-file#json-lines). For example, to get an array of all names, you can use the following: + +```html +{{ range .JSON.Array "..#.name" }} +{{ .String "" }}
+{{ end }} +``` + +Output: + +```html +Steve
+Alex
+John
+``` + +## Functions + +The following functions are available on the `JSON` object: + +- `String(key string) string`: Returns the value of the key as a string. +- `Int(key string) int`: Returns the value of the key as an integer. +- `Float(key string) float`: Returns the value of the key as a float. +- `Bool(key string) bool`: Returns the value of the key as a boolean. +- `Array(key string) []JSON`: Returns the value of the key as an array of `JSON` objects. +- `Exists(key string) bool`: Returns true if the key exists in the JSON object. + +The following helper functions provided by Glance are available: + +- `toFloat(i int) float`: Converts an integer to a float. +- `toInt(f float) int`: Converts a float to an integer. +- `toRelativeTime(t time.Time) template.HTMLAttr`: Converts Time to a relative time such as 2h, 1d, etc which dynamically updates. **NOTE:** the value of this function should be used as an attribute in an HTML tag, e.g. ``. +- `now() time.Time`: Returns the current time. +- `offsetNow(offset string) time.Time`: Returns the current time with an offset. The offset can be positive or negative and must be in the format "3h" "-1h" or "2h30m10s". +- `duration(str string) time.Duration`: Parses a string such as `1h`, `24h`, `5h30m`, etc into a `time.Duration`. +- `parseTime(layout string, s string) time.Time`: Parses a string into time.Time. The layout must be provided in Go's [date format](https://pkg.go.dev/time#pkg-constants). You can alternatively use these values instead of the literal format: "unix", "RFC3339", "RFC3339Nano", "DateTime", "DateOnly". +- `parseLocalTime(layout string, s string) time.Time`: Same as the above, except in the absence of a timezone, it will use the local timezone instead of UTC. +- `parseRelativeTime(layout string, s string) time.Time`: A shorthand for `{{ .String "date" | parseTime "rfc3339" | toRelativeTime }}`. +- `add(a, b float) float`: Adds two numbers. +- `sub(a, b float) float`: Subtracts two numbers. +- `mul(a, b float) float`: Multiplies two numbers. +- `div(a, b float) float`: Divides two numbers. +- `formatApproxNumber(n int) string`: Formats a number to be more human-readable, e.g. 1000 -> 1k. +- `formatNumber(n float|int) string`: Formats a number with commas, e.g. 1000 -> 1,000. +- `trimPrefix(prefix string, str string) string`: Trims the prefix from a string. +- `trimSuffix(suffix string, str string) string`: Trims the suffix from a string. +- `trimSpace(str string) string`: Trims whitespace from a string on both ends. +- `replaceAll(old string, new string, str string) string`: Replaces all occurrences of a string in a string. +- `replaceMatches(pattern string, replacement string, str string) string`: Replaces all occurrences of a regular expression in a string. +- `findMatch(pattern string, str string) string`: Finds the first match of a regular expression in a string. +- `findSubmatch(pattern string, str string) string`: Finds the first submatch of a regular expression in a string. +- `sortByString(key string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by a string key in either ascending or descending order. +- `sortByInt(key string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by an integer key in either ascending or descending order. +- `sortByFloat(key string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by a float key in either ascending or descending order. +- `sortByTime(key string, layout string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by a time key in either ascending or descending order. The format must be provided in Go's [date format](https://pkg.go.dev/time#pkg-constants). +- `concat(strings ...string) string`: Concatenates multiple strings together. +- `unique(key string, arr []JSON) []JSON`: Returns a unique array of JSON objects based on the given key. + +The following helper functions provided by Go's `text/template` are available: + +- `eq(a, b any) bool`: Compares two values for equality. +- `ne(a, b any) bool`: Compares two values for inequality. +- `lt(a, b any) bool`: Compares two values for less than. +- `lte(a, b any) bool`: Compares two values for less than or equal to. +- `gt(a, b any) bool`: Compares two values for greater than. +- `gte(a, b any) bool`: Compares two values for greater than or equal to. +- `and(a, b bool) bool`: Returns true if both values are true. +- `or(a, b bool) bool`: Returns true if either value is true. +- `not(a bool) bool`: Returns the opposite of the value. +- `index(a any, b int) any`: Returns the value at the specified index of an array. +- `len(a any) int`: Returns the length of an array. +- `printf(format string, a ...any) string`: Returns a formatted string. diff --git a/docs/extensions.md b/docs/extensions.md index b1fa4fa..b6719c1 100644 --- a/docs/extensions.md +++ b/docs/extensions.md @@ -26,6 +26,9 @@ If you know how to setup an HTTP server and a bit of HTML and CSS you're ready t ### `Widget-Title` Used to specify the title of the widget. If not provided, the widget's title will be "Extension". +### `Widget-Title-URL` +Used to specify the URL that will be opened when the widget's title is clicked. If the user has specified a `title-url` in their config, it will take precedence over this header. + ### `Widget-Content-Type` Used to specify the content type that will be returned by the extension. If not provided, the content will be shown as plain text. diff --git a/docs/glance.yml b/docs/glance.yml new file mode 100644 index 0000000..35dc7cb --- /dev/null +++ b/docs/glance.yml @@ -0,0 +1,105 @@ +pages: + - name: Home + # Optionally, if you only have a single page you can hide the desktop navigation for a cleaner look + # hide-desktop-navigation: true + columns: + - size: small + widgets: + - type: calendar + first-day-of-week: monday + + - type: rss + limit: 10 + collapse-after: 3 + cache: 12h + feeds: + - url: https://selfh.st/rss/ + title: selfh.st + limit: 4 + - url: https://ciechanow.ski/atom.xml + - url: https://www.joshwcomeau.com/rss.xml + title: Josh Comeau + - url: https://samwho.dev/rss.xml + - url: https://ishadeed.com/feed.xml + title: Ahmad Shadeed + + - type: twitch-channels + channels: + - theprimeagen + - j_blow + - piratesoftware + - cohhcarnage + - christitustech + - EJ_SA + + - size: full + widgets: + - type: group + widgets: + - type: hacker-news + - type: lobsters + + - type: videos + channels: + - UCXuqSBlHAE6Xw-yeJA0Tunw # Linus Tech Tips + - UCR-DXc1voovS8nhAvccRZhg # Jeff Geerling + - UCsBjURrPoezykLs9EqgamOA # Fireship + - UCBJycsmduvYEL83R_U4JriQ # Marques Brownlee + - UCHnyfMqiRRG1u-2MsSQLbXA # Veritasium + + - type: group + widgets: + - type: reddit + subreddit: technology + show-thumbnails: true + - type: reddit + subreddit: selfhosted + show-thumbnails: true + + - size: small + widgets: + - type: weather + location: London, United Kingdom + units: metric # alternatively "imperial" + hour-format: 12h # alternatively "24h" + # Optionally hide the location from being displayed in the widget + # hide-location: true + + - type: markets + markets: + - symbol: SPY + name: S&P 500 + - symbol: BTC-USD + name: Bitcoin + - symbol: NVDA + name: NVIDIA + - symbol: AAPL + name: Apple + - symbol: MSFT + name: Microsoft + + - type: releases + cache: 1d + # Without authentication the Github API allows for up to 60 requests per hour. You can create a + # read-only token from your Github account settings and use it here to increase the limit. + # token: ... + repositories: + - glanceapp/glance + - go-gitea/gitea + - immich-app/immich + - syncthing/syncthing + + # Add more pages here: + # - name: Your page name + # columns: + # - size: small + # widgets: + # # Add widgets here + + # - size: full + # widgets: + # # Add widgets here + + # - size: small + # widgets: + # # Add widgets here diff --git a/docs/images/calendar-legacy-widget-preview.png b/docs/images/calendar-legacy-widget-preview.png new file mode 100644 index 0000000..5a161bf Binary files /dev/null and b/docs/images/calendar-legacy-widget-preview.png differ diff --git a/docs/images/calendar-widget-preview.png b/docs/images/calendar-widget-preview.png index 5a161bf..4922a9b 100644 Binary files a/docs/images/calendar-widget-preview.png and b/docs/images/calendar-widget-preview.png differ diff --git a/docs/images/custom-api-preview-1.png b/docs/images/custom-api-preview-1.png new file mode 100644 index 0000000..4cf4c30 Binary files /dev/null and b/docs/images/custom-api-preview-1.png differ diff --git a/docs/images/custom-api-preview-2.png b/docs/images/custom-api-preview-2.png new file mode 100644 index 0000000..481ef85 Binary files /dev/null and b/docs/images/custom-api-preview-2.png differ diff --git a/docs/images/custom-api-preview-3.png b/docs/images/custom-api-preview-3.png new file mode 100644 index 0000000..15d8cb2 Binary files /dev/null and b/docs/images/custom-api-preview-3.png differ diff --git a/docs/images/docker-container-parent.png b/docs/images/docker-container-parent.png new file mode 100644 index 0000000..479b3e8 Binary files /dev/null and b/docs/images/docker-container-parent.png differ diff --git a/docs/images/docker-container-parent2.png b/docs/images/docker-container-parent2.png new file mode 100644 index 0000000..4562239 Binary files /dev/null and b/docs/images/docker-container-parent2.png differ diff --git a/docs/images/docker-containers-preview.png b/docs/images/docker-containers-preview.png new file mode 100644 index 0000000..ba14fce Binary files /dev/null and b/docs/images/docker-containers-preview.png differ diff --git a/docs/images/preconfigured-page-preview.png b/docs/images/preconfigured-page-preview.png index 0a57c14..e10084c 100644 Binary files a/docs/images/preconfigured-page-preview.png and b/docs/images/preconfigured-page-preview.png differ diff --git a/docs/images/reddit-field-search.png b/docs/images/reddit-field-search.png index 97ba04a..a84ee33 100644 Binary files a/docs/images/reddit-field-search.png and b/docs/images/reddit-field-search.png differ diff --git a/docs/images/server-stats-flame-icon.png b/docs/images/server-stats-flame-icon.png new file mode 100644 index 0000000..28cf0b8 Binary files /dev/null and b/docs/images/server-stats-flame-icon.png differ diff --git a/docs/images/server-stats-preview.gif b/docs/images/server-stats-preview.gif new file mode 100644 index 0000000..829679b Binary files /dev/null and b/docs/images/server-stats-preview.gif differ diff --git a/docs/images/split-column-widget-3-columns.png b/docs/images/split-column-widget-3-columns.png new file mode 100644 index 0000000..88192c3 Binary files /dev/null and b/docs/images/split-column-widget-3-columns.png differ diff --git a/docs/images/split-column-widget-4-columns.png b/docs/images/split-column-widget-4-columns.png new file mode 100644 index 0000000..450f53e Binary files /dev/null and b/docs/images/split-column-widget-4-columns.png differ diff --git a/docs/images/split-column-widget-masonry.png b/docs/images/split-column-widget-masonry.png new file mode 100644 index 0000000..145b2d6 Binary files /dev/null and b/docs/images/split-column-widget-masonry.png differ diff --git a/docs/images/split-column-widget-preview.png b/docs/images/split-column-widget-preview.png index f1931f8..1ee336d 100644 Binary files a/docs/images/split-column-widget-preview.png and b/docs/images/split-column-widget-preview.png differ diff --git a/docs/images/themes/dracula.png b/docs/images/themes/dracula.png new file mode 100644 index 0000000..8dba452 Binary files /dev/null and b/docs/images/themes/dracula.png differ diff --git a/docs/images/themes/gruvbox.png b/docs/images/themes/gruvbox.png new file mode 100644 index 0000000..2e5b7a9 Binary files /dev/null and b/docs/images/themes/gruvbox.png differ diff --git a/docs/images/videos-widget-vertical-list-preview.png b/docs/images/videos-widget-vertical-list-preview.png new file mode 100644 index 0000000..e33ce86 Binary files /dev/null and b/docs/images/videos-widget-vertical-list-preview.png differ diff --git a/docs/themes.md b/docs/themes.md index b4185db..fdc10b2 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -53,6 +53,16 @@ theme: primary-color: 97 13 80 ``` +### Gruvbox Dark + +```yaml +theme: + background-color: 0 0 16 + primary-color: 43 59 81 + positive-color: 61 66 44 + negative-color: 6 96 59 +``` + ### Kanagawa Dark  ```yaml @@ -72,6 +82,17 @@ theme: negative-color: 209 88 54 ``` +### Dracula + +```yaml +theme: + background-color: 231 15 21 + primary-color: 265 89 79 + contrast-multiplier: 1.2 + positive-color: 135 94 66 + negative-color: 0 100 67 +``` + ## Light ### Catppuccin Latte diff --git a/docs/v0.7.0-upgrade.md b/docs/v0.7.0-upgrade.md new file mode 100644 index 0000000..93fa6b8 --- /dev/null +++ b/docs/v0.7.0-upgrade.md @@ -0,0 +1,57 @@ +## Upgrading to v0.7.0 from previous versions + +In essence, the `glance.yml` file has been moved from the root of the project to a `config/` directory and you now need to mount that directory to `/app/config` in the container. + +### Before + +Versions before v0.7.0 used a `docker-compose.yml` that looked like the following: + +```yaml +services: + glance: + image: glanceapp/glance + volumes: + - ./glance.yml:/app/glance.yml + ports: + - 8080:8080 +``` + +And expected you to have the following directory structure: + +```plaintext +glance/ + docker-compose.yml + glance.yml +``` + +### After + +With the release of v0.7.0, the recommended `docker-compose.yml` looks like the following: + +```yaml +services: + glance: + container_name: glance + image: glanceapp/glance + volumes: + - ./config:/app/config + ports: + - 8080:8080 +``` + +And expects you to have the following directory structure: + +```plaintext +glance/ + docker-compose.yml + config/ + glance.yml +``` + +## Why this change was necessary + +1. Mounting a file rather than a directory is not common practice and leads to some issues, such as creating a directory if the file is not present, which has tripped up multiple people and caused unnecessary confusion +2. v0.7.0 added automatic reloads when the configuration file changes, which based on testing didn't work when mounting a single file +3. v0.7.0 added the ability to include config files, so you'd have to make this change anyways if you wanted to take advantage of that feature + +Taking all of these into account, it felt like the right time to implement the change. diff --git a/go.mod b/go.mod index aa66fa8..4c19477 100644 --- a/go.mod +++ b/go.mod @@ -1,24 +1,32 @@ module github.com/glanceapp/glance -go 1.23.1 +go 1.24.2 require ( - github.com/fsnotify/fsnotify v1.8.0 + github.com/fsnotify/fsnotify v1.9.0 github.com/mmcdole/gofeed v1.3.0 + github.com/shirou/gopsutil/v4 v4.25.3 github.com/tidwall/gjson v1.18.0 - golang.org/x/text v0.21.0 + golang.org/x/text v0.24.0 gopkg.in/yaml.v3 v3.0.1 ) require ( - github.com/PuerkitoBio/goquery v1.10.0 // indirect + github.com/PuerkitoBio/goquery v1.10.2 // indirect github.com/andybalholm/cascadia v1.3.3 // indirect + github.com/ebitengine/purego v0.8.2 // indirect + github.com/go-ole/go-ole v1.3.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35 // indirect github.com/mmcdole/goxpp v1.1.1 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect - golang.org/x/net v0.33.0 // indirect - golang.org/x/sys v0.28.0 // indirect + github.com/tklauser/go-sysconf v0.3.15 // indirect + github.com/tklauser/numcpus v0.10.0 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect + golang.org/x/net v0.39.0 // indirect + golang.org/x/sys v0.32.0 // indirect ) diff --git a/go.sum b/go.sum index 7840f0b..9a79559 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,31 @@ -github.com/PuerkitoBio/goquery v1.10.0 h1:6fiXdLuUvYs2OJSvNRqlNPoBm6YABE226xrbavY5Wv4= -github.com/PuerkitoBio/goquery v1.10.0/go.mod h1:TjZZl68Q3eGHNBA8CWaxAN7rOU1EbDz3CWuolcO5Yu4= -github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= -github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= +github.com/PuerkitoBio/goquery v1.10.1 h1:Y8JGYUkXWTGRB6Ars3+j3kN0xg1YqqlwvdTV8WTFQcU= +github.com/PuerkitoBio/goquery v1.10.1/go.mod h1:IYiHrOMps66ag56LEH7QYDDupKXyo5A8qrjIx3ZtujY= +github.com/PuerkitoBio/goquery v1.10.2 h1:7fh2BdHcG6VFZsK7toXBT/Bh1z5Wmy8Q9MV9HqT2AM8= +github.com/PuerkitoBio/goquery v1.10.2/go.mod h1:0guWGjcLu9AYC7C1GHnpysHy056u9aEkUHwhdnePMCU= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I= +github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0= +github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= +github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35 h1:PpXWgLPs+Fqr325bN2FD2ISlRRztXibcX6e8f5FR5Dc= +github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg= github.com/mmcdole/gofeed v1.3.0 h1:5yn+HeqlcvjMeAI4gu6T+crm7d0anY85+M+v6fIFNG4= github.com/mmcdole/gofeed v1.3.0/go.mod h1:9TGv2LcJhdXePDzxiuMnukhV2/zb6VtnZt1mS+SjkLE= github.com/mmcdole/goxpp v1.1.1 h1:RGIX+D6iQRIunGHrKqnA2+700XMCnNv0bAOOv5MUhx8= @@ -24,10 +37,16 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/shirou/gopsutil/v4 v4.25.1 h1:QSWkTc+fu9LTAWfkZwZ6j8MSUk4A2LV7rbH0ZqmLjXs= +github.com/shirou/gopsutil/v4 v4.25.1/go.mod h1:RoUCUpndaJFtT+2zsZzzmhvbfGoDCJ7nFXKJf8GqJbI= +github.com/shirou/gopsutil/v4 v4.25.3 h1:SeA68lsu8gLggyMbmCn8cmp97V1TI9ld9sVzAUcKcKE= +github.com/shirou/gopsutil/v4 v4.25.3/go.mod h1:xbuxyoZj+UsgnZrENu3lQivsngRR5BdjbJwf2fv4szA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= @@ -35,7 +54,17 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU= +github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY= +github.com/tklauser/go-sysconf v0.3.15 h1:VE89k0criAymJ/Os65CSn1IXaol+1wrsFHEB8Ol49K4= +github.com/tklauser/go-sysconf v0.3.15/go.mod h1:Dmjwr6tYFIseJw7a3dRLJfsHAMXZ3nEnL/aZY+0IuI4= +github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPDo= +github.com/tklauser/numcpus v0.9.0/go.mod h1:SN6Nq1O3VychhC1npsWostA+oW+VOQTxZrS604NSRyI= +github.com/tklauser/numcpus v0.10.0 h1:18njr6LDBk1zuna922MgdjQuJFjrdppsZG60sHGfjso= +github.com/tklauser/numcpus v0.10.0/go.mod h1:BiTKazU708GQTYF4mB+cmlpT2Is1gLk7XVuEeem8LsQ= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= @@ -51,15 +80,15 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= -golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= +golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -68,25 +97,27 @@ golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= -golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= @@ -100,10 +131,11 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= -golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/glance/cli.go b/internal/glance/cli.go index e231706..0a76e66 100644 --- a/internal/glance/cli.go +++ b/internal/glance/cli.go @@ -5,23 +5,39 @@ import ( "fmt" "os" "strings" + + "github.com/shirou/gopsutil/v4/disk" + "github.com/shirou/gopsutil/v4/sensors" ) type cliIntent uint8 const ( - cliIntentServe cliIntent = iota - cliIntentConfigValidate = iota - cliIntentConfigPrint = iota - cliIntentDiagnose = iota + cliIntentVersionPrint cliIntent = iota + cliIntentServe + cliIntentConfigValidate + cliIntentConfigPrint + cliIntentDiagnose + cliIntentSensorsPrint + cliIntentMountpointInfo ) type cliOptions struct { intent cliIntent configPath string + args []string } func parseCliOptions() (*cliOptions, error) { + var args []string + + args = os.Args[1:] + if len(args) == 1 && (args[0] == "--version" || args[0] == "-v" || args[0] == "version") { + return &cliOptions{ + intent: cliIntentVersionPrint, + }, nil + } + flags := flag.NewFlagSet("", flag.ExitOnError) flags.Usage = func() { fmt.Println("Usage: glance [options] command") @@ -32,6 +48,8 @@ func parseCliOptions() (*cliOptions, error) { fmt.Println("\nCommands:") fmt.Println(" config:validate Validate the config file") fmt.Println(" config:print Print the parsed config file with embedded includes") + fmt.Println(" sensors:print List all sensors") + fmt.Println(" mountpoint:info Print information about a given mountpoint path") fmt.Println(" diagnose Run diagnostic checks") } configPath := flags.String("config", "glance.yml", "Set config path") @@ -41,7 +59,7 @@ func parseCliOptions() (*cliOptions, error) { } var intent cliIntent - var args = flags.Args() + args = flags.Args() unknownCommandErr := fmt.Errorf("unknown command: %s", strings.Join(args, " ")) if len(args) == 0 { @@ -51,11 +69,19 @@ func parseCliOptions() (*cliOptions, error) { intent = cliIntentConfigValidate } else if args[0] == "config:print" { intent = cliIntentConfigPrint + } else if args[0] == "sensors:print" { + intent = cliIntentSensorsPrint } else if args[0] == "diagnose" { intent = cliIntentDiagnose } else { return nil, unknownCommandErr } + } else if len(args) == 2 { + if args[0] == "mountpoint:info" { + intent = cliIntentMountpointInfo + } else { + return nil, unknownCommandErr + } } else { return nil, unknownCommandErr } @@ -63,5 +89,54 @@ func parseCliOptions() (*cliOptions, error) { return &cliOptions{ intent: intent, configPath: *configPath, + args: args, }, nil } + +func cliSensorsPrint() int { + tempSensors, err := sensors.SensorsTemperatures() + if err != nil { + if warns, ok := err.(*sensors.Warnings); ok { + fmt.Printf("Could not retrieve information for some sensors (%v):\n", err) + for _, w := range warns.List { + fmt.Printf(" - %v\n", w) + } + fmt.Println() + } else { + fmt.Printf("Failed to retrieve sensor information: %v\n", err) + return 1 + } + } + + if len(tempSensors) == 0 { + fmt.Println("No sensors found") + return 0 + } + + fmt.Println("Sensors found:") + for _, sensor := range tempSensors { + fmt.Printf(" %s: %.1f°C\n", sensor.SensorKey, sensor.Temperature) + } + + return 0 +} + +func cliMountpointInfo(requestedPath string) int { + usage, err := disk.Usage(requestedPath) + if err != nil { + fmt.Printf("Failed to retrieve info for path %s: %v\n", requestedPath, err) + if warns, ok := err.(*disk.Warnings); ok { + for _, w := range warns.List { + fmt.Printf(" - %v\n", w) + } + } + + return 1 + } + + fmt.Println("Path:", usage.Path) + fmt.Println("FS type:", ternary(usage.Fstype == "", "unknown", usage.Fstype)) + fmt.Printf("Used percent: %.1f%%\n", usage.UsedPercent) + + return 0 +} diff --git a/internal/glance/config-fields.go b/internal/glance/config-fields.go index 6c6f0c5..1a0a701 100644 --- a/internal/glance/config-fields.go +++ b/internal/glance/config-fields.go @@ -1,7 +1,11 @@ package glance import ( + "crypto/tls" "fmt" + "html/template" + "net/http" + "net/url" "regexp" "strconv" "strings" @@ -10,7 +14,7 @@ import ( "gopkg.in/yaml.v3" ) -var hslColorFieldPattern = regexp.MustCompile(`^(?:hsla?\()?(\d{1,3})(?: |,)+(\d{1,3})%?(?: |,)+(\d{1,3})%?\)?$`) +var hslColorFieldPattern = regexp.MustCompile(`^(?:hsla?\()?([\d\.]+)(?: |,)+([\d\.]+)%?(?: |,)+([\d\.]+)%?\)?$`) const ( hslHueMax = 360 @@ -19,13 +23,17 @@ const ( ) type hslColorField struct { - Hue uint16 - Saturation uint8 - Lightness uint8 + Hue float64 + Saturation float64 + Lightness float64 } func (c *hslColorField) String() string { - return fmt.Sprintf("hsl(%d, %d%%, %d%%)", c.Hue, c.Saturation, c.Lightness) + return fmt.Sprintf("hsl(%.1f, %.1f%%, %.1f%%)", c.Hue, c.Saturation, c.Lightness) +} + +func (c *hslColorField) ToHex() string { + return hslToHex(c.Hue, c.Saturation, c.Lightness) } func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error { @@ -41,7 +49,7 @@ func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error { return fmt.Errorf("invalid HSL color format: %s", value) } - hue, err := strconv.ParseUint(matches[1], 10, 16) + hue, err := strconv.ParseFloat(matches[1], 64) if err != nil { return err } @@ -50,7 +58,7 @@ func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error { return fmt.Errorf("HSL hue must be between 0 and %d", hslHueMax) } - saturation, err := strconv.ParseUint(matches[2], 10, 8) + saturation, err := strconv.ParseFloat(matches[2], 64) if err != nil { return err } @@ -59,7 +67,7 @@ func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error { return fmt.Errorf("HSL saturation must be between 0 and %d", hslSaturationMax) } - lightness, err := strconv.ParseUint(matches[3], 10, 8) + lightness, err := strconv.ParseFloat(matches[3], 64) if err != nil { return err } @@ -68,9 +76,9 @@ func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error { return fmt.Errorf("HSL lightness must be between 0 and %d", hslLightnessMax) } - c.Hue = uint16(hue) - c.Saturation = uint8(saturation) - c.Lightness = uint8(lightness) + c.Hue = hue + c.Saturation = saturation + c.Lightness = lightness return nil } @@ -112,7 +120,7 @@ func (d *durationField) UnmarshalYAML(node *yaml.Node) error { } type customIconField struct { - URL string + URL template.URL IsFlatIcon bool // TODO: along with whether the icon is flat, we also need to know // whether the icon is black or white by default in order to properly @@ -120,17 +128,23 @@ type customIconField struct { } func newCustomIconField(value string) customIconField { + const autoInvertPrefix = "auto-invert " field := customIconField{} prefix, icon, found := strings.Cut(value, ":") if !found { - field.URL = value + if strings.HasPrefix(value, autoInvertPrefix) { + field.IsFlatIcon = true + value = strings.TrimPrefix(value, autoInvertPrefix) + } + + field.URL = template.URL(value) return field } switch prefix { case "si": - field.URL = "https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + icon + ".svg" + field.URL = template.URL("https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + icon + ".svg") field.IsFlatIcon = true case "di", "sh": // syntax: di: