|
| 1 | +After PodOS has been included on your page, let's take a look at how to show some data about things on the web. |
| 2 | + |
| 3 | +We will go through these for steps: |
| 4 | + |
| 5 | +1. Define a new app |
| 6 | +2. Refer to a resource on the web |
| 7 | +3. Show label and description of that resource |
| 8 | +4. Mix and match with plain HTML |
| 9 | +5. Show a picture of the resource |
| 10 | + |
| 11 | +??? question "What is a resource?" |
| 12 | + |
| 13 | + A resource is anything on the Web identified by a URI (Uniform Resource Identifier). |
| 14 | + Most contents on the Web are *pages*, that can be found by their URL (Uniform Resource Locator). |
| 15 | + With PodOS and Solid, we are going beyond pages: *Anything* can be identified by a URI and when this URI resolves to |
| 16 | + data, then PodOS will be able to show it. |
| 17 | + |
| 18 | +## Define a new app |
| 19 | + |
| 20 | +Anything you want to do with PodOS needs to be wrapped in `<pos-app></pos-app>` |
| 21 | + |
| 22 | +```html |
| 23 | + |
| 24 | +<body> |
| 25 | +<pos-app> |
| 26 | + <!-- your app goes here --> |
| 27 | +</pos-app> |
| 28 | +</body> |
| 29 | +``` |
| 30 | + |
| 31 | +Whenever you add other PodOS elements to your page, make sure they are placed inside `pos-app`. This ensures that |
| 32 | +the child elements get access to PodOS functionality. |
| 33 | + |
| 34 | +## Refer to a resource |
| 35 | + |
| 36 | +Now that we have an app, we can refer to a resource we want to display information about. |
| 37 | + |
| 38 | +First, we need the URI of the resource in question. The PodOS project has a URI at solidcommunity.net, that serves some |
| 39 | +data: |
| 40 | + |
| 41 | +``` |
| 42 | +https://pod-os.solidcommunity.net/profile/card#me |
| 43 | +``` |
| 44 | + |
| 45 | +To fetch the data of that resource and make it available for further usage, add a `<pos-resource>` into the app: |
| 46 | + |
| 47 | +```html hl_lines="2-3" |
| 48 | + |
| 49 | +<pos-app> |
| 50 | + <pos-resource uri="https://pod-os.solidcommunity.net/profile/card#me"> |
| 51 | + </pos-resource> |
| 52 | +</pos-app> |
| 53 | +``` |
| 54 | + |
| 55 | +!!! tip |
| 56 | + |
| 57 | + If you already own a Solid Pod, you can also pass your WebID into the `uri` attribute. |
| 58 | + |
| 59 | +If you open your page now, you might notice that the resource URI will be fetched from the network already, but nothing |
| 60 | +shows up yet. We will change that in a second. |
| 61 | + |
| 62 | +## Show label and description |
| 63 | + |
| 64 | +With `<pos-resource>` we set the context to a specific resource. Inside that element, we can now define what data we |
| 65 | +want to show. |
| 66 | + |
| 67 | +Let's add |
| 68 | + |
| 69 | +1. `pos-label` to show a human-readable name of the resource |
| 70 | +2. `pos-description` to get a short text describing what it is |
| 71 | + |
| 72 | +```html hl_lines="3-4" |
| 73 | + |
| 74 | +<pos-app> |
| 75 | + <pos-resource uri="https://pod-os.solidcommunity.net/profile/card#me"> |
| 76 | + <pos-label></pos-label> |
| 77 | + <pos-description></pos-description> |
| 78 | + </pos-resource> |
| 79 | +</pos-app> |
| 80 | +``` |
| 81 | + |
| 82 | +!!! info |
| 83 | + |
| 84 | + Both `pos-label` and `pos-description` try to be "smart" about what information to show. On the web there are multiple |
| 85 | + terms that could be used to state resource labels, e.g. `rdfs:label`, `schema:name` and more. |
| 86 | + PodOS tries to use the most fitting terms and falls back to others until it finds something it could show. If nothing is availabe |
| 87 | + `pos-label` will just show the resource URI as a last resort. |
| 88 | + |
| 89 | +If you open the page now, you will see some content! |
| 90 | + |
| 91 | +> PodOS An operating system for your personal online datastore |
| 92 | +
|
| 93 | +But it does not look very appealing, yet. This is where good old HTML and CSS come in. |
| 94 | + |
| 95 | +## Mix in plain HTML and CSS |
| 96 | + |
| 97 | +PodOS elements *extend* HTML, they do not replace it. On the contrary, you can use any HTML elements next to, |
| 98 | +around or (depending on the element) even inside PodOS elements. |
| 99 | + |
| 100 | +Let's create a `section` with a `h1` heading and a `blockquote`. Use `pos-label` as part of the a heading and put |
| 101 | +`pos-description` into the `blockquote`: |
| 102 | + |
| 103 | +```html |
| 104 | + |
| 105 | +<section> |
| 106 | + <h1> |
| 107 | + Welcome to |
| 108 | + <pos-label></pos-label> |
| 109 | + </h1> |
| 110 | + <blockquote> |
| 111 | + <pos-description></pos-description> |
| 112 | + </blockquote> |
| 113 | +</section> |
| 114 | +``` |
| 115 | + |
| 116 | +Let's also add some style for `pos-app`: |
| 117 | + |
| 118 | +```html |
| 119 | + |
| 120 | +<style> |
| 121 | + pos-app { |
| 122 | + display: block; |
| 123 | + padding: 4rem; |
| 124 | + margin: 1rem; |
| 125 | + border-radius: 1rem; |
| 126 | + background-color: var(--pos-background-color); |
| 127 | + } |
| 128 | +</style> |
| 129 | +``` |
| 130 | + |
| 131 | +This should look a lot better already. But nothing compares to showing a picture. |
| 132 | + |
| 133 | +!!! tip "Build in CSS variables" |
| 134 | + |
| 135 | + Did you notice the `--pos-background-color` we are using here? PodOS comes with several of those variables built-in. You can find the available variables in [global.css](https://github.com/pod-os/PodOS/blob/main/elements/src/global.css). `--pos-background-color` is aware of the preferred color scheme and adjust to light and dark mode. |
| 136 | + |
| 137 | +## Showing a picture |
| 138 | + |
| 139 | +Adding a picture works the same as adding a label and description. You might have guessed it by now, add a `pos-picture` |
| 140 | +to your page: |
| 141 | + |
| 142 | +```html hl_lines="2" |
| 143 | + |
| 144 | +<pos-resource uri="https://pod-os.solidcommunity.net/profile/card#me"> |
| 145 | + <pos-picture></pos-picture> |
| 146 | + <section> |
| 147 | + ... |
| 148 | + </section> |
| 149 | +</pos-resource> |
| 150 | +``` |
| 151 | + |
| 152 | +We added it right next to the section with our label and description, so that we can now apply a nice flex layout to the |
| 153 | +`pos-resource`, so that the picture appears next to the text: |
| 154 | + |
| 155 | +```css |
| 156 | +pos-resource { |
| 157 | + display: flex; |
| 158 | + gap: 1rem; |
| 159 | + align-items: center; |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +## The final page |
| 164 | + |
| 165 | +Now let's take a look at the page we have built! You can find a living example at [demo.html](./demo.html). You can use |
| 166 | +your browsers "View source" feature to view the |
| 167 | +source, [or find it on GitHub](https://github.com/pod-os/PodOS/blob/main/homepage/docs/getting-started/demo.html). |
| 168 | + |
| 169 | +## Element reference |
| 170 | + |
| 171 | +Elements we have used in this guide: |
| 172 | + |
| 173 | +- [pos-app](../reference/elements/components/pos-app/index.md) |
| 174 | +- [pos-resource](../reference/elements/components/pos-resource/index.md) |
| 175 | +- [pos-label](../reference/elements/components/pos-label/index.md) |
| 176 | +- [pos-description](../reference/elements/components/pos-description/index.md) |
| 177 | +- [pos-picture](../reference/elements/components/pos-picture/index.md) |
0 commit comments