@lullabot/eleventy-decision-records 1.0.0

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/package.json +94 -0
  4. package/src/YYYYMMDD-decision-template.md +41 -0
  5. package/src/about.md +36 -0
  6. package/src/assets/fonts/OFL.txt +93 -0
  7. package/src/assets/fonts/gabarito-v9-latin-500.woff2 +0 -0
  8. package/src/assets/fonts/gabarito-v9-latin-700.woff2 +0 -0
  9. package/src/assets/fonts/gabarito-v9-latin-regular.woff2 +0 -0
  10. package/src/assets/icons/facebook.svg +1 -0
  11. package/src/assets/icons/github.svg +1 -0
  12. package/src/assets/icons/linkedin.svg +1 -0
  13. package/src/assets/icons/mastodon.svg +1 -0
  14. package/src/assets/icons/x.svg +1 -0
  15. package/src/assets/icons/youtube.svg +1 -0
  16. package/src/assets/images/horizontal.jpg +0 -0
  17. package/src/assets/images/vertical.jpg +0 -0
  18. package/src/assets/js/scrollable.js +49 -0
  19. package/src/assets/js/search.js +189 -0
  20. package/src/assets/js/time-since.js +31 -0
  21. package/src/assets/styles/content.css +149 -0
  22. package/src/assets/styles/fonts.css +33 -0
  23. package/src/assets/styles/footer.css +65 -0
  24. package/src/assets/styles/layout.css +483 -0
  25. package/src/assets/styles/pages.css +348 -0
  26. package/src/assets/styles/recent-decisions.css +104 -0
  27. package/src/assets/styles/reset.css +107 -0
  28. package/src/assets/styles/search-dialog.css +196 -0
  29. package/src/assets/styles/tags.css +16 -0
  30. package/src/assets/styles/tokens.css +181 -0
  31. package/src/assets/styles/typography.css +182 -0
  32. package/src/assets/styles/view-transitions.css +67 -0
  33. package/src/config.js +38 -0
  34. package/src/defaultConfig.json +99 -0
  35. package/src/index.js +227 -0
  36. package/src/index.md +28 -0
  37. package/src/lib/collections/adrs.js +10 -0
  38. package/src/lib/collections/contributors.js +15 -0
  39. package/src/lib/collections/index.js +14 -0
  40. package/src/lib/collections/topics.js +18 -0
  41. package/src/lib/data/index.js +19 -0
  42. package/src/lib/filters/collections.js +63 -0
  43. package/src/lib/filters/dates.js +68 -0
  44. package/src/lib/filters/index.js +26 -0
  45. package/src/lib/filters/strings.js +23 -0
  46. package/src/lib/plugins/bundle.js +23 -0
  47. package/src/lib/plugins/index.js +16 -0
  48. package/src/lib/plugins/markdown.js +10 -0
  49. package/src/lib/plugins/rss.js +24 -0
  50. package/src/lib/plugins/syntax-highlight.js +8 -0
  51. package/src/lib/plugins/toc.js +11 -0
  52. package/src/lib/shortcodes/icons.js +91 -0
  53. package/src/lib/shortcodes/index.js +11 -0
  54. package/src/lib/shortcodes/search.js +32 -0
  55. package/src/templates/assets/favicon.njk +7 -0
  56. package/src/templates/assets/search_index.njk +13 -0
  57. package/src/templates/layouts/adr.njk +59 -0
  58. package/src/templates/layouts/page.njk +136 -0
  59. package/src/templates/pages/contributor.njk +51 -0
  60. package/src/templates/pages/contributors.njk +46 -0
  61. package/src/templates/pages/decisions.njk +41 -0
  62. package/src/templates/pages/practice-areas.njk +48 -0
  63. package/src/templates/pages/topics.njk +50 -0
  64. package/src/templates/partials/footer.njk +12 -0
  65. package/src/templates/partials/recent-decisions.njk +33 -0
  66. package/src/templates/partials/site-nav.njk +61 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Lullabot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @lullabot/eleventy-decision-records
2
+
3
+ An [Eleventy](https://www.11ty.dev/) (v3 or v4) theme plugin for documenting architectural decision records (ADRs).
4
+
5
+ Install it into an Eleventy project and you get the listing pages, per-topic and per-contributor pages, search, and an Atom feed — without copying any of it into your repository.
6
+
7
+ ## Getting Started
8
+
9
+ ```bash
10
+ npm install @lullabot/eleventy-decision-records
11
+ ```
12
+
13
+ Eleventy is a peer dependency (3.x, or the 4.x prereleases), so install it too if you have not already:
14
+
15
+ ```bash
16
+ npm install --save-dev @11ty/eleventy
17
+ ```
18
+
19
+ Register the plugin in your Eleventy config:
20
+
21
+ ```js
22
+ import decisionRecords from '@lullabot/eleventy-decision-records';
23
+
24
+ export default function (eleventyConfig) {
25
+ eleventyConfig.addPlugin(decisionRecords, {
26
+ site: {
27
+ organization: 'Your Organization',
28
+ url: 'https://decisions.example.com/',
29
+ },
30
+ });
31
+
32
+ return {
33
+ markdownTemplateEngine: 'njk',
34
+ htmlTemplateEngine: 'njk',
35
+ dir: {
36
+ input: 'docs',
37
+ },
38
+ };
39
+ }
40
+ ```
41
+
42
+ Both template engines must be set to `njk` — the theme's pages and layouts are Nunjucks, including the markdown ones. Your project also needs `"type": "module"` in its `package.json`.
43
+
44
+ Site metadata, navigation, and practice areas are configured through the plugin options only. The theme registers them as global data, which Eleventy merges _over_ any `_data/site.json`, `_data/navigation.json`, or `_data/practiceAreas.json` in your project.
45
+
46
+ Then write decision records as markdown files in `docs/decisions/`, and build as usual:
47
+
48
+ ```bash
49
+ npx eleventy --serve
50
+ ```
51
+
52
+ The theme supplies a homepage and an about page until you add your own. Anything it provides can be replaced by putting a file of the same name in your project — see [Customizing](docs/customizing.md).
53
+
54
+ ## Documentation
55
+
56
+ - [Customizing for your organization](docs/customizing.md) — plugin options, overriding templates, styles, and icons
57
+ - [Writing ADRs](docs/writing-adrs.md) — naming convention and frontmatter fields
58
+ - [Development](docs/development.md) — commands, testing, CI/deployment
59
+ - [Architecture](docs/architecture.md) — how the plugin is put together
60
+
61
+ ## License
62
+
63
+ See [LICENSE](LICENSE) for details.
64
+
65
+ The Gabarito font files in `src/assets/fonts/` are licensed separately under the SIL Open Font License 1.1. See [src/assets/fonts/OFL.txt](src/assets/fonts/OFL.txt).
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@lullabot/eleventy-decision-records",
3
+ "version": "1.0.0",
4
+ "description": "An Eleventy theme plugin for documenting decision records",
5
+ "scripts": {
6
+ "start": "bash bin/link-fixture-site.sh && DECISION_RECORDS_DEV=1 npm --prefix tests/fixture-site run serve",
7
+ "lint": "eslint && prettier -c .",
8
+ "lint:fix": "eslint --fix && prettier -w .",
9
+ "lint-staged": "lint-staged",
10
+ "prepare": "husky",
11
+ "test": "bash bin/run-e2e.sh",
12
+ "test:config": "bash bin/prepare-fixture-site.sh && npm --prefix tests/fixture-site test",
13
+ "test:update": "bash bin/run-e2e.sh --update",
14
+ "test:local": "playwright test"
15
+ },
16
+ "exports": {
17
+ ".": "./src/index.js"
18
+ },
19
+ "files": [
20
+ "src/index.js",
21
+ "src/config.js",
22
+ "src/defaultConfig.json",
23
+ "src/index.md",
24
+ "src/about.md",
25
+ "src/YYYYMMDD-decision-template.md",
26
+ "src/lib",
27
+ "src/templates",
28
+ "src/assets"
29
+ ],
30
+ "peerDependencies": {
31
+ "@11ty/eleventy": "^3.0.0 || ^4.0.0-0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "engines": {
37
+ "node": ">=22"
38
+ },
39
+ "keywords": [
40
+ "eleventy",
41
+ "eleventy-plugin",
42
+ "eleventy-theme",
43
+ "11ty",
44
+ "adr",
45
+ "architecture-decision-record",
46
+ "decision-records",
47
+ "documentation"
48
+ ],
49
+ "author": "Lullabot, Inc.",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://github.com/Lullabot/eleventy-decision-records"
53
+ },
54
+ "homepage": "https://github.com/Lullabot/eleventy-decision-records#readme",
55
+ "bugs": {
56
+ "url": "https://github.com/Lullabot/eleventy-decision-records/issues"
57
+ },
58
+ "license": "MIT",
59
+ "type": "module",
60
+ "devDependencies": {
61
+ "@axe-core/playwright": "^4.13.0",
62
+ "@eslint/js": "^10.0.0",
63
+ "@lullabot/playwright-drupal": "^1.11.0",
64
+ "@playwright/test": "^1.62.1",
65
+ "eslint": "^10.0.3",
66
+ "eslint-config-prettier": "^10.0.3",
67
+ "eslint-plugin-prettier": "^5.2.1",
68
+ "globals": "^17.0.0",
69
+ "husky": "^9.1.7",
70
+ "lint-staged": "^17.0.0",
71
+ "prettier": "^3.4.2"
72
+ },
73
+ "dependencies": {
74
+ "@11ty/eleventy-plugin-bundle": "^3.0.7",
75
+ "@11ty/eleventy-plugin-rss": "^3.0.0",
76
+ "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2",
77
+ "@11ty/eleventy-utils": "^2.0.7",
78
+ "@js-temporal/polyfill": "^0.5.1",
79
+ "@material-symbols/svg-400": "^0.47.0",
80
+ "@orama/orama": "^3.1.18",
81
+ "eleventy-plugin-toc": "^1.1.5",
82
+ "he": "^1.2.0",
83
+ "lightningcss": "^1.32.0",
84
+ "markdown-it": "^15.0.0",
85
+ "markdown-it-anchor": "^10.0.0",
86
+ "node-html-parser": "^9.0.0",
87
+ "prettier-plugin-jinja-template": "^2.1.0",
88
+ "striptags": "^3.2.0"
89
+ },
90
+ "lint-staged": {
91
+ "*.js": "eslint",
92
+ "*.{js,njk,json,md,css,yml,yaml}": "prettier --check"
93
+ }
94
+ }
@@ -0,0 +1,41 @@
1
+ ---
2
+ # In the metadata section, # is a comment, not a heading.
3
+ # If other ADRs are added before this one is finished, set the date to
4
+ # today's date to push it to the top of the list.
5
+ date: YYYY-MM-DD
6
+
7
+ # New ADRs start at accepted, and no longer relevant ADRs are deprecated.
8
+ status: accepted
9
+
10
+ # Practice area - one of: Design, Engineering, Project Management, Strategy
11
+ practiceArea: Engineering
12
+
13
+ # Topics are freeform - see existing ADRs for ideas
14
+ topics:
15
+ - development
16
+ - testing
17
+
18
+ # Include anyone who was involved in the decision or discussions. The goal
19
+ # is to have a list for the future so the team has a starting point to ask
20
+ # for any missing historical context. This list should be sorted alphabetically
21
+ # by first name.
22
+ contributors:
23
+ - Individual A
24
+ - Individual B
25
+ - Individual C
26
+
27
+ title: A simple statement describing the decision
28
+ context: A sentence or two describing the context of the decision.
29
+ ---
30
+
31
+ <!-- Begin Markdown and HTML -->
32
+
33
+ ## Decision
34
+
35
+ <!-- Write the decision here -->
36
+ <!-- Headings will be shown in a table of contents with links -->
37
+
38
+ ## Consequences
39
+
40
+ <!-- What has to be done now that we've made the decision? -->
41
+ <!-- How will this impact us or our clients? -->
package/src/about.md ADDED
@@ -0,0 +1,36 @@
1
+ ---
2
+ title: About
3
+ description: What are architectural decision records and how we use them
4
+ permalink: /about/
5
+ eleventyExcludeFromCollections: true
6
+ ---
7
+
8
+ # {{ title }}
9
+
10
+ ## What is an ADR?
11
+
12
+ An Architectural Decision (AD) is a software design choice that addresses a functional or non-functional requirement that is architecturally significant. An Architectural Decision Record (ADR) captures a single AD — the collection of ADRs created and maintained in a project constitutes its decision log.
13
+
14
+ An ADR is immutable once accepted, beyond simple fixes and improvements that don't change the substance of the decision. Otherwise, only its status can change (i.e., become deprecated or superseded). Team members can become familiar with the whole history of decisions by reading the decision log in chronological order.
15
+
16
+ ## Why keep decision records?
17
+
18
+ - **Onboarding** — New team members can quickly understand why things are built the way they are
19
+ - **Accountability** — Avoid blindly accepting or reversing past decisions without understanding the original context
20
+ - **Process** — Formalize how the team evaluates and agrees on architectural choices
21
+
22
+ ## How to contribute
23
+
24
+ Create a new markdown file in the `{{ dirs.decisions }}/` directory using the naming convention `YYYYMMDD-url-friendly-name.md`. Use the decision template as a starting point and fill in the required frontmatter fields:
25
+
26
+ - **date** — When the decision was made
27
+ - **status** — `accepted` or `deprecated`
28
+ - **practiceArea** — One of: Design, Engineering, Project Management, Strategy
29
+ - **topics** — Freeform tags describing what the decision covers
30
+ - **contributors** — Team members involved in making the decision
31
+ - **title** — A concise summary of the decision
32
+ - **context** — Brief description of the problem or situation
33
+
34
+ ## License
35
+
36
+ This work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).
@@ -0,0 +1,93 @@
1
+ Copyright (c) 2023, The Gabarito Project Authors (https://github.com/naipefoundry/gabarito).
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://openfontlicense.org
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="96 96 448 448"><path d="M512 96L127.9 96C110.3 96 96 110.5 96 128.3L96 511.7C96 529.5 110.3 544 127.9 544L512 544C529.6 544 544 529.5 544 511.7L544 128.3C544 110.5 529.6 96 512 96zM231.4 480L165 480L165 266.2L231.5 266.2L231.5 480L231.4 480zM198.2 160C219.5 160 236.7 177.2 236.7 198.5C236.7 219.8 219.5 237 198.2 237C176.9 237 159.7 219.8 159.7 198.5C159.7 177.2 176.9 160 198.2 160zM480.3 480L413.9 480L413.9 376C413.9 351.2 413.4 319.3 379.4 319.3C344.8 319.3 339.5 346.3 339.5 374.2L339.5 480L273.1 480L273.1 266.2L336.8 266.2L336.8 295.4L337.7 295.4C346.6 278.6 368.3 260.9 400.6 260.9C467.8 260.9 480.3 305.2 480.3 362.8L480.3 480z"/></svg>
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M23.268 5.313c-.35-2.578-2.617-4.61-5.304-5.004C17.51.242 15.792 0 11.813 0h-.03c-3.98 0-4.835.242-5.288.309C3.882.692 1.496 2.518.917 5.127.64 6.412.61 7.837.661 9.143c.074 1.874.088 3.745.26 5.611.118 1.24.325 2.47.62 3.68.55 2.237 2.777 4.098 4.96 4.857 2.336.792 4.849.923 7.256.38.265-.061.527-.132.786-.213.585-.184 1.27-.39 1.774-.753a.057.057 0 0 0 .023-.043v-1.809a.052.052 0 0 0-.02-.041.053.053 0 0 0-.046-.01 20.282 20.282 0 0 1-4.709.545c-2.73 0-3.463-1.284-3.674-1.818a5.593 5.593 0 0 1-.319-1.433.053.053 0 0 1 .066-.054c1.517.363 3.072.546 4.632.546.376 0 .75 0 1.125-.01 1.57-.044 3.224-.124 4.768-.422.038-.008.077-.015.11-.024 2.435-.464 4.753-1.92 4.989-5.604.008-.145.03-1.52.03-1.67.002-.512.167-3.63-.024-5.545zm-3.748 9.195h-2.561V8.29c0-1.309-.55-1.976-1.67-1.976-1.23 0-1.846.79-1.846 2.35v3.403h-2.546V8.663c0-1.56-.617-2.35-1.848-2.35-1.112 0-1.668.668-1.67 1.977v6.218H4.822V8.102c0-1.31.337-2.35 1.011-3.12.696-.77 1.608-1.164 2.74-1.164 1.311 0 2.302.5 2.962 1.498l.638 1.06.638-1.06c.66-.999 1.65-1.498 2.96-1.498 1.13 0 2.043.395 2.74 1.164.675.77 1.012 1.81 1.012 3.12z"/></svg>
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M14.234 10.162 22.977 0h-2.072l-7.591 8.824L7.251 0H.258l9.168 13.343L.258 24H2.33l8.016-9.318L16.749 24h6.993zm-2.837 3.299-.929-1.329L3.076 1.56h3.182l5.965 8.532.929 1.329 7.754 11.09h-3.182z"/></svg>
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/></svg>
Binary file
Binary file
@@ -0,0 +1,49 @@
1
+ // Scroll boxes with nothing focusable inside cannot be scrolled from the
2
+ // keyboard in WebKit, so each one gets a tab stop while, and only while,
3
+ // its content overflows. Tables also become a named region so the stop
4
+ // is announced.
5
+ const boxes = document.querySelectorAll(
6
+ '.adr-content pre, .adr-content .table-scroll',
7
+ );
8
+
9
+ let captionCount = 0;
10
+
11
+ function label(box) {
12
+ const caption = box.querySelector('caption');
13
+ if (!caption) {
14
+ box.setAttribute('aria-label', 'Scrollable table');
15
+ return;
16
+ }
17
+ caption.id ||= `scrollable-caption-${++captionCount}`;
18
+ box.setAttribute('aria-labelledby', caption.id);
19
+ }
20
+
21
+ function update(box) {
22
+ const overflows = box.scrollWidth > box.clientWidth;
23
+ if (overflows === box.hasAttribute('tabindex')) return;
24
+
25
+ if (overflows) {
26
+ box.setAttribute('tabindex', '0');
27
+ if (box.matches('.table-scroll')) {
28
+ box.setAttribute('role', 'region');
29
+ label(box);
30
+ }
31
+ } else {
32
+ for (const name of ['tabindex', 'role', 'aria-label', 'aria-labelledby']) {
33
+ box.removeAttribute(name);
34
+ }
35
+ }
36
+ }
37
+
38
+ // The content is observed as well as the box, since a late web font can
39
+ // widen a table without the box itself changing size.
40
+ const observer = new ResizeObserver((entries) => {
41
+ for (const { target } of entries) {
42
+ update(target.closest('pre, .table-scroll'));
43
+ }
44
+ });
45
+
46
+ for (const box of boxes) {
47
+ observer.observe(box);
48
+ if (box.firstElementChild) observer.observe(box.firstElementChild);
49
+ }
@@ -0,0 +1,189 @@
1
+ import { create, load, search } from '/js/orama/index.js';
2
+ import { timeSince } from './time-since.js';
3
+
4
+ function highlightTerms(text, terms) {
5
+ const escaped = text.replace(/&/g, '&amp;').replace(/</g, '&lt;');
6
+ const pattern = terms
7
+ .map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
8
+ .join('|');
9
+ return escaped.replace(new RegExp(`(${pattern})`, 'gi'), '<mark>$1</mark>');
10
+ }
11
+
12
+ function getSnippet(text, terms, contextChars = 80) {
13
+ const lowerText = text.toLowerCase();
14
+ let bestIndex = -1;
15
+
16
+ for (const term of terms) {
17
+ const idx = lowerText.indexOf(term);
18
+ if (idx !== -1) {
19
+ bestIndex = idx;
20
+ break;
21
+ }
22
+ }
23
+
24
+ if (bestIndex === -1) {
25
+ return '';
26
+ }
27
+
28
+ const start = Math.max(0, bestIndex - contextChars);
29
+ const end = Math.min(text.length, bestIndex + contextChars);
30
+ let snippet = text.slice(start, end).trim();
31
+ if (start > 0) {
32
+ snippet = `\u2026${snippet}`;
33
+ }
34
+ if (end < text.length) {
35
+ snippet = `${snippet}\u2026`;
36
+ }
37
+
38
+ return highlightTerms(snippet, terms);
39
+ }
40
+
41
+ (async () => {
42
+ const dialog = document.getElementById('search-dialog');
43
+ const searchInput = dialog.querySelector('input[type="search"]');
44
+ const resultsList = dialog.querySelector('ol');
45
+ const summary = dialog.querySelector('.results-summary');
46
+ const status = dialog.querySelector('[aria-live="polite"]');
47
+
48
+ // Debounce announcements past the typing echo (VoiceOver's echo preempts
49
+ // polite announcements rather than queueing behind them), and write in a
50
+ // single mutation — every region mutation can cancel in-flight speech.
51
+ let announceTimer;
52
+ function announce(text) {
53
+ summary.textContent = text;
54
+ clearTimeout(announceTimer);
55
+ announceTimer = setTimeout(() => {
56
+ status.textContent = text;
57
+ }, 150);
58
+ }
59
+ const resultTemplate = dialog.querySelector('template').content;
60
+
61
+ let db;
62
+ let initPromise = null;
63
+
64
+ const SCHEMA = {
65
+ url: 'string',
66
+ title: 'string',
67
+ topics: 'string[]',
68
+ context: 'string',
69
+ content: 'string',
70
+ status: 'string',
71
+ date: 'string',
72
+ };
73
+
74
+ function initializeSearch() {
75
+ initPromise ??= (async () => {
76
+ const response = await fetch('/searchindex.json');
77
+ if (!response.ok) {
78
+ throw new Error(`Search index returned ${response.status}`);
79
+ }
80
+ const rawData = await response.json();
81
+
82
+ db = create({ schema: SCHEMA });
83
+ load(db, rawData);
84
+ })().catch((error) => {
85
+ // Allow the next search to retry the fetch.
86
+ initPromise = null;
87
+ throw error;
88
+ });
89
+ return initPromise;
90
+ }
91
+
92
+ async function doSearch() {
93
+ const query = searchInput.value.trim();
94
+ if (!query) {
95
+ resultsList.innerHTML = '';
96
+ clearTimeout(announceTimer);
97
+ summary.textContent = '';
98
+ status.textContent = '';
99
+ return;
100
+ }
101
+
102
+ resultsList.innerHTML = '';
103
+ const loading = document.createElement('li');
104
+ loading.textContent = 'Loading search\u2026';
105
+ resultsList.append(loading);
106
+
107
+ try {
108
+ await initializeSearch();
109
+ } catch {
110
+ resultsList.innerHTML = '';
111
+ announce('Search is unavailable right now — please try again.');
112
+ return;
113
+ }
114
+
115
+ const { hits } = search(db, {
116
+ term: query,
117
+ properties: ['title', 'topics', 'context', 'content'],
118
+ boost: { title: 3, topics: 2, context: 1.5 },
119
+ tolerance: 1,
120
+ threshold: 0.6,
121
+ limit: 50,
122
+ });
123
+
124
+ const queryTerms = query
125
+ .toLowerCase()
126
+ .split(/\s+/)
127
+ .filter((t) => t.length > 0);
128
+
129
+ let results = hits.map((hit) => ({
130
+ ...hit.document,
131
+ href: hit.document.url,
132
+ snippet: getSnippet(hit.document.content, queryTerms),
133
+ }));
134
+
135
+ results.sort((a, b) => {
136
+ if (a.status === b.status) return 0;
137
+ if (a.status === 'deprecated') return 1;
138
+ if (b.status === 'deprecated') return -1;
139
+ return 0;
140
+ });
141
+
142
+ results = results.map((result, i) => {
143
+ const entry = resultTemplate.cloneNode(true);
144
+
145
+ const li = entry.querySelector('li');
146
+ li.style.animationDelay = `${i * 50}ms`;
147
+
148
+ entry.querySelector('a').innerHTML = highlightTerms(
149
+ result.title,
150
+ queryTerms,
151
+ );
152
+ entry.querySelector('a').href = result.href;
153
+ entry.querySelector('.snippet').innerHTML = result.snippet;
154
+ entry.querySelector('.status').textContent = result.status;
155
+ entry.querySelector('.age').textContent = timeSince(result.date);
156
+
157
+ const tagsEl = entry.querySelector('.tags');
158
+ for (const tag of result.topics) {
159
+ const span = document.createElement('span');
160
+ span.textContent = tag;
161
+ tagsEl.append(span);
162
+ }
163
+
164
+ return entry;
165
+ });
166
+
167
+ resultsList.innerHTML = '';
168
+ resultsList.append(...results);
169
+ if (results.length) {
170
+ const s = results.length === 1 ? '' : 's';
171
+ announce(`${results.length} result${s} for \u201c${query}\u201d`);
172
+ } else {
173
+ announce(`No results found for \u201c${query}\u201d`);
174
+ }
175
+ }
176
+
177
+ // Start fetching the index on the first keystroke, ahead of the debounce.
178
+ searchInput.addEventListener(
179
+ 'input',
180
+ () => initializeSearch().catch(() => {}),
181
+ { once: true },
182
+ );
183
+
184
+ let debounceTimer;
185
+ searchInput.addEventListener('input', () => {
186
+ clearTimeout(debounceTimer);
187
+ debounceTimer = setTimeout(doSearch, 250);
188
+ });
189
+ })();
@@ -0,0 +1,31 @@
1
+ // TODO: Replace with Temporal (matching src/lib/filters/dates.js) once
2
+ // browser support is baseline:
3
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal#browser_compatibility
4
+ export function timeSince(isoDate) {
5
+ const then = new Date(isoDate);
6
+ const now = new Date();
7
+ let years = now.getUTCFullYear() - then.getUTCFullYear();
8
+ let months = now.getUTCMonth() - then.getUTCMonth();
9
+ let days = now.getUTCDate() - then.getUTCDate();
10
+
11
+ if (days < 0) {
12
+ months -= 1;
13
+ days += new Date(now.getUTCFullYear(), now.getUTCMonth(), 0).getDate();
14
+ }
15
+ if (months < 0) {
16
+ years -= 1;
17
+ months += 12;
18
+ }
19
+
20
+ const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'always' });
21
+ if (years > 0) {
22
+ return rtf.format(-years, 'year');
23
+ }
24
+ if (months > 0) {
25
+ return rtf.format(-months, 'month');
26
+ }
27
+ if (days > 0) {
28
+ return rtf.format(-days, 'day');
29
+ }
30
+ return 'today';
31
+ }