Hydrilla on-disk data format » History » Version 2
koszko, 11/11/2021 06:33 PM
update index.json example
| 1 | 1 | koszko | # Hydrilla on-disk data format |
|---|---|---|---|
| 2 | |||
| 3 | This page explains the upcoming format for Hydrilla site content stored in the filesystem. It refers to the upcoming Hydrilla 0.2 release. |
||
| 4 | |||
| 5 | {{toc}} |
||
| 6 | |||
| 7 | ## How Hydrilla loads content |
||
| 8 | |||
| 9 | Hydrilla expects a content directory to be specified in its configuration file (under the key "content-dir"). It then processes all its direct subdirectories. If given subdirectory contains an `index.json` file, Hydrilla loads it (smartly ignoring '//' comments in it) and collects the definitions of site resources, pattern->payload mappings and licenses in it. |
||
| 10 | |||
| 11 | ## Format of an index.json |
||
| 12 | |||
| 13 | To understand the format, look into this example file with explanatory comments in it: |
||
| 14 | |||
| 15 | ``` javascript |
||
| 16 | // SPDX-License-Identifier: CC0-1.0 |
||
| 17 | |||
| 18 | // Copyright (C) 2021 Wojtek Kosior |
||
| 19 | // Available under the terms of Creative Commons Zero v1.0 Universal. |
||
| 20 | |||
| 21 | // This is an example index.json file describing Hydrilla site content. As you |
||
| 22 | // can see, for storing site content information Hydrilla utilizes JSON with an |
||
| 23 | // additional extension in the form of '//' comments support. Hydrilla shall |
||
| 24 | // look into each direct subdirectory of the content directory passed to it |
||
| 25 | // (via a cofig file option). If such subsirectory contains an index.json file, |
||
| 26 | // Hydrilla shall process it. |
||
| 27 | |||
| 28 | // An index.json file conveys definitions of site resources, pattern->payload |
||
| 29 | // mappings and licenses thereof. The definitions may reference files under |
||
| 30 | // index.json's containing directory, using relative paths. This is how scripts, |
||
| 31 | // license texts, etc. are included. Unix paths (using '/' as separator) are |
||
| 32 | // assumed. It is not allowed for an index.json file to reference files outside |
||
| 33 | // its directory. |
||
| 34 | |||
| 35 | { |
||
| 36 | // Once the json schema changes, this number will change. Our software will |
||
| 37 | // be able to handle both current and older formats thanks to this |
||
| 38 | // information present in every index.json file. |
||
| 39 | "schema_version": "2021.11.11", |
||
| 40 | |||
| 41 | // Copyright of this json file. It's a list of copyright holder information |
||
| 42 | // objects. Alternatively, "auto" can be used to make Hydrilla attempt to |
||
| 43 | // extract copyright info from the comment at the beginning of the file. |
||
| 44 | "copyright": [ |
||
| 45 | // There can be multiple entries, one for each co-holder of the |
||
| 46 | // copyright. |
||
| 47 | { |
||
| 48 | // There can also be multiple years, like ["2021","2023-2024"]. |
||
| 49 | "years": ["2021"], |
||
| 50 | // Name of the copyright holder. Depending on the situation it can |
||
| 51 | // be just the firts name, name+surname, a company name, a |
||
| 52 | // pseudonym, etc. |
||
| 53 | "holder": "Wojtek Kosior" |
||
| 54 | } |
||
| 55 | ], |
||
| 56 | |||
| 57 | // License of this json file. Identifier has to be known to Hydrilla. Can |
||
| 58 | // be defined either in the same or another index.json file as a "license" |
||
| 59 | // content item. It is possible to specify license combinations, like: |
||
| 60 | // [["Expat", "and", "Apache-2.0"], "or", "GPL-3.0-only"] |
||
| 61 | // Alternatively, "auto" can be used to make Hydrilla attempt to extract |
||
| 62 | // copyright info from this file's SPDX license identifier. |
||
| 63 | "licenses": "CC0-1.0", |
||
| 64 | |||
| 65 | // Where this software/work initially comes from. In some cases (i.e. when |
||
| 66 | // the developer of content is also the one who packages it for Hydrilla) |
||
| 67 | // this might be the same as "source_url". |
||
| 68 | "upstream_url": "https://git.koszko.org/pydrilla/tree/example_content/hello", |
||
| 69 | |||
| 70 | // Where sources for the packaging of this content can be found. |
||
| 71 | "source_url": "https://git.koszko.org/pydrilla/tree/example_content/hello", |
||
| 72 | |||
| 73 | // List of actual site resources, pattern->payload mappings and licenses. |
||
| 74 | // Each of them is represented by an object. Meta-sites and replacement site |
||
| 75 | // interfaces will also belong here once they get implemented. |
||
| 76 | "content": [ |
||
| 77 | { |
||
| 78 | // Value of "type" can currently be one of: "resource", "license" |
||
| 79 | // and "mapping". The one we have here, "resource", defines a list |
||
| 80 | // of injectable scripts that can be used as a payload or as a |
||
| 81 | // dependency of another "resource". In the future CSS style sheets |
||
| 82 | // and WASM modules will also be composite parts of a "resource" as |
||
| 83 | // scripts are now. |
||
| 84 | "type": "resource", |
||
| 85 | |||
| 86 | // "name" serves as an identifier. Used when referring to this |
||
| 87 | // resource in "dependencies" list of another resource or in |
||
| 88 | // "payload" field of a mapping. |
||
| 89 | "name": "helloapple", |
||
| 90 | |||
| 91 | // Different versions of the same resource can be defined in |
||
| 92 | // separate index.json files. This makes it easy to accidently cause |
||
| 93 | // a name clash. To help detect it, we require that each resource |
||
| 94 | // has a uuid associated with it. Attempt to define multiple |
||
| 95 | // resources with the same identifier and different uuids will |
||
| 96 | // result in an error being reported. Defining multiple resources |
||
| 97 | // with different identifiers and the same uuid is disallowed for |
||
| 98 | // now (it may be later permitted if we consider it good for some |
||
| 99 | // use-case). |
||
| 100 | "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68", |
||
| 101 | |||
| 102 | // "old_uuids" field can be used to indicate that some specific |
||
| 103 | // resource name collision is allowed, for example when some |
||
| 104 | // resource (e.g. a javascript library) changes its versioning |
||
| 105 | // schema. All definitions with one of the old uuids will be treated |
||
| 106 | // as less up-to-date versions, overriding the "version" field |
||
| 107 | // value. |
||
| 108 | "old_uuids": ["ad38dc5e-30b7-492d-9290-6c3ca658f1f3"], |
||
| 109 | |||
| 110 | // A version string. Should match: [0-9]+(\.[0-9])*(-[0-9]+)? |
||
| 111 | // Values of this field from various definitions of a resource will |
||
| 112 | // be compared to decide which one provides the most current version |
||
| 113 | // (and in the future also to see which one satisfies versioned |
||
| 114 | // dependencies...). The (optional) part after '-' is the Hydrilla |
||
| 115 | // revision number. For each new resource version it starts as 1 and |
||
| 116 | // gets incremented by 1 each time a modification to the packaging |
||
| 117 | // of this version is done. |
||
| 118 | "version": "2021.11.10-1", |
||
| 119 | |||
| 120 | // A short, meaningful description of what the resource is and/or |
||
| 121 | // what it does. |
||
| 122 | "description": "greets an apple", |
||
| 123 | |||
| 124 | // If needed, a "comment" field can be added to provide some |
||
| 125 | // additional information. |
||
| 126 | // "comment": "this resource something something", |
||
| 127 | |||
| 128 | // One should specify the copyright and licensing terms of the |
||
| 129 | // entire package. The format is the same as when specifying these |
||
| 130 | // for the index.json file, except "auto" cannot be used. |
||
| 131 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
| 132 | "licenses": "CC0-1.0", |
||
| 133 | |||
| 134 | // Resource's "dependencies" array shall contain names of other |
||
| 135 | // resources that (in case of scripts at least) should get evaluated |
||
| 136 | // on a page before this resource's own scripts. |
||
| 137 | "dependencies": ["hello-message"], |
||
| 138 | |||
| 139 | // Array of javascript files that belong to this resource. |
||
| 140 | "scripts": [ |
||
| 141 | { |
||
| 142 | // Script name. It should also be a valid file path. |
||
| 143 | "name": "hello.js", |
||
| 144 | // Copyright and license info of a script file can be |
||
| 145 | // specified using the same format as in the case of the |
||
| 146 | // index.json file itself. If "copyright" or "license" is |
||
| 147 | // not provided, Hydrilla assumes it to be the same as the |
||
| 148 | // value specified for the resource itself. |
||
| 149 | "copyright": "auto", |
||
| 150 | 2 | koszko | "licenses": "auto" |
| 151 | 1 | koszko | }, { |
| 152 | 2 | koszko | "name": "bye.js" |
| 153 | 1 | koszko | } |
| 154 | ] |
||
| 155 | }, { |
||
| 156 | 2 | koszko | "type": "resource", |
| 157 | "name": "hello-message", |
||
| 158 | "uuid": "1ec36229-298c-4b35-8105-c4f2e1b9811e", |
||
| 159 | // If "old_uuids" is empty, it can as well be omitted. |
||
| 160 | // "old_uuids": [], |
||
| 161 | "version": "2021.11.10-2", |
||
| 162 | "description": "define messages for saying hello and bye", |
||
| 163 | "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}], |
||
| 164 | "licenses": "CC0-1.0", |
||
| 165 | // If "dependencies" is empty, it can also be omitted. |
||
| 166 | // "dependencies": [], |
||
| 167 | "scripts": [{"name": "message.js"}] |
||
| 168 | }, { |
||
| 169 | 1 | koszko | "type": "mapping", |
| 170 | |||
| 171 | // "name" serves as an identifier. It should be unique among all |
||
| 172 | // mapping names. It can be the same as some resource name, though. |
||
| 173 | "name": "helloapple", |
||
| 174 | 2 | koszko | |
| 175 | 1 | koszko | // "uuid", "old_uuids" and "version" have the same meaning as in the |
| 176 | // case of resources. |
||
| 177 | "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7", |
||
| 178 | "old_uuids": ["0525824d-f6e2-4ee2-8ac6-401e9dc79cdf"], |
||
| 179 | "version": "2021.11.10-1", |
||
| 180 | |||
| 181 | // A short, meaningful description of what the mapping does. |
||
| 182 | "description": "causes apple to get greeted on Hydrillabugs issue tracker", |
||
| 183 | |||
| 184 | // A comment, if necessary. |
||
| 185 | // "comment": "blah blah because bleh" |
||
| 186 | |||
| 187 | // The "injections" array specifies, which payloads are to be |
||
| 188 | // applied to which URLs. |
||
| 189 | "injctions": [ |
||
| 190 | { |
||
| 191 | // Should be a valid Haketilo URL pattern. |
||
| 192 | "pattern": "https://hydrillabugs.koszko.org/***", |
||
| 193 | // Should be the name of an existing resource. The resource |
||
| 194 | // may, but doesn't have to, be defined in the same |
||
| 195 | // index.json file. |
||
| 196 | "payload": "helloapple" |
||
| 197 | }, |
||
| 198 | // More associations may follow. |
||
| 199 | { |
||
| 200 | "pattern": "https://hachettebugs.koszko.org/***", |
||
| 201 | "payload": "helloapple" |
||
| 202 | } |
||
| 203 | ] |
||
| 204 | }, { |
||
| 205 | "type": "license", |
||
| 206 | |||
| 207 | // Will be used to refer to this license in other places. Should |
||
| 208 | // match the SPDX identifier if possible (despite that, please use |
||
| 209 | // "Expat" instead of "MIT" where possible). Unlike other content |
||
| 210 | // item types, "license" does not allow uuids to be used to avoid |
||
| 211 | // license id clashes. Any attempt to define multiple licenses with |
||
| 212 | // the same id will result in an error being reported. |
||
| 213 | "identifier": "CC0-1.0", |
||
| 214 | |||
| 215 | // This long name must also be unique among all license definitions. |
||
| 216 | "long_name": "Creative Commons Zero v1.0 Universal", |
||
| 217 | |||
| 218 | "legal_text": [ |
||
| 219 | // Legal text can be available in multiple forms. Usually just |
||
| 220 | // plain .txt file is enough, though. |
||
| 221 | { |
||
| 222 | // "format" should match an agreed-upon MIME type if |
||
| 223 | // possible. |
||
| 224 | "format": "text/plain", |
||
| 225 | // Value of "file" should be a path relative to the |
||
| 226 | // directory of index.json file. |
||
| 227 | "file": "cc0.txt" |
||
| 228 | } |
||
| 229 | // If a markdown version of CC0 was provided, we could add this: |
||
| 230 | // { |
||
| 231 | // "format": "text/markdown", |
||
| 232 | // "file": "cc0.md" |
||
| 233 | // } |
||
| 234 | ] |
||
| 235 | |||
| 236 | // If needed, a "comment" field can be added to clarify something. |
||
| 237 | // For example, when definind "Expat" license we could add: |
||
| 238 | // |
||
| 239 | // "comment": "Expat license is the most common form of the license often called \"MIT\". Many other forms of \"MIT\" license exist. Here the name \"Expat\" is used to avoid ambiguity." |
||
| 240 | |||
| 241 | // If applicable, a "notice" can be included. It shall then be a |
||
| 242 | // path (relative to index.json) to a plain text file with that |
||
| 243 | // notice. |
||
| 244 | // |
||
| 245 | // "notice": "license-notice.txt" |
||
| 246 | // |
||
| 247 | // This is needed for example in case of GNU licenses (both with and |
||
| 248 | // without exceptions). For example, |
||
| 249 | // "GPL-3.0-or-later-with-html-exception" could have the following |
||
| 250 | // in its notice file: |
||
| 251 | // |
||
| 252 | // This program is free software: you can redistribute it and/or |
||
| 253 | // modify it under the terms of the GNU General Public License as |
||
| 254 | // published by the Free Software Foundation, either version 3 of |
||
| 255 | // the License, or (at your option) any later version. |
||
| 256 | // |
||
| 257 | // This program is distributed in the hope that it will be useful, |
||
| 258 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 259 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 260 | // GNU General Public License for more details. |
||
| 261 | // |
||
| 262 | // As a special exception to the GPL, any HTML file which merely |
||
| 263 | // makes function calls to this code, and for that purpose |
||
| 264 | // includes it by reference shall be deemed a separate work for |
||
| 265 | // copyright law purposes. If you modify this code, you may extend |
||
| 266 | // this exception to your version of the code, but you are not |
||
| 267 | // obligated to do so. If you do not wish to do so, delete this |
||
| 268 | // exception statement from your version. |
||
| 269 | // |
||
| 270 | // You should have received a copy of the GNU General Public License |
||
| 271 | // along with this program. If not, see |
||
| 272 | // <https://www.gnu.org/licenses/>. |
||
| 273 | } |
||
| 274 | ] |
||
| 275 | } |
||
| 276 | ``` |