Project

General

Profile

Hydrilla on-disk data format » History » Version 3

koszko, 11/11/2021 07:06 PM
update index.json example once again

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 3 koszko
	    // Used when referring to this resource in "dependencies" list of
87
	    // another resource or in "payload" field of a mapping. Should
88
	    // be consize and can only use a restricted set of characters. It
89
	    // has to match: [-0-9a-zA-Z]
90
	    "identifier": "helloapple",
91 1 koszko
92 3 koszko
	    // "long_name" should be used to specify a user-friendly alternative
93
	    // to an identifier. It should not collide with a long name of some
94
	    // resource with a different uuid. However, it can change in-between
95
	    // versions of the same resource and is allowed to contain arbitrary
96
	    // unicode characters (within reason!).
97
	    "long_name": "Hello Apple",
98
99 1 koszko
	    // Different versions of the same resource can be defined in
100
	    // separate index.json files. This makes it easy to accidently cause
101 3 koszko
	    // an identifier clash. To help detect it, we require that each
102
	    // resource has a uuid associated with it. Attempt to define
103
	    // multiple resources with the same identifier and different uuids
104
	    // will result in an error being reported. Defining multiple
105
	    // resources with different identifiers and the same uuid is
106
	    // disallowed for now (it may be later permitted if we consider it
107
	    // good for some use-case).
108 1 koszko
	    "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68",
109
110
	    // "old_uuids" field can be used to indicate that some specific
111 3 koszko
	    // resource identifier collision is allowed, for example when some
112 1 koszko
	    // resource (e.g. a javascript library) changes its versioning
113
	    // schema. All definitions with one of the old uuids will be treated
114
	    // as less up-to-date versions, overriding the "version" field
115 3 koszko
	    // values comparison result.
116 1 koszko
	    "old_uuids": ["ad38dc5e-30b7-492d-9290-6c3ca658f1f3"],
117
118 3 koszko
	    // A version string. Should match:
119
	    // [1-9][0-9]*(\.[1-9][0-9])*-[1-9][0-9]*?
120 1 koszko
	    // Values of this field from various definitions of a resource will
121
	    // be compared to decide which one provides the most current version
122
	    // (and in the future also to see which one satisfies versioned
123
	    // dependencies...). The (optional) part after '-' is the Hydrilla
124
	    // revision number. For each new resource version it starts as 1 and
125
	    // gets incremented by 1 each time a modification to the packaging
126
	    // of this version is done.
127
	    "version": "2021.11.10-1",
128
129
	    // A short, meaningful description of what the resource is and/or
130
	    // what it does.
131
	    "description": "greets an apple",
132
133
	    // If needed, a "comment" field can be added to provide some
134
	    // additional information.
135
	    // "comment": "this resource something something",
136
137
	    // One should specify the copyright and licensing terms of the
138
	    // entire package. The format is the same as when specifying these
139
	    // for the index.json file, except "auto" cannot be used.
140
	    "copyright": [{"years": ["2021"], "holder": "Wojtek Kosior"}],
141
	    "licenses": "CC0-1.0",
142
143
	    // Resource's "dependencies" array shall contain names of other
144
	    // resources that (in case of scripts at least) should get evaluated
145
	    // on a page before this resource's own scripts.
146
	    "dependencies": ["hello-message"],
147
148
	    // Array of javascript files that belong to this resource.
149
	    "scripts": [
150
		{
151
		    // Script name. It should also be a valid file path.
152
		    "name": "hello.js",
153
		    // Copyright and license info of a script file can be
154
		    // specified using the same format as in the case of the
155 2 koszko
		    // index.json file itself. If "copyright" or "license" is
156
		    // not provided, Hydrilla assumes it to be the same as the
157
		    // value specified for the resource itself.
158 1 koszko
		    "copyright": "auto",
159
		    "licenses":  "auto"
160
		}, {
161
		    "name":   "bye.js"
162
		}
163
	    ]
164
	}, {
165 3 koszko
	    "type":       "resource",
166
	    "identifier": "hello-message",
167
	    "long_name":  "Hello Message",
168
	    "uuid":       "1ec36229-298c-4b35-8105-c4f2e1b9811e",
169 2 koszko
	    // If "old_uuids" is empty, it can as well be omitted.
170
	    // "old_uuids": [],
171 3 koszko
	    "version":     "2021.11.10-2",
172 2 koszko
	    "description": "define messages for saying hello and bye",
173 3 koszko
	    "copyright":   [{"years": ["2021"], "holder": "Wojtek Kosior"}],
174
	    "licenses":    "CC0-1.0",
175 2 koszko
	    // If "dependencies" is empty, it can also be omitted.
176 1 koszko
	    // "dependencies": [],
177
	    "scripts": [{"name": "message.js"}]
178
	}, {
179
	    "type": "mapping",
180
181 3 koszko
	    // Has similar function to resource's identifier. Should be consize
182
	    // and can only use a restricted set of characters. It has to match:
183
	    // [-0-9a-zA-Z]
184
	    // It can be the same as some resource identifier (those are
185
	    // different entities and are treated separately).
186
	    "identifier": "helloapple",
187 1 koszko
188 3 koszko
	    // "long name", "uuid", "old_uuids" and "version" have the same
189
	    // meaning as in the case of resources.
190
	    "long_name": "Hello Apple",
191 1 koszko
	    "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7",
192
	    "old_uuids": ["0525824d-f6e2-4ee2-8ac6-401e9dc79cdf"],
193
	    "version": "2021.11.10-1",
194
195
	    // A short, meaningful description of what the mapping does.
196
	    "description": "causes apple to get greeted on Hydrillabugs issue tracker",
197
198
	    // A comment, if necessary.
199
	    // "comment": "blah blah because bleh"
200
201
	    // The "injections" array specifies, which payloads are to be
202
	    // applied to which URLs.
203
	    "injctions": [
204
		{
205
		    // Should be a valid Haketilo URL pattern.
206
		    "pattern": "https://hydrillabugs.koszko.org/***",
207
		    // Should be the name of an existing resource. The resource
208
		    // may, but doesn't have to, be defined in the same
209
		    // index.json file.
210
		    "payload": "helloapple"
211
		},
212
		// More associations may follow.
213
		{
214
		    "pattern": "https://hachettebugs.koszko.org/***",
215
		    "payload": "helloapple"
216
		}
217
	    ]
218
	}, {
219
	    "type": "license",
220
221
	    // Will be used to refer to this license in other places. Should
222
	    // match the SPDX identifier if possible (despite that, please use
223
	    // "Expat" instead of "MIT" where possible). Unlike other content
224
	    // item types, "license" does not allow uuids to be used to avoid
225
	    // license id clashes. Any attempt to define multiple licenses with
226
	    // the same id will result in an error being reported.
227
	    "identifier": "CC0-1.0",
228
229
	    // This long name must also be unique among all license definitions.
230
	    "long_name": "Creative Commons Zero v1.0 Universal",
231
232
	    "legal_text": [
233
		// Legal text can be available in multiple forms. Usually just
234
		// plain .txt file is enough, though.
235
		{
236
		    // "format" should match an agreed-upon MIME type if
237
		    // possible.
238
		    "format": "text/plain",
239
		    // Value of "file" should be a path relative to the
240
		    // directory of index.json file.
241
		    "file":   "cc0.txt"
242
		}
243
		// If a markdown version of CC0 was provided, we could add this:
244
		// {
245
		//     "format": "text/markdown",
246
		//     "file": "cc0.md"
247
		// }
248
	    ]
249
250
	    // If needed, a "comment" field can be added to clarify something.
251
	    // For example, when definind "Expat" license we could add:
252
	    //
253
	    // "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."
254
255
	    // If applicable, a "notice" can be included. It shall then be a
256
	    // path (relative to index.json) to a plain text file with that
257
	    // notice.
258
	    //
259
	    // "notice": "license-notice.txt"
260
	    //
261
	    // This is needed for example in case of GNU licenses (both with and
262
	    // without exceptions). For example,
263
	    // "GPL-3.0-or-later-with-html-exception" could have the following
264
	    // in its notice file:
265
	    //
266
	    // This program is free software: you can redistribute it and/or
267
	    // modify it under the terms of the GNU General Public License as
268
	    // published by the Free Software Foundation, either version 3 of
269
	    // the License, or (at your option) any later version.
270
	    //
271
	    // This program is distributed in the hope that it will be useful,
272
	    // but WITHOUT ANY WARRANTY; without even the implied warranty of
273
	    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
274
	    // GNU General Public License for more details.
275
	    //
276
	    // As a special exception to the GPL, any HTML file which merely
277
	    // makes function calls to this code, and for that purpose
278
	    // includes it by reference shall be deemed a separate work for
279
	    // copyright law purposes.  If you modify this code, you may extend
280
	    // this exception to your version of the code, but you are not
281
	    // obligated to do so.  If you do not wish to do so, delete this
282
	    // exception statement from your version.
283
	    //
284
	    // You should have received a copy of the GNU General Public License
285
	    // along with this program.  If not, see
286
	    // <https://www.gnu.org/licenses/>.
287
	}
288
    ]
289
}
290
```