]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - docs/tips-and-tricks.md
Fixes identations and link docs.
[github/bastienwirtz/homer.git] / docs / tips-and-tricks.md
CommitLineData
1bc75494
BW
1# Tips & Tricks
2
3Here is a collection of neat tips and tricks that Homer users have come up with!
4
5## Use Homer as a custom "new tab" page
6#### `by @vosdev`
7
4f04feb2 8These extensions for [Firefox](https://addons.mozilla.org/firefox/addon/custom-new-tab-page) and [Chrome & Friends](https://chrome.google.com/webstore/detail/new-tab-changer/occbjkhimchkolibngmcefpjlbknggfh) allow you to have your homer dashboard in your new tab page, while leaving focus on the address bar meaning you can still type right away if you want to search or go to a page that is not on your homer dash.
1bc75494 9
2662b170 10The Firefox extension loads Homer in an iframe on your new tab page, meaning you have to add `target: '_top'` to each of your items.
1bc75494
BW
11
12```yaml
13- name: "Reddit"
14 logo: "assets/daily/reddit.png"
15 url: "https://reddit.com"
16 target: '_top'
17
18- name: "YouTube"
19 logo: "assets/daily/youtube.png"
20 url: "https://youtube.com"
21 target: '_top'
22```
23
1bc75494
BW
24## YAML Anchors
25#### `by @JamiePhonic`
26
2662b170 27Since Homer is configured using YAML, it supports all of YAML's helpful features, such as anchoring!
1bc75494
BW
28
29For example, you can define tags and tag styles for each "item" in a service.
30Using Anchoring, you can define all your tags and their styles once like this: (for example)
31
32```yaml
33# Some pre-defined tag styles. reference these using <<: *{NAME} inside an item definition; For Example, <<: *Apps
34tags:
35 Favourite: &Favourite
36 - tag: "Favourite"
37 tagstyle: "is-medium is-primary"
38 CI: &CI
39 - tag: "CI"
40 tagstyle: "is-medium is-success"
41 Apps: &Apps
42 - tag: "App"
43 tagstyle: "is-medium is-info"
44```
45
46and then simply reference these pre-defined (anchored) tags in each item like so:
47
48```yaml
49- name: "VS Code"
50 logo: "/assets/vscode.png"
86f4680a 51 subtitle: "Develop Code Anywhere, On Anything!"
52 <<: *App # Reference to the predefined "App" Tag
1bc75494
BW
53 url: "https://vscode.example.com/"
54 target: "_blank" # optional html tag target attribute
55````
56
86f4680a 57Then when Homer reads your config, it will substitute your anchors automatically, the above example is equal to:
1bc75494
BW
58
59```yaml
60- name: "VS Code"
61 logo: "/assets/vscode.png"
86f4680a 62 subtitle: "Develop Code Anywhere, On Anything!"
1bc75494
BW
63 tag: "App"
64 tagstyle: "is-medium is-info"
65 url: "https://vscode.example.com/"
66 target: "_blank" # optional html tag target attribute
67```
68
86f4680a 69The end result is that if you want to update the name or style of any particular tag, just update it once, in the tags section!
1bc75494
BW
70Great if you have a lot of services or a lot of tags!
71
72## Remotely edit your config with Code Server
73#### `by @JamiePhonic`
74
86f4680a 75Homer doesn't yet provide a way to edit your configuration from inside Homer itself, but that doesn't mean it can't be done!
1bc75494 76
b102c9b2 77You can setup and use [Code-Server](https://github.com/cdr/code-server) to edit your `config.yml` file from anywhere!
1bc75494
BW
78
79If you're running Homer in docker, you can setup a Code-Server container and pass your homer config directory into it.
86f4680a 80Simply pass your homer config directory as an extra -v parameter to your code-server container:
1bc75494
BW
81```
82-v '/your/local/homer/config-dir/':'/config/homer':'rw'
83```
84This will map your homer config directory (For example, /docker/appdata/homer/) into code-server's `/config/` directory, in a sub folder called `homer`
85
86As a bonus, Code-Server puts the "current folder" as a parameter in the URL bar, so you could add a `links:` entry in Homer that points to your code-server instance with the directory pre-filled for essentially 1 click editing!
87
86f4680a 88For example:
1bc75494
BW
89```yml
90links:
91 - name: Edit config
92 icon: fas fa-cog
93 url: https://vscode.example.net/?folder=/config/homer
94 target: "_blank" # optional html tag target attribute
95```
96where the path after `?folder=` is the path to the folder where you mounted your homer config INSIDE the Code-Server container.
97
98### Example Code-Server docker create command
99```sh
100docker create \
101 --name=code-server \
102 -e PUID=1000 \
103 -e PGID=1000 \
104 -e TZ=Europe/London \
105 -e PASSWORD={YOUR_PASSWORD} `#optional` \
106 -e SUDO_PASSWORD={YOUR SUDO_PASSWORD} `#optional` \
107 -p 8443:8443 \
108 -v /path/to/appdata/config:/config \
109 -v /your/local/homer/config-dir/:/config/homer \
110 --restart unless-stopped \
111 linuxserver/code-server
112```
af663d33
J
113
114
115## Get the news headlines in Homer
6d29bc27 116
117### Mapping Fields
118Most times, the url you're getting headlines from follows a different schema than the one expected by Homer.
119
120For example, if you would like to show jokes from ChuckNorris.io, you'll find that the url https://api.chucknorris.io/jokes/random is giving you info like this:
121
122```json
123{
124 "categories": [],
125 "created_at": "2020-01-05 13:42:22.089095",
126 "icon_url": "https://assets.chucknorris.host/img/avatar/chuck-norris.png",
127 "id": "MR2-BnMBR667xSpQBIleUg",
128 "updated_at": "2020-01-05 13:42:22.089095",
129 "url": "https://api.chucknorris.io/jokes/MR2-BnMBR667xSpQBIleUg",
130 "value": "Chuck Norris can quitely sneak up on himself"
131}
132```
133
134but... you need that info to be transformed to something like this:
135
136```json
137{
138 "title": "MR2-BnMBR667xSpQBIleUg",
139 "content": "Chuck Norris can quitely sneak up on himself"
140}
141```
142
143Now, you can do that using the `mapping` field in your `message` configuration. This example would be something like this:
144
145```yml
146message:
147 url: https://api.chucknorris.io/jokes/random
9542de6e 148 mapping:
149 title: 'id'
150 content: 'value'
6d29bc27 151```
152
153As you would see, using the ID as a title doesn't seem nice, that's why when a field is empty it would keep the default values, like this:
154
155```yml
156message:
157 url: https://api.chucknorris.io/jokes/random
9542de6e 158 mapping:
159 content: 'value'
6d29bc27 160 title: "Chuck Norris Facts!"
161```
162
163and even an error message in case the `url` didn't respond or threw an error:
164
165```yml
166message:
167 url: https://api.chucknorris.io/jokes/random
9542de6e 168 mapping:
169 content: 'value'
6d29bc27 170 title: "Chuck Norris Facts!"
171 content: "Message could not be loaded"
172```
173
af663d33
J
174#### `by @JamiePhonic`
175
176Homer allows you to set a "message" that will appear at the top of the page, however, you can also supply a `url:`.
177
178If the URL you specified returns a JSON object that defines a `title` and `content` item, homer will replace these values from your `config.yml` with the ones in the returned object.
179
180So, using [Node-Red](https://nodered.org/docs/getting-started/) and a quick flow, you can process an RSS feed to replace the message with a news item!
181
182To get started, simply import [this flow](https://flows.nodered.org/flow/4b6406c9a684c26ace0430dd1826e95d) into your Node-Red instance and change the RSS feed in the "Get News RSS Feed" node to one of your choosing!
183
2662b170 184So far, the flow has been tested with BBC News and Sky News, however it should be easy to modify the flow to work with other RSS feeds if they don't work out of the box!