archsight 0.4.3 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +4 -0
  3. data/docs/configuration.md +6 -0
  4. data/docs/diagram.md +5 -0
  5. data/docs/index.md.erb +2 -0
  6. data/docs/pdf-export.md +118 -0
  7. data/docs/slide-decks.md +58 -0
  8. data/lib/archsight/analysis/typst_renderer.rb +25 -78
  9. data/lib/archsight/assets.rb +37 -1
  10. data/lib/archsight/cli.rb +37 -0
  11. data/lib/archsight/diagram/graph/attributes.rb +3 -1
  12. data/lib/archsight/diagram/graph/node.rb +18 -1
  13. data/lib/archsight/diagram/layout/expander.rb +75 -3
  14. data/lib/archsight/diagram/layout/rank_arranger.rb +3 -1
  15. data/lib/archsight/linter.rb +13 -0
  16. data/lib/archsight/markdown.rb +17 -1
  17. data/lib/archsight/pdf/cache.rb +41 -0
  18. data/lib/archsight/pdf/compiler.rb +69 -0
  19. data/lib/archsight/pdf/dependency_graph.rb +127 -0
  20. data/lib/archsight/pdf/document.rb +227 -0
  21. data/lib/archsight/pdf/embeds.rb +134 -0
  22. data/lib/archsight/pdf/images.rb +94 -0
  23. data/lib/archsight/pdf/markdown.rb +217 -0
  24. data/lib/archsight/pdf/remote_image.rb +122 -0
  25. data/lib/archsight/pdf/resource_sheet.rb +129 -0
  26. data/lib/archsight/pdf/sample_document.rb +67 -0
  27. data/lib/archsight/pdf/tables.rb +72 -0
  28. data/lib/archsight/pdf/theme.rb +125 -0
  29. data/lib/archsight/pdf/typst/archsight.typ +152 -0
  30. data/lib/archsight/pdf/typst.rb +45 -0
  31. data/lib/archsight/pdf.rb +30 -0
  32. data/lib/archsight/resources/config.rb +147 -0
  33. data/lib/archsight/resources/page.rb +8 -0
  34. data/lib/archsight/slides.rb +88 -0
  35. data/lib/archsight/version.rb +1 -1
  36. data/lib/archsight/web/api/openapi/spec.yaml +312 -1
  37. data/lib/archsight/web/api/page_helpers.rb +2 -0
  38. data/lib/archsight/web/api/pdf_helpers.rb +46 -0
  39. data/lib/archsight/web/api/routes.rb +45 -0
  40. data/lib/archsight/web/public/vue/DocPage-CkTW4dsq.js +1 -0
  41. data/lib/archsight/web/public/vue/EditorPage-DSxjLS7O.js +35 -0
  42. data/lib/archsight/web/public/vue/ErrorPage-t0nIF3Mt.js +2 -0
  43. data/lib/archsight/web/public/vue/GraphView-cjbSm9VK.js +1 -0
  44. data/lib/archsight/web/public/vue/HomePage-CNTs4DbN.js +2 -0
  45. data/lib/archsight/web/public/vue/{InstanceRouter-CJSkGdBG.css → InstanceRouter-BCKbW-Wp.css} +1 -1
  46. data/lib/archsight/web/public/vue/InstanceRouter-DVwn6cFX.js +1 -0
  47. data/lib/archsight/web/public/vue/KindList-Bc6JpBac.js +1 -0
  48. data/lib/archsight/web/public/vue/PageView-I-RdgItl.js +1 -0
  49. data/lib/archsight/web/public/vue/QueryError-C2MuoLnX.js +1 -0
  50. data/lib/archsight/web/public/vue/ResourceList-B442GZt_.js +2 -0
  51. data/lib/archsight/web/public/vue/SearchResults-Dnv-7uqa.js +1 -0
  52. data/lib/archsight/web/public/vue/{WikiPage-TpmM1VAF.css → WikiPage-CuUi4C8v.css} +1 -1
  53. data/lib/archsight/web/public/vue/WikiPage-D6pLR-8Q.js +3 -0
  54. data/lib/archsight/web/public/vue/{index-DMhBow5t.js → index-1Vr7UBrY.js} +2 -2
  55. data/lib/archsight/web/public/vue/index-MTJVvg_J.css +1 -0
  56. data/lib/archsight/web/public/vue.html +2 -2
  57. metadata +37 -17
  58. data/lib/archsight/web/public/vue/DocPage-L0GzDFiV.js +0 -1
  59. data/lib/archsight/web/public/vue/EditorPage-B3iNbh1u.js +0 -35
  60. data/lib/archsight/web/public/vue/ErrorPage-Lro5vwhy.js +0 -2
  61. data/lib/archsight/web/public/vue/GraphView-BRKwxa--.js +0 -1
  62. data/lib/archsight/web/public/vue/HomePage-DKgI1DXr.js +0 -2
  63. data/lib/archsight/web/public/vue/InstanceRouter-CX6qxVTm.js +0 -1
  64. data/lib/archsight/web/public/vue/KindList-C556gf23.js +0 -1
  65. data/lib/archsight/web/public/vue/PageView-DAqHjL1x.js +0 -1
  66. data/lib/archsight/web/public/vue/QueryError-DvspMrsh.js +0 -1
  67. data/lib/archsight/web/public/vue/ResourceList-BZOYa68X.js +0 -2
  68. data/lib/archsight/web/public/vue/SearchResults-DaaOPG3t.js +0 -1
  69. data/lib/archsight/web/public/vue/WikiPage-Bfx92Iig.js +0 -3
  70. data/lib/archsight/web/public/vue/index-B_YGrWD8.css +0 -1
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Config holds settings of a feature of the tool, kept with the model so they are shared and versioned like it
4
+ class Archsight::Resources::Config < Archsight::Resources::Base
5
+ include_annotations :architecture
6
+
7
+ description <<~MD
8
+ Holds the settings of a feature of the tool, such as the look of the PDF export.
9
+
10
+ ## Definition
11
+
12
+ A Config is a tool-specific resource type. It carries no architecture, only settings, so that everything that
13
+ should look or behave the same is written once and shared through the resources repository instead of being
14
+ repeated in every page. It is not the per-user configuration file (tokens, URLs of other systems): that stays in
15
+ `~/.config/archsight/archsight.yaml`.
16
+
17
+ ## Type
18
+
19
+ `config/type` says which feature the settings are for; the feature looks up its own Configs by type, so every
20
+ feature can have a Config named `default`. The settings of a feature use the annotations of its own prefix.
21
+
22
+ | `config/type` | Settings | Used by |
23
+ |---------------|----------|---------|
24
+ | `pdf` | `pdf/*`: colours, fonts, logo, header and footer | [PDF export](/doc/pdf-export) |
25
+
26
+ A document picks a different Config of the type with the tag `pdf:template:<name>`; without a tag the one named
27
+ `default` is used, and without any the export has a neutral built-in look.
28
+
29
+ ## PDF settings
30
+
31
+ - **Colours** (`pdf/color-*`) are hex values (`#0b3d91`). `primary` is used for headings, the cover band and
32
+ table headers, `accent` for rules and links.
33
+ - **Fonts** (`pdf/font-*`) are family names. Fonts that are not installed fall back to the built-in ones; put
34
+ font files in a directory of the resources and name it in `pdf/font-dir` to ship them with the model.
35
+ - **Logos** (`pdf/logo`, `pdf/logo-light`) are image files (svg, png) of the resources directory, given
36
+ relative to it. `logo` goes on white (page header), `logo-light` on the coloured cover band.
37
+ - **Texts** (`pdf/footer-text`, `pdf/classification`) appear on every page.
38
+ MD
39
+
40
+ icon "settings"
41
+ layer "other"
42
+
43
+ TYPE_FORMAT = /\A[a-z][a-z0-9-]*\z/
44
+
45
+ annotation "config/type",
46
+ description: "The feature these settings are for (pdf). The feature looks up its Configs by this type",
47
+ title: "Type",
48
+ filter: :word,
49
+ summary: true,
50
+ validator: ->(value) { Archsight::Resources::Config.pattern_error(value, TYPE_FORMAT, "a lowercase word such as pdf") }
51
+
52
+ COLOR = /\A#(\h{3}|\h{6})\z/
53
+ FONT_NAME = /\A[\p{L}\p{N} ._+-]{1,80}\z/
54
+ LENGTH = /\A\d+(\.\d+)?(mm|cm|pt|in)\z/
55
+
56
+ # Colour annotations: key suffix, title, role
57
+ COLORS = {
58
+ "primary" => ["Primary colour", "headings, cover band, table headers"],
59
+ "accent" => ["Accent colour", "rules and links"],
60
+ "text" => ["Text colour", "body text"],
61
+ "muted" => ["Muted colour", "secondary text, header and footer"],
62
+ "ok" => ["Positive colour", "good status"],
63
+ "warn" => ["Warning colour", "warning status"],
64
+ "danger" => ["Danger colour", "bad status and the classification marking"]
65
+ }.freeze
66
+
67
+ COLORS.each do |key, (title, role)|
68
+ annotation "pdf/color-#{key}",
69
+ description: "#{title} as hex value (#rrggbb), used for #{role}",
70
+ title: title,
71
+ validator: ->(value) { Archsight::Resources::Config.pattern_error(value, COLOR, "a hex colour such as #0b3d91") },
72
+ sidebar: false
73
+ end
74
+
75
+ %w[body heading mono].each do |role|
76
+ annotation "pdf/font-#{role}",
77
+ description: "Font family of the #{role} text",
78
+ title: "#{role.capitalize} font",
79
+ validator: ->(value) { Archsight::Resources::Config.pattern_error(value, FONT_NAME, "a font family name") },
80
+ sidebar: false
81
+ end
82
+
83
+ annotation "pdf/font-dir",
84
+ description: "Directory with font files (ttf, otf), relative to the resources directory",
85
+ title: "Font directory",
86
+ sidebar: false
87
+
88
+ annotation "pdf/logo",
89
+ description: "Logo for the page header (svg or png), path relative to the resources directory",
90
+ title: "Logo",
91
+ validator: ->(value) { Archsight::Resources::Config.logo_error(value) },
92
+ sidebar: false
93
+ annotation "pdf/logo-light",
94
+ description: "Logo for the coloured cover band (svg or png), path relative to the resources directory",
95
+ title: "Logo (light)",
96
+ validator: ->(value) { Archsight::Resources::Config.logo_error(value) },
97
+ sidebar: false
98
+
99
+ annotation "pdf/footer-text",
100
+ description: "Text in the footer of every page (centre)",
101
+ title: "Footer text",
102
+ sidebar: false
103
+ annotation "pdf/classification",
104
+ description: "Marking shown in the footer of every page, e.g. Internal. A document can override it with " \
105
+ "the page property Classification",
106
+ title: "Classification",
107
+ sidebar: false
108
+ annotation "pdf/header-meta",
109
+ description: "Comma-separated parts of the header line: id, version, date, owner (default: all)",
110
+ title: "Header line",
111
+ sidebar: false,
112
+ validator: ->(value) { Archsight::Resources::Config.header_meta_error(value) }
113
+ annotation "pdf/lang",
114
+ description: "Language of the fixed texts (page, contents, ...)",
115
+ title: "Language",
116
+ enum: %w[en de],
117
+ sidebar: false
118
+ annotation "pdf/paper",
119
+ description: "Paper size",
120
+ title: "Paper",
121
+ enum: %w[a4 a5 us-letter],
122
+ sidebar: false
123
+ annotation "pdf/margin",
124
+ description: "Horizontal page margin as length (e.g. 16mm)",
125
+ title: "Margin",
126
+ validator: ->(value) { Archsight::Resources::Config.pattern_error(value, LENGTH, "a length such as 16mm") },
127
+ sidebar: false
128
+
129
+ HEADER_PARTS = %w[id version date owner].freeze
130
+
131
+ # Validator helpers: nil if the value is fine, else the message
132
+ def self.pattern_error(value, pattern, expected)
133
+ value.to_s.match?(pattern) ? nil : "expected #{expected}"
134
+ end
135
+
136
+ def self.logo_error(value)
137
+ ext = File.extname(value.to_s).downcase
138
+ return nil if %w[.svg .png].include?(ext) && Archsight::Assets.normalize(value.to_s)
139
+
140
+ "expected a path of an svg or png file relative to the resources directory"
141
+ end
142
+
143
+ def self.header_meta_error(value)
144
+ unknown = value.to_s.split(",").map(&:strip) - HEADER_PARTS
145
+ unknown.empty? ? nil : "unknown part #{unknown.join(", ")}; use #{HEADER_PARTS.join(", ")}"
146
+ end
147
+ end
@@ -76,6 +76,14 @@ class Archsight::Resources::Page < Archsight::Resources::Base
76
76
  title: "Properties",
77
77
  format: :multiline,
78
78
  sidebar: false
79
+ annotation "page/slides",
80
+ description: "Finished slide deck of the page: a .pdf or a self-contained .html file next to the page",
81
+ title: "Slides",
82
+ sidebar: false
83
+ annotation "page/cover",
84
+ description: "Cover image of the slide deck (a file next to the page)",
85
+ title: "Cover",
86
+ sidebar: false
79
87
  annotation "page/content",
80
88
  description: "Markdown body of the page",
81
89
  title: "Content",
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "assets"
4
+ require_relative "user_config"
5
+
6
+ module Archsight
7
+ # The finished slide deck a page shows (`slides:` in its frontmatter): a PDF, or one self-contained HTML page made by
8
+ # any slide tool. Archsight does not render slides; it serves the file and embeds it next to the page's summary.
9
+ #
10
+ # An HTML deck is somebody else's script, so it is only ever served inside a sandbox: a Content-Security-Policy with
11
+ # `sandbox allow-scripts` (no `allow-same-origin`) gives it an opaque origin, which cannot reach the API or the
12
+ # storage of Archsight, also when the file is opened on its own. Scripts may come from the hosts of the setting
13
+ # `slides.script_hosts` (`ARCHSIGHT_SLIDES_SCRIPT_HOSTS`, space or comma separated), by default the common CDNs.
14
+ module Slides
15
+ DEFAULT_SCRIPT_HOSTS = %w[https://unpkg.com https://cdn.jsdelivr.net https://cdnjs.cloudflare.com].freeze
16
+ HOST = %r{\Ahttps://[A-Za-z0-9.-]+(:\d+)?\z}
17
+
18
+ module_function
19
+
20
+ # @return [Array<String>] the hosts an HTML deck may load scripts, styles and fonts from (`https://host` only)
21
+ def script_hosts
22
+ setting = UserConfig.setting("slides", "script_hosts")
23
+ return DEFAULT_SCRIPT_HOSTS unless setting
24
+
25
+ setting.to_s.split(/[\s,]+/).grep(HOST)
26
+ end
27
+
28
+ # @return [String] the Content-Security-Policy of an HTML deck
29
+ def csp(hosts = script_hosts)
30
+ list = hosts.join(" ")
31
+ [
32
+ "sandbox allow-scripts allow-popups",
33
+ "default-src 'none'",
34
+ "script-src 'unsafe-inline' 'unsafe-eval' blob: data: #{list}".strip,
35
+ "style-src 'unsafe-inline' blob: data: #{list}".strip,
36
+ "font-src data: blob: #{list}".strip,
37
+ "img-src data: blob:",
38
+ "media-src data: blob:",
39
+ "connect-src blob: data:"
40
+ ].join("; ")
41
+ end
42
+
43
+ # The deck of a page for the API
44
+ # @return [Hash, nil] `{url:, filename:, type:, cover_url:}`, nil if the page has none or the reference is not servable
45
+ def for_page(page, resources_dir: Archsight.resources_dir)
46
+ reference = page.annotations["page/slides"].to_s.strip
47
+ return nil if reference.empty?
48
+
49
+ base = Assets.base_dir_for(page, resources_dir: resources_dir)
50
+ path = base && Assets.resolve_reference(reference, base)
51
+ return nil unless path && Assets.deck_problem(path, resources_dir: resources_dir).nil?
52
+
53
+ { url: Assets.deck_url_for(path), filename: File.basename(path), type: Assets.html_deck?(path) ? "html" : "pdf",
54
+ cover_url: cover_url(page, base, resources_dir) }
55
+ end
56
+
57
+ def cover_url(page, base, resources_dir)
58
+ reference = page.annotations["page/cover"].to_s.strip
59
+ path = !reference.empty? && Assets.resolve_reference(reference, base)
60
+ path && Assets.problem(path, resources_dir: resources_dir).nil? ? Assets.url_for(path) : nil
61
+ end
62
+
63
+ # Problems of the `page/slides` and `page/cover` references of a page, for the linter
64
+ # @return [Array<String>]
65
+ def audit(page, resources_dir:)
66
+ base = Assets.base_dir_for(page, resources_dir: resources_dir)
67
+ return [] unless base
68
+
69
+ [["page/slides", ->(path) { Assets.deck_problem(path, resources_dir: resources_dir) }, Assets::DECK_TYPES],
70
+ ["page/cover", ->(path) { Assets.problem(path, resources_dir: resources_dir) }, Assets::TYPES]].filter_map do |key, check, types|
71
+ reference = page.annotations[key].to_s.strip
72
+ next if reference.empty?
73
+
74
+ problem(key, reference, base, check, types)
75
+ end
76
+ end
77
+
78
+ def problem(key, reference, base, check, types)
79
+ path = Assets.resolve_reference(reference, base)
80
+ return "#{key} #{reference.inspect} is not a path inside the resources directory" unless path
81
+
82
+ case check.call(path)
83
+ when :type then "#{key} #{reference.inspect} must be #{types.keys.join(", ")}"
84
+ when :missing then "#{key} #{reference.inspect} does not exist (#{path})"
85
+ end
86
+ end
87
+ end
88
+ end
@@ -4,5 +4,5 @@
4
4
  # Do not edit manually.
5
5
 
6
6
  module Archsight
7
- VERSION = "0.4.3"
7
+ VERSION = "0.5.1"
8
8
  end
@@ -336,6 +336,65 @@ paths:
336
336
  error: NotFound
337
337
  message: Page 'nope' not found
338
338
 
339
+ /api/v1/decks/{path}:
340
+ get:
341
+ summary: Get a slide deck (PDF or self-contained HTML)
342
+ description: |
343
+ Serves the finished slide deck of a page (`slides:` in its frontmatter): a `.pdf` or one self-contained
344
+ `.html` file made by any slide tool. Archsight does not render slides, it serves the file and embeds it next
345
+ to the page. The URL is part of `slides.url` of `GET /api/v1/pages/{name}`.
346
+
347
+ The same boundary as the assets applies: regular files inside the resources directory, at most 25 MB, a path
348
+ that is outside, missing or of another type gets the same `404`.
349
+
350
+ An HTML deck is script of its author, so it is only ever served with a `Content-Security-Policy` that starts
351
+ with `sandbox allow-scripts` (no `allow-same-origin`): the deck cannot reach the API or the storage of
352
+ Archsight, also when the file is opened on its own. Scripts, styles and fonts may come from the hosts of the
353
+ setting `slides.script_hosts` (default: common CDNs).
354
+ operationId: getDeck
355
+ tags:
356
+ - Assets
357
+ parameters:
358
+ - name: path
359
+ in: path
360
+ required: true
361
+ description: Path relative to the resources directory, with a literal `/` between the segments
362
+ schema:
363
+ type: string
364
+ example: slides/example-deck/deck.pdf
365
+ responses:
366
+ '200':
367
+ description: The deck
368
+ headers:
369
+ Content-Security-Policy:
370
+ description: Only on HTML decks, the sandbox policy
371
+ schema:
372
+ type: string
373
+ X-Content-Type-Options:
374
+ description: Always `nosniff`
375
+ schema:
376
+ type: string
377
+ content:
378
+ application/pdf:
379
+ schema:
380
+ type: string
381
+ format: binary
382
+ text/html:
383
+ schema:
384
+ type: string
385
+ '404':
386
+ description: No such deck
387
+ content:
388
+ application/json:
389
+ schema:
390
+ $ref: '#/components/schemas/Error'
391
+ '413':
392
+ description: The file is larger than 25 MB
393
+ content:
394
+ application/json:
395
+ schema:
396
+ $ref: '#/components/schemas/Error'
397
+
339
398
  /api/v1/status/{colour}/{text}:
340
399
  get:
341
400
  summary: Get the lozenge of a status macro
@@ -374,6 +433,234 @@ paths:
374
433
  "404":
375
434
  description: Unknown colour
376
435
 
436
+ "/api/v1/kinds/Config/instances/{name}/preview":
437
+ get:
438
+ summary: Preview the look of a PDF Config
439
+ description: A fixed sample document (cover page and a page with headings, list,
440
+ quote, table with status badges and code) in the look of one `Config` of type
441
+ `pdf`, typeset by Typst like every PDF export. Served inline, for showing it
442
+ in a page. Only the Config shapes the result, so a changed colour, font or logo
443
+ is visible at once. The response carries an `ETag` (fingerprint of the document
444
+ and the files it is made of) and answers `304` for a matching `If-None-Match`.
445
+ operationId: getConfigPreview
446
+ tags:
447
+ - PDF
448
+ parameters:
449
+ - name: name
450
+ in: path
451
+ required: true
452
+ description: Name of the Config, e.g. `Config:PDF:default`
453
+ schema:
454
+ type: string
455
+ - name: part
456
+ in: query
457
+ required: false
458
+ description: "`cover` or `page` for a document of just that page (the viewer needs no navigation); without it both pages"
459
+ schema:
460
+ type: string
461
+ enum:
462
+ - cover
463
+ - page
464
+ - name: If-None-Match
465
+ in: header
466
+ required: false
467
+ description: The `ETag` of a copy the client has; a match answers `304`
468
+ schema:
469
+ type: string
470
+ responses:
471
+ '200':
472
+ description: The PDF
473
+ headers:
474
+ ETag:
475
+ schema:
476
+ type: string
477
+ Content-Disposition:
478
+ description: '`inline; filename="preview-<name>.pdf"`'
479
+ schema:
480
+ type: string
481
+ content:
482
+ application/pdf:
483
+ schema:
484
+ type: string
485
+ format: binary
486
+ '304':
487
+ description: The client's copy is current
488
+ '404':
489
+ description: No such Config
490
+ content:
491
+ application/json:
492
+ schema:
493
+ "$ref": "#/components/schemas/Error"
494
+ '422':
495
+ description: The Config is not of type `pdf`, or the sample could not be typeset
496
+ (message of typst)
497
+ content:
498
+ application/json:
499
+ schema:
500
+ "$ref": "#/components/schemas/Error"
501
+ '503':
502
+ description: typst is not installed
503
+ content:
504
+ application/json:
505
+ schema:
506
+ "$ref": "#/components/schemas/Error"
507
+
508
+ "/api/v1/kinds/{kind}/instances/{name}/pdf":
509
+ get:
510
+ summary: Download a resource as PDF
511
+ description: |
512
+ Returns one resource as a PDF document, laid out by Typst (`typst` must be installed, the container image has it).
513
+
514
+ **What it contains**: a page is exported as written (headings, tables, images, `asd` diagrams as vector graphics,
515
+ `[[links]]` as their label); any other resource becomes a generated document with its description,
516
+ properties, relations and its `architecture/diagram`. Tags steer the layout: `pdf:cover`, `pdf:toc`,
517
+ `pdf:landscape`, `pdf:draft`, `pdf:template:<name>` and `version:<x>`.
518
+
519
+ **Look**: colours, fonts, logo and the texts of header and footer come from the `Config` resource of type `pdf` named
520
+ `default` (or the one `template` / the tag names); without one a neutral look is used.
521
+
522
+ The response carries an `ETag` (a fingerprint of everything the PDF is made from, so a changed page, image,
523
+ diagram or template changes it) and answers `304` for a matching `If-None-Match`.
524
+ operationId: getInstancePdf
525
+ tags:
526
+ - PDF
527
+ parameters:
528
+ - "$ref": "#/components/parameters/kind"
529
+ - "$ref": "#/components/parameters/name"
530
+ - name: template
531
+ in: query
532
+ required: false
533
+ description: Name of a `Config` of type `pdf` to use instead of the tag or `default`
534
+ schema:
535
+ type: string
536
+ - name: draft
537
+ in: query
538
+ required: false
539
+ description: "`1` adds the draft watermark"
540
+ schema:
541
+ type: string
542
+ enum:
543
+ - '1'
544
+ - name: If-None-Match
545
+ in: header
546
+ required: false
547
+ description: The `ETag` of a copy the client has; a match answers `304`
548
+ schema:
549
+ type: string
550
+ responses:
551
+ '200':
552
+ description: The PDF
553
+ headers:
554
+ ETag:
555
+ schema:
556
+ type: string
557
+ Content-Disposition:
558
+ description: '`attachment; filename="<name>.pdf"`'
559
+ schema:
560
+ type: string
561
+ content:
562
+ application/pdf:
563
+ schema:
564
+ type: string
565
+ format: binary
566
+ '304':
567
+ description: The client's copy is current
568
+ '404':
569
+ description: Not found
570
+ content:
571
+ application/json:
572
+ schema:
573
+ "$ref": "#/components/schemas/Error"
574
+ '422':
575
+ description: The document could not be typeset (message of typst)
576
+ content:
577
+ application/json:
578
+ schema:
579
+ "$ref": "#/components/schemas/Error"
580
+ '503':
581
+ description: typst is not installed
582
+ content:
583
+ application/json:
584
+ schema:
585
+ "$ref": "#/components/schemas/Error"
586
+ "/api/v1/pages/{name}/pdf":
587
+ get:
588
+ summary: Download a page as PDF
589
+ description: |
590
+ Returns one page as a PDF document, laid out by Typst (`typst` must be installed, the container image has it).
591
+
592
+ **What it contains**: a page is exported as written (headings, tables, images, `asd` diagrams as vector graphics,
593
+ `[[links]]` as their label); any other resource becomes a generated document with its description,
594
+ properties, relations and its `architecture/diagram`. Tags steer the layout: `pdf:cover`, `pdf:toc`,
595
+ `pdf:landscape`, `pdf:draft`, `pdf:template:<name>` and `version:<x>`.
596
+
597
+ **Look**: colours, fonts, logo and the texts of header and footer come from the `Config` resource of type `pdf` named
598
+ `default` (or the one `template` / the tag names); without one a neutral look is used.
599
+
600
+ The response carries an `ETag` (a fingerprint of everything the PDF is made from, so a changed page, image,
601
+ diagram or template changes it) and answers `304` for a matching `If-None-Match`.
602
+ operationId: getPagePdf
603
+ tags:
604
+ - PDF
605
+ parameters:
606
+ - "$ref": "#/components/parameters/name"
607
+ - name: template
608
+ in: query
609
+ required: false
610
+ description: Name of a `Config` of type `pdf` to use instead of the tag or `default`
611
+ schema:
612
+ type: string
613
+ - name: draft
614
+ in: query
615
+ required: false
616
+ description: "`1` adds the draft watermark"
617
+ schema:
618
+ type: string
619
+ enum:
620
+ - '1'
621
+ - name: If-None-Match
622
+ in: header
623
+ required: false
624
+ description: The `ETag` of a copy the client has; a match answers `304`
625
+ schema:
626
+ type: string
627
+ responses:
628
+ '200':
629
+ description: The PDF
630
+ headers:
631
+ ETag:
632
+ schema:
633
+ type: string
634
+ Content-Disposition:
635
+ description: '`attachment; filename="<name>.pdf"`'
636
+ schema:
637
+ type: string
638
+ content:
639
+ application/pdf:
640
+ schema:
641
+ type: string
642
+ format: binary
643
+ '304':
644
+ description: The client's copy is current
645
+ '404':
646
+ description: Not found
647
+ content:
648
+ application/json:
649
+ schema:
650
+ "$ref": "#/components/schemas/Error"
651
+ '422':
652
+ description: The document could not be typeset (message of typst)
653
+ content:
654
+ application/json:
655
+ schema:
656
+ "$ref": "#/components/schemas/Error"
657
+ '503':
658
+ description: typst is not installed
659
+ content:
660
+ application/json:
661
+ schema:
662
+ "$ref": "#/components/schemas/Error"
663
+
377
664
  /api/v1/assets/{path}:
378
665
  get:
379
666
  summary: Get an asset (image or draw.io diagram)
@@ -1983,9 +2270,26 @@ components:
1983
2270
  type: string
1984
2271
  description: Name of the page the menu opens, present when it opens one; the crumb links to it
1985
2272
 
2273
+ PageSlides:
2274
+ type: object
2275
+ description: The finished slide deck of a page (`slides:` in the frontmatter), shown next to the page's summary
2276
+ required: [url, filename, type, cover_url]
2277
+ properties:
2278
+ url:
2279
+ type: string
2280
+ description: Where the deck is served, `/api/v1/decks/<path>`
2281
+ filename:
2282
+ type: string
2283
+ type:
2284
+ type: string
2285
+ enum: [pdf, html]
2286
+ cover_url:
2287
+ type: [string, 'null']
2288
+ description: The cover image (`cover:` in the frontmatter) as an asset URL
2289
+
1986
2290
  PageResponse:
1987
2291
  type: object
1988
- required: [name, title, status, author, owner, created, updated, properties, links, tags, toc, breadcrumb, html, backlinks]
2292
+ required: [name, title, status, author, owner, created, updated, properties, links, tags, slides, toc, breadcrumb, html, backlinks]
1989
2293
  properties:
1990
2294
  name:
1991
2295
  type: string
@@ -2035,6 +2339,11 @@ components:
2035
2339
  type: array
2036
2340
  items:
2037
2341
  type: string
2342
+ slides:
2343
+ oneOf:
2344
+ - $ref: '#/components/schemas/PageSlides'
2345
+ - type: 'null'
2346
+ description: The slide deck of the page, null if it has none or the file cannot be served
2038
2347
  toc:
2039
2348
  type: array
2040
2349
  description: Headings of the body; empty unless the frontmatter has `toc` `yes`
@@ -2120,6 +2429,8 @@ tags:
2120
2429
  description: Search and query operations
2121
2430
  - name: Pages
2122
2431
  description: Wiki pages (markdown with frontmatter), the page tree and the home page
2432
+ - name: PDF
2433
+ description: Pages and resources as PDF documents (Typst)
2123
2434
  - name: Assets
2124
2435
  description: Images and draw.io diagrams that markdown embeds
2125
2436
  - name: Macros
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../../page_tree"
4
+ require_relative "../../slides"
4
5
 
5
6
  module Archsight; end
6
7
  module Archsight::Web; end
@@ -43,6 +44,7 @@ module Archsight::Web::API::PageHelpers
43
44
  properties: page.properties.map { |key, value| { key: key, value: value, html: inline_markdown(value, page) } },
44
45
  links: annotations.select { |key, _| key.start_with?("link/") }.transform_keys { |key| key.delete_prefix("link/") },
45
46
  tags: Archsight::Resources::Page.annotation_matching("page/tags")&.value_for(page) || [],
47
+ slides: Archsight::Slides.for_page(page),
46
48
  toc: annotations["page/toc"] == "yes" ? Archsight::PageTree.toc(body) : [],
47
49
  breadcrumb: tree.breadcrumb(page),
48
50
  html: markdown(body, base: Archsight::Assets.base_dir_for(page, resources_dir: Archsight.resources_dir), page: page),
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../pdf"
4
+ require_relative "../../pdf/cache"
5
+ require_relative "../../pdf/sample_document"
6
+
7
+ module Archsight; end
8
+ module Archsight::Web; end
9
+ module Archsight::Web::API; end
10
+
11
+ # Download of a page or resource as PDF
12
+ module Archsight::Web::API::PdfHelpers
13
+ CACHE = Archsight::Pdf::Cache.new
14
+ COMPILER = Archsight::Pdf::Compiler.new
15
+
16
+ # Sends the PDF of `resource`. The ETag is the fingerprint of everything the PDF is made from, so a client (and
17
+ # the server's cache) keeps it exactly as long as the page, its images, diagrams and the template are unchanged.
18
+ # Query: `template` (name of a pdf Config), `draft=1` (watermark).
19
+ def serve_pdf(resource)
20
+ pdf_response do
21
+ Archsight::Pdf.document(db, resource, compiler: COMPILER, template: params[:template].to_s.empty? ? nil : params[:template],
22
+ draft: params[:draft] == "1")
23
+ end
24
+ end
25
+
26
+ # Sends the sample document in the look of a pdf Config, shown in the page instead of downloaded
27
+ def serve_pdf_preview(config)
28
+ pdf_response("inline") { Archsight::Pdf::SampleDocument.new(db, config, part: params[:part], pdf_images: COMPILER.pdf_images?) }
29
+ end
30
+
31
+ # Typesets the document the block builds and sends it; typst problems are answered as JSON errors
32
+ def pdf_response(disposition = "attachment")
33
+ document = yield
34
+ headers "X-Content-Type-Options" => "nosniff"
35
+ cache_control :private, :must_revalidate, max_age: 0
36
+ etag document.fingerprint
37
+ pdf = CACHE.fetch(document.fingerprint) { Archsight::Pdf.compile(document, compiler: COMPILER) }
38
+ content_type "application/pdf"
39
+ headers "Content-Disposition" => %(#{disposition}; filename="#{document.filename}")
40
+ pdf
41
+ rescue Archsight::Pdf::Unavailable => e
42
+ json_error(e.message, status: 503, error_type: "ServiceUnavailable")
43
+ rescue Archsight::Pdf::Error => e
44
+ json_error(e.message, status: 422, error_type: "UnprocessableEntity")
45
+ end
46
+ end