react-cheminfo 0.4.1 → 0.6.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 (99) hide show
  1. package/README.md +182 -34
  2. package/lib/ecosystem/core/sites.d.ts +1 -1
  3. package/lib/ecosystem/core/sites.d.ts.map +1 -1
  4. package/lib/ecosystem/core/sites.js +10 -0
  5. package/lib/ecosystem/core/sites.js.map +1 -1
  6. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  7. package/lib/ecosystem/ui/glyphs.js +3 -0
  8. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  9. package/lib/orbital/ui/AtomicOrbitalCanvas.d.ts +5 -0
  10. package/lib/orbital/ui/AtomicOrbitalCanvas.d.ts.map +1 -1
  11. package/lib/orbital/ui/AtomicOrbitalCanvas.js +4 -3
  12. package/lib/orbital/ui/AtomicOrbitalCanvas.js.map +1 -1
  13. package/lib/orbital/ui/AtomicOrbitalViewer.d.ts +5 -0
  14. package/lib/orbital/ui/AtomicOrbitalViewer.d.ts.map +1 -1
  15. package/lib/orbital/ui/AtomicOrbitalViewer.js.map +1 -1
  16. package/lib/orbital/ui/axesGeometry.d.ts +27 -0
  17. package/lib/orbital/ui/axesGeometry.d.ts.map +1 -0
  18. package/lib/orbital/ui/axesGeometry.js +74 -0
  19. package/lib/orbital/ui/axesGeometry.js.map +1 -0
  20. package/lib/orbital/ui/camera.d.ts +7 -0
  21. package/lib/orbital/ui/camera.d.ts.map +1 -1
  22. package/lib/orbital/ui/camera.js +8 -1
  23. package/lib/orbital/ui/camera.js.map +1 -1
  24. package/lib/orbital/ui/renderAxes.d.ts +53 -0
  25. package/lib/orbital/ui/renderAxes.d.ts.map +1 -0
  26. package/lib/orbital/ui/renderAxes.js +110 -0
  27. package/lib/orbital/ui/renderAxes.js.map +1 -0
  28. package/lib/orbital/ui/viewer.d.ts +16 -0
  29. package/lib/orbital/ui/viewer.d.ts.map +1 -1
  30. package/lib/orbital/ui/viewer.js +24 -2
  31. package/lib/orbital/ui/viewer.js.map +1 -1
  32. package/lib/seo/core/documentMeta.d.ts +2 -2
  33. package/lib/seo/core/documentMeta.js +4 -3
  34. package/lib/seo/core/documentMeta.js.map +1 -1
  35. package/lib/seo/core/index.d.ts +13 -4
  36. package/lib/seo/core/index.d.ts.map +1 -1
  37. package/lib/seo/core/index.js +8 -3
  38. package/lib/seo/core/index.js.map +1 -1
  39. package/lib/seo/core/noscript.d.ts +97 -0
  40. package/lib/seo/core/noscript.d.ts.map +1 -0
  41. package/lib/seo/core/noscript.js +93 -0
  42. package/lib/seo/core/noscript.js.map +1 -0
  43. package/lib/seo/core/pageMeta.d.ts +30 -14
  44. package/lib/seo/core/pageMeta.d.ts.map +1 -1
  45. package/lib/seo/core/pageMeta.js +40 -43
  46. package/lib/seo/core/pageMeta.js.map +1 -1
  47. package/lib/seo/core/robots.d.ts +55 -0
  48. package/lib/seo/core/robots.d.ts.map +1 -0
  49. package/lib/seo/core/robots.js +70 -0
  50. package/lib/seo/core/robots.js.map +1 -0
  51. package/lib/seo/core/routes.d.ts +73 -5
  52. package/lib/seo/core/routes.d.ts.map +1 -1
  53. package/lib/seo/core/routes.js +142 -16
  54. package/lib/seo/core/routes.js.map +1 -1
  55. package/lib/seo/core/siteFiles.d.ts +39 -43
  56. package/lib/seo/core/siteFiles.d.ts.map +1 -1
  57. package/lib/seo/core/siteFiles.js +53 -69
  58. package/lib/seo/core/siteFiles.js.map +1 -1
  59. package/lib/seo/core/startDocumentMeta.d.ts +44 -0
  60. package/lib/seo/core/startDocumentMeta.d.ts.map +1 -0
  61. package/lib/seo/core/startDocumentMeta.js +47 -0
  62. package/lib/seo/core/startDocumentMeta.js.map +1 -0
  63. package/lib/seo/core/structuredData.d.ts +48 -0
  64. package/lib/seo/core/structuredData.d.ts.map +1 -0
  65. package/lib/seo/core/structuredData.js +41 -0
  66. package/lib/seo/core/structuredData.js.map +1 -0
  67. package/lib/seo/core/template.d.ts +48 -0
  68. package/lib/seo/core/template.d.ts.map +1 -0
  69. package/lib/seo/core/template.js +53 -0
  70. package/lib/seo/core/template.js.map +1 -0
  71. package/lib/seo/vite/ogCard.d.ts +9 -1
  72. package/lib/seo/vite/ogCard.d.ts.map +1 -1
  73. package/lib/seo/vite/ogCard.js +14 -4
  74. package/lib/seo/vite/ogCard.js.map +1 -1
  75. package/lib/seo/vite/prerender.d.ts +38 -7
  76. package/lib/seo/vite/prerender.d.ts.map +1 -1
  77. package/lib/seo/vite/prerender.js +68 -30
  78. package/lib/seo/vite/prerender.js.map +1 -1
  79. package/package.json +1 -1
  80. package/src/ecosystem/core/sites.ts +11 -0
  81. package/src/ecosystem/ui/glyphs.tsx +19 -0
  82. package/src/orbital/ui/AtomicOrbitalCanvas.tsx +9 -2
  83. package/src/orbital/ui/AtomicOrbitalViewer.tsx +5 -0
  84. package/src/orbital/ui/axesGeometry.ts +91 -0
  85. package/src/orbital/ui/camera.ts +9 -1
  86. package/src/orbital/ui/renderAxes.ts +190 -0
  87. package/src/orbital/ui/viewer.ts +32 -2
  88. package/src/seo/core/documentMeta.ts +5 -5
  89. package/src/seo/core/index.ts +19 -12
  90. package/src/seo/core/noscript.ts +195 -0
  91. package/src/seo/core/pageMeta.ts +54 -53
  92. package/src/seo/core/robots.ts +114 -0
  93. package/src/seo/core/routes.ts +181 -14
  94. package/src/seo/core/siteFiles.ts +58 -96
  95. package/src/seo/core/startDocumentMeta.ts +77 -0
  96. package/src/seo/core/structuredData.ts +80 -0
  97. package/src/seo/core/template.ts +54 -0
  98. package/src/seo/vite/ogCard.ts +15 -5
  99. package/src/seo/vite/prerender.ts +105 -58
@@ -7,19 +7,25 @@
7
7
  * running app, which retitles the tab after an in-app move. A page missing from
8
8
  * the table is a page a search engine only ever sees as the home page.
9
9
  */
10
+ import { stripBasePath } from "../../router/core/basePath.js";
11
+ const QUERY_OR_FRAGMENT = /[?#]/;
12
+ const TRAILING_SLASHES = /\/+$/;
13
+ // A scheme and an authority: what `location.href` hands out, and the one shape
14
+ // that cannot be confused with a path. `//host/path` is left as a path, because
15
+ // a route table is free to name one.
16
+ const ABSOLUTE_URL = /^[a-z][\d+.a-z-]*:\/\//i;
10
17
  /**
11
18
  * The route an address names.
19
+ *
20
+ * An address a route claims exactly always wins over one that claims it as a
21
+ * subtree, and between two subtrees the longer claim wins, so `/molecules/HEM`
22
+ * is a molecule rather than whatever `/` answers.
12
23
  * @param routes - Every address the site answers.
13
24
  * @param path - Absolute path, without a query string.
14
25
  * @returns Its entry, or `undefined` when the site does not know the address.
15
26
  */
16
27
  export function routeFor(routes, path) {
17
- const wanted = trimTrailingSlash(path) || '/';
18
- for (const route of routes) {
19
- if (trimTrailingSlash(route.path) === wanted)
20
- return route;
21
- }
22
- return undefined;
28
+ return exactRoute(routes, path) ?? prefixRoute(routes, path);
23
29
  }
24
30
  /**
25
31
  * The page an address opens.
@@ -27,17 +33,45 @@ export function routeFor(routes, path) {
27
33
  * An address the site does not know is described as the home page rather than
28
34
  * invented on the fly, which is what the router does with it too. The query
29
35
  * string never reaches the answer: the structure being drawn and the
30
- * configuration a shared link carries are not pages of their own.
36
+ * configuration a shared link carries are not pages of their own. An absolute
37
+ * address is read for its path, so an app handing over `location.href` after an
38
+ * in-app move is answered rather than silently described as the home page.
39
+ *
40
+ * The route table is written from the site's own root, and a server behind a
41
+ * mount is handed the address the browser asked for — `/surge/exercises` for a
42
+ * table that names `/exercises`. So the address is read at the site's own root
43
+ * first, and the four lookups run in this order:
44
+ *
45
+ * 1. the mount taken off, claimed exactly;
46
+ * 2. the address as written, claimed exactly;
47
+ * 3. the mount taken off, claimed as a subtree;
48
+ * 4. the address as written, claimed as a subtree.
49
+ *
50
+ * Exact before subtree, or a `prefix` route — a home page answering everything
51
+ * beneath it above all — would claim every mounted address and the mount would
52
+ * never come off. Stripped before as-written, or the mount itself would open
53
+ * whichever page happens to carry the mount's own name rather than the site's
54
+ * front page. Taking the address as written second is what leaves an unmounted
55
+ * caller answering exactly as before, and lets a table whose own paths start
56
+ * with the mount's name still be read.
31
57
  * @param routes - Every address the site answers.
32
- * @param url - The address, query string and fragment included.
58
+ * @param url - The address, query string and fragment included, either as a
59
+ * path or as an absolute `scheme://host/path` address.
60
+ * @param basePath - The path the site is mounted at, when the address carries
61
+ * it, written `surge`, `/surge` or `/surge/`.
62
+ * @default '' — the address is already written from the site's own root
33
63
  * @returns The route it is indexed as.
34
64
  * @throws {Error} When the table is empty, so there is no page to fall back to.
35
65
  */
36
- export function pageMetaFor(routes, url) {
66
+ export function pageMetaFor(routes, url, basePath = '') {
37
67
  const home = homeRoute(routes);
38
- const cut = url.search(/[?#]/);
39
- const path = cut === -1 ? url : url.slice(0, cut);
40
- return routeFor(routes, path) ?? home;
68
+ const path = pathOf(url);
69
+ const own = stripBasePath(basePath, path);
70
+ return (exactRoute(routes, own) ??
71
+ exactRoute(routes, path) ??
72
+ prefixRoute(routes, own) ??
73
+ prefixRoute(routes, path) ??
74
+ home);
41
75
  }
42
76
  /**
43
77
  * The page an unknown address falls back to.
@@ -49,14 +83,106 @@ export function homeRoute(routes) {
49
83
  const first = routes[0];
50
84
  if (first === undefined)
51
85
  throw new Error('a site answers at least one route');
52
- return routeFor(routes, '/') ?? first;
86
+ return exactRoute(routes, '/') ?? first;
87
+ }
88
+ /**
89
+ * Check a route table before a build reads it as a set of file names.
90
+ *
91
+ * An address written twice ships two sitemap entries and two links to a page
92
+ * only the first entry describes, and one carrying a `..` segment writes its
93
+ * file outside the build output — a real build asked for `/../escaped` and got
94
+ * a sibling of `dist`. Two addresses that differ only in an empty segment or in
95
+ * case are the same defect wearing a disguise: `//x` and `/x` both write
96
+ * `dist/x/index.html`, and so do `/About` and `/about` on the case-insensitive
97
+ * filesystem macOS and Windows ship by default — one file, two sitemap entries,
98
+ * and only one of the two descriptions survives. All of it is author
99
+ * configuration read at build time, so it is refused where it is written rather
100
+ * than repaired where it lands.
101
+ * @param routes - Every address the site answers.
102
+ * @throws {Error} When the table is empty, names one address twice — under any
103
+ * of those spellings — or carries a path that is not one.
104
+ */
105
+ export function assertRoutes(routes) {
106
+ if (routes.length === 0)
107
+ throw new Error('a site answers at least one route');
108
+ const claimed = new Set();
109
+ const folded = new Map();
110
+ for (const route of routes) {
111
+ const written = JSON.stringify(route.path);
112
+ assertPath(route.path, written);
113
+ const address = trimTrailingSlash(route.path) || '/';
114
+ if (address.includes('//')) {
115
+ throw new Error(`a route path names no empty segment: ${written}`);
116
+ }
117
+ if (claimed.has(address)) {
118
+ throw new Error(`a route path is written once: ${written}`);
119
+ }
120
+ const first = folded.get(address.toLowerCase());
121
+ if (first !== undefined) {
122
+ throw new Error(`two route paths name one file on a case-insensitive disk: ${first} and ${written}`);
123
+ }
124
+ claimed.add(address);
125
+ folded.set(address.toLowerCase(), written);
126
+ }
53
127
  }
54
128
  /**
55
- * Drop a trailing slash, so `/about/` and `/about` are one page.
129
+ * Drop the trailing slashes, so `/about/` and `/about` are one page and an
130
+ * origin written `https://host/surge//` composes one address rather than one
131
+ * with an empty segment in it.
56
132
  * @param value - A path or an origin.
57
- * @returns It, without the trailing slash `/` itself keeps.
133
+ * @returns It, without the trailing slashes `/` itself keeps.
58
134
  */
59
135
  export function trimTrailingSlash(value) {
60
- return value.length > 1 && value.endsWith('/') ? value.slice(0, -1) : value;
136
+ const trimmed = value.replace(TRAILING_SLASHES, '');
137
+ return trimmed === '' && value !== '' ? '/' : trimmed;
138
+ }
139
+ function assertPath(path, written) {
140
+ if (!path.startsWith('/')) {
141
+ throw new Error(`a route path starts at the site root: ${written}`);
142
+ }
143
+ if (QUERY_OR_FRAGMENT.test(path)) {
144
+ throw new Error(`a route path carries no query string and no fragment: ${written}`);
145
+ }
146
+ if (path.split('/').includes('..')) {
147
+ throw new Error(`a route path stays inside the site: ${written}`);
148
+ }
149
+ }
150
+ // The path half of whatever the caller had at hand: an absolute address, or a
151
+ // path already, with the query string and the fragment cut off either way.
152
+ function pathOf(url) {
153
+ if (ABSOLUTE_URL.test(url) && URL.canParse(url))
154
+ return new URL(url).pathname;
155
+ const cut = url.search(QUERY_OR_FRAGMENT);
156
+ return cut === -1 ? url : url.slice(0, cut);
157
+ }
158
+ function exactRoute(routes, path) {
159
+ const wanted = trimTrailingSlash(path) || '/';
160
+ for (const route of routes) {
161
+ if ((trimTrailingSlash(route.path) || '/') === wanted)
162
+ return route;
163
+ }
164
+ return undefined;
165
+ }
166
+ function prefixRoute(routes, path) {
167
+ const wanted = trimTrailingSlash(path) || '/';
168
+ let claimed;
169
+ let claimedLength = -1;
170
+ for (const route of routes) {
171
+ if (route.prefix !== true)
172
+ continue;
173
+ const routePath = trimTrailingSlash(route.path) || '/';
174
+ if (!isUnder(routePath, wanted))
175
+ continue;
176
+ if (routePath.length > claimedLength) {
177
+ claimed = route;
178
+ claimedLength = routePath.length;
179
+ }
180
+ }
181
+ return claimed;
182
+ }
183
+ function isUnder(routePath, path) {
184
+ // `/surgeon` is not a page of `/surge`, so a claim only holds when what
185
+ // follows it is a path of its own.
186
+ return routePath === '/' || path.startsWith(`${routePath}/`);
61
187
  }
62
188
  //# sourceMappingURL=routes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../../../src/seo/core/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACtB,MAA4B,EAC5B,IAAY;IAEZ,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;IAC9C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,MAAM;YAAE,OAAO,KAAK,CAAC;IAC7D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CACzB,MAA4B,EAC5B,GAAW;IAEX,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/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C;IAEvB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI;YAAE,SAAS;QACpC,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;QACvD,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;YAAE,SAAS;QAC1C,IAAI,SAAS,CAAC,MAAM,GAAG,aAAa,EAAE,CAAC;YACrC,OAAO,GAAG,KAAK,CAAC;YAChB,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC;QACnC,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,OAAO,CAAC,SAAiB,EAAE,IAAY;IAC9C,wEAAwE;IACxE,mCAAmC;IACnC,OAAO,SAAS,KAAK,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC;AAC/D,CAAC"}
@@ -1,10 +1,12 @@
1
1
  /**
2
- * The files and blocks a crawler reads besides the head: the sitemap, the
3
- * robots policy, the structured-data block and the list of addresses a visitor
4
- * without JavaScript can still follow.
2
+ * The sitemap, and what every other file a crawler fetches on its own is
3
+ * derived from: which site is being written, where it is served, and the path
4
+ * it is mounted at.
5
5
  *
6
- * All four are derived from the site's own record and its route table, so a
7
- * page added to the table is added to every one of them at once.
6
+ * A deployment names where it serves the site in full — origin and mount path
7
+ * in one value — because the origin is what a canonical link and a sitemap
8
+ * entry need. The mount is read back out of it here, so the addresses these
9
+ * files hand out start where the site actually answers.
8
10
  */
9
11
  import type { EcosystemSite, SiteId } from '../../ecosystem/core/sites.ts';
10
12
  import type { RouteMeta } from './routes.ts';
@@ -15,59 +17,53 @@ export interface SiteFilesOptions {
15
17
  /** Every address it answers. */
16
18
  routes: readonly RouteMeta[];
17
19
  /**
18
- * Origin every absolute address is built on.
20
+ * Where the site is served, mount path included, e.g.
21
+ * `https://learn.cheminfo.org/surge`. Every absolute address is built on it,
22
+ * and every path one of these files writes starts at its mount.
19
23
  * @default `https://<the site's host>`
20
24
  */
21
25
  origin?: string;
22
26
  }
23
27
  /**
24
28
  * Every routed address, as the sitemap lists them.
29
+ *
30
+ * A sitemap names at least one address: `<url>` is required by the sitemaps.org
31
+ * schema, and `robots.txt` advertises the file, so an empty one is reported as
32
+ * an error on every fetch rather than read as a site with nothing to index.
25
33
  * @param options - The site and its routes.
26
34
  * @returns The `sitemap.xml` document.
35
+ * @throws {Error} When the site answers no route, or names an origin that is
36
+ * not an absolute address.
27
37
  */
28
38
  export declare function sitemapXml(options: SiteFilesOptions): string;
29
39
  /**
30
- * The crawl policy.
31
- *
32
- * Our tools are meant to be found, so only the endpoints are disallowed — an
33
- * API prefix and its documentation are not pages. The sitemap is named only
34
- * because this module also writes it: a `Sitemap:` line pointing at a 404 is
35
- * reported as an error on every fetch.
36
- * @param options - The site and its routes.
37
- * @param disallow - Address prefixes to keep out of the index.
38
- * @returns The `robots.txt` document.
40
+ * The site these files are being written for.
41
+ * @param site - The site, named or passed.
42
+ * @returns Its record.
39
43
  */
40
- export declare function robotsTxt(options: SiteFilesOptions, disallow?: readonly string[]): string;
41
- /** What the structured-data block says the tool is. */
42
- export interface StructuredDataOptions extends SiteFilesOptions {
43
- /**
44
- * The schema.org application category.
45
- * @default 'EducationalApplication'
46
- */
47
- category?: string;
48
- /**
49
- * What the tool needs to run.
50
- * @default 'Any modern browser'
51
- */
52
- operatingSystem?: string;
53
- }
44
+ export declare function resolveSite(site: EcosystemSite | SiteId): EcosystemSite;
54
45
  /**
55
- * One `application/ld+json` block describing the tool.
46
+ * Where the site is served, as an absolute address without a trailing slash.
56
47
  *
57
- * It is the same on every page of a site — what varies per page is the head —
58
- * so it is written into the built page once rather than per route.
59
- * @param options - The site, and what kind of application it is.
60
- * @returns The script tag, ready to put in the head.
48
+ * It is an absolute `http` or `https` address or it is refused: a canonical
49
+ * link, an `og:url` and a sitemap entry are addresses a crawler resolves on its
50
+ * own, and one written from an origin missing its scheme is resolved against
51
+ * whatever directory the page was fetched from — pointing every page of the
52
+ * site at a sibling of itself. A dev or staging origin written `localhost:3000`
53
+ * is refused for the same reason: it parses, but as a path under a `localhost:`
54
+ * scheme, so the mount read back off it would be `/3000`.
55
+ * @param options - The site and where it is served.
56
+ * @returns The origin, mount path included when the deployment named one.
57
+ * @throws {Error} When the deployment named something that is not an absolute
58
+ * `http` or `https` address.
61
59
  */
62
- export declare function structuredDataScript(options: StructuredDataOptions): string;
60
+ export declare function originOf(options: SiteFilesOptions): string;
63
61
  /**
64
- * A readable page for a visitor, or a crawler, with no JavaScript.
65
- *
66
- * The body of our sites is an empty root element, so this is the only crawl
67
- * path through them that costs nothing to render — and it is honest: it says
68
- * the tool needs JavaScript, and links every address it answers.
69
- * @param options - The site and its routes.
70
- * @returns The `noscript` block, ready to put in the body.
62
+ * The path the deployment is mounted at, read off the address it named.
63
+ * @param options - The site and where it is served.
64
+ * @returns `''` for a site owning its host, `/surge` for one mounted under it.
65
+ * @throws {Error} When the deployment named something that is not an absolute
66
+ * address, so there is no path to read off it.
71
67
  */
72
- export declare function noscriptIndex(options: SiteFilesOptions): string;
68
+ export declare function mountPathOf(options: SiteFilesOptions): string;
73
69
  //# sourceMappingURL=siteFiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"siteFiles.d.ts","sourceRoot":"","sources":["../../../src/seo/core/siteFiles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAG3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC;IAC7B,gCAAgC;IAChC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IAC7B;;;OAGG;IACH,MAAM,CAAC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,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAQ1D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAE7D"}
@@ -1,23 +1,37 @@
1
1
  /**
2
- * The files and blocks a crawler reads besides the head: the sitemap, the
3
- * robots policy, the structured-data block and the list of addresses a visitor
4
- * without JavaScript can still follow.
2
+ * The sitemap, and what every other file a crawler fetches on its own is
3
+ * derived from: which site is being written, where it is served, and the path
4
+ * it is mounted at.
5
5
  *
6
- * All four are derived from the site's own record and its route table, so a
7
- * page added to the table is added to every one of them at once.
6
+ * A deployment names where it serves the site in full — origin and mount path
7
+ * in one value — because the origin is what a canonical link and a sitemap
8
+ * entry need. The mount is read back out of it here, so the addresses these
9
+ * files hand out start where the site actually answers.
8
10
  */
9
- import { siteById, siteDisplayName } from "../../ecosystem/core/lookup.js";
10
- import { escapeAttribute, escapeText } from "../../share/core/escape.js";
11
+ import { siteById } from "../../ecosystem/core/lookup.js";
12
+ import { basePathOf } from "../../router/core/basePath.js";
13
+ import { escapeText } from "../../share/core/escape.js";
11
14
  import { trimTrailingSlash } from "./routes.js";
12
- /** The sequence that must not appear raw inside a script element. */
13
- const SCRIPT_SAFE_LESS_THAN = String.raw `\u003c`;
15
+ // A crawler fetches what it is given over HTTP, so an origin is written in one
16
+ // of the two schemes it speaks. Parsing alone does not say that: `localhost:3000`
17
+ // parses, with `localhost:` as its scheme and `3000` as its path.
18
+ const HTTP_ORIGIN = /^https?:\/\//i;
14
19
  /**
15
20
  * Every routed address, as the sitemap lists them.
21
+ *
22
+ * A sitemap names at least one address: `<url>` is required by the sitemaps.org
23
+ * schema, and `robots.txt` advertises the file, so an empty one is reported as
24
+ * an error on every fetch rather than read as a site with nothing to index.
16
25
  * @param options - The site and its routes.
17
26
  * @returns The `sitemap.xml` document.
27
+ * @throws {Error} When the site answers no route, or names an origin that is
28
+ * not an absolute address.
18
29
  */
19
30
  export function sitemapXml(options) {
20
31
  const origin = originOf(options);
32
+ if (options.routes.length === 0) {
33
+ throw new Error('a sitemap lists at least one address');
34
+ }
21
35
  const entries = options.routes
22
36
  .map((route) => ` <url><loc>${escapeText(`${origin}${route.path}`)}</loc></url>`)
23
37
  .join('\n');
@@ -28,73 +42,43 @@ ${entries}
28
42
  `;
29
43
  }
30
44
  /**
31
- * The crawl policy.
32
- *
33
- * Our tools are meant to be found, so only the endpoints are disallowed — an
34
- * API prefix and its documentation are not pages. The sitemap is named only
35
- * because this module also writes it: a `Sitemap:` line pointing at a 404 is
36
- * reported as an error on every fetch.
37
- * @param options - The site and its routes.
38
- * @param disallow - Address prefixes to keep out of the index.
39
- * @returns The `robots.txt` document.
45
+ * The site these files are being written for.
46
+ * @param site - The site, named or passed.
47
+ * @returns Its record.
40
48
  */
41
- export function robotsTxt(options, disallow = []) {
42
- const lines = ['User-agent: *', 'Allow: /'];
43
- for (const path of disallow)
44
- lines.push(`Disallow: ${path}`);
45
- lines.push('', `Sitemap: ${originOf(options)}/sitemap.xml`, '');
46
- return lines.join('\n');
49
+ export function resolveSite(site) {
50
+ return typeof site === 'string' ? siteById(site) : site;
47
51
  }
48
52
  /**
49
- * One `application/ld+json` block describing the tool.
53
+ * Where the site is served, as an absolute address without a trailing slash.
50
54
  *
51
- * It is the same on every page of a site — what varies per page is the head —
52
- * so it is written into the built page once rather than per route.
53
- * @param options - The site, and what kind of application it is.
54
- * @returns The script tag, ready to put in the head.
55
+ * It is an absolute `http` or `https` address or it is refused: a canonical
56
+ * link, an `og:url` and a sitemap entry are addresses a crawler resolves on its
57
+ * own, and one written from an origin missing its scheme is resolved against
58
+ * whatever directory the page was fetched from — pointing every page of the
59
+ * site at a sibling of itself. A dev or staging origin written `localhost:3000`
60
+ * is refused for the same reason: it parses, but as a path under a `localhost:`
61
+ * scheme, so the mount read back off it would be `/3000`.
62
+ * @param options - The site and where it is served.
63
+ * @returns The origin, mount path included when the deployment named one.
64
+ * @throws {Error} When the deployment named something that is not an absolute
65
+ * `http` or `https` address.
55
66
  */
56
- export function structuredDataScript(options) {
57
- const site = resolveSite(options.site);
58
- const data = {
59
- '@context': 'https://schema.org',
60
- '@type': 'WebApplication',
61
- name: siteDisplayName(site),
62
- url: `${originOf(options)}/`,
63
- description: site.tagline,
64
- applicationCategory: options.category ?? 'EducationalApplication',
65
- operatingSystem: options.operatingSystem ?? 'Any modern browser',
66
- offers: { '@type': 'Offer', price: '0', priceCurrency: 'EUR' },
67
- publisher: { '@type': 'Organization', name: 'cheminfo' },
68
- };
69
- const json = JSON.stringify(data, null, 2).replaceAll('<', SCRIPT_SAFE_LESS_THAN);
70
- return `<script type="application/ld+json">\n${json}\n</script>`;
67
+ export function originOf(options) {
68
+ const origin = options.origin ?? `https://${resolveSite(options.site).host}`;
69
+ if (!HTTP_ORIGIN.test(origin) || !URL.canParse(origin)) {
70
+ throw new Error(`an origin is an absolute address, e.g. https://surge.cheminfo.org: ${JSON.stringify(origin)}`);
71
+ }
72
+ return trimTrailingSlash(origin);
71
73
  }
72
74
  /**
73
- * A readable page for a visitor, or a crawler, with no JavaScript.
74
- *
75
- * The body of our sites is an empty root element, so this is the only crawl
76
- * path through them that costs nothing to render — and it is honest: it says
77
- * the tool needs JavaScript, and links every address it answers.
78
- * @param options - The site and its routes.
79
- * @returns The `noscript` block, ready to put in the body.
75
+ * The path the deployment is mounted at, read off the address it named.
76
+ * @param options - The site and where it is served.
77
+ * @returns `''` for a site owning its host, `/surge` for one mounted under it.
78
+ * @throws {Error} When the deployment named something that is not an absolute
79
+ * address, so there is no path to read off it.
80
80
  */
81
- export function noscriptIndex(options) {
82
- const site = resolveSite(options.site);
83
- const items = options.routes
84
- .map((route) => ` <li><a href="${escapeAttribute(route.path)}">${escapeText(route.title)}</a></li>`)
85
- .join('\n');
86
- return `<noscript>
87
- <h1>${escapeText(siteDisplayName(site))}</h1>
88
- <p>${escapeText(site.tagline)} This tool needs JavaScript; these are the pages it offers:</p>
89
- <ul>
90
- ${items}
91
- </ul>
92
- </noscript>`;
93
- }
94
- function resolveSite(site) {
95
- return typeof site === 'string' ? siteById(site) : site;
96
- }
97
- function originOf(options) {
98
- return trimTrailingSlash(options.origin ?? `https://${resolveSite(options.site).host}`);
81
+ export function mountPathOf(options) {
82
+ return basePathOf(originOf(options));
99
83
  }
100
84
  //# sourceMappingURL=siteFiles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"siteFiles.js","sourceRoot":"","sources":["../../../src/seo/core/siteFiles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,qEAAqE;AACrE,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAA,QAAQ,CAAC;AAejD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAyB;IAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM;SAC3B,GAAG,CACF,CAAC,KAAK,EAAE,EAAE,CACR,eAAe,UAAU,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,cAAc,CACpE;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO;;EAEP,OAAO;;CAER,CAAC;AACF,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CACvB,OAAyB,EACzB,WAA8B,EAAE;IAEhC,MAAM,KAAK,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAC5C,KAAK,MAAM,IAAI,IAAI,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;IAC7D,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,YAAY,QA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U,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,cAAc,CACpE;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO;;EAEP,OAAO;;CAER,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAA4B;IACtD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,WAAW,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7E,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CACb,sEAAsE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAC/F,CAAC;IACJ,CAAC;IACD,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAAyB;IACnD,OAAO,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Keep the tab and the canonical link in step with the page on screen.
3
+ *
4
+ * The server, or the build that wrote one file per address, already titled the
5
+ * page it handed out; this is what a move inside the app changes, and what a
6
+ * crawler that renders the page reads afterwards. Every site did the same three
7
+ * things around it — read the address it is on, look it up in its route table,
8
+ * write the head — so all three live here, and a site says only where its
9
+ * address is read and how a change to it is noticed.
10
+ */
11
+ import type { PageMetaOptions } from './pageMeta.ts';
12
+ /** Where a site's address is read, and how a change to it is noticed. */
13
+ export interface StartDocumentMetaOptions extends Omit<PageMetaOptions, 'url' | 'image'> {
14
+ /**
15
+ * The address on screen, query string included: a path, or the absolute
16
+ * address read off the page. It is read again on every write, so a `follow`
17
+ * that tracks what it reads — a signals `effect` — notices the next page.
18
+ */
19
+ url: () => string;
20
+ /**
21
+ * How a change of page is noticed: `effect` from `@preact/signals-react`
22
+ * follows whichever signals `url` reads and hands back the function that
23
+ * stops it. Left out, the head is written once, which is what a site calling
24
+ * this from its own `popstate` handler wants.
25
+ * @default undefined — the head is written once
26
+ */
27
+ follow?: (write: () => void) => () => void;
28
+ }
29
+ /**
30
+ * Write the head of the page on screen, and keep it in step as the page
31
+ * changes.
32
+ *
33
+ * Nothing happens where there is no document — a prerender script, a unit test
34
+ * of the route table — so this is safe to call from a module either of them
35
+ * imports.
36
+ * @param options - The site, its routes, where its address is read and how a
37
+ * change to it is noticed.
38
+ * @returns The function that stops following, which does nothing when nothing
39
+ * was followed.
40
+ * @throws {Error} When the site answers no route, or names an origin that is
41
+ * not an absolute address.
42
+ */
43
+ export declare function startDocumentMeta(options: StartDocumentMetaOptions): () => void;
44
+ //# sourceMappingURL=startDocumentMeta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"startDocumentMeta.d.ts","sourceRoot":"","sources":["../../../src/seo/core/startDocumentMeta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGrD,yEAAyE;AACzE,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CACpD,eAAe,EACf,KAAK,GAAG,OAAO,CAChB;IACC;;;;OAIG;IACH,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CAC5C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,wBAAwB,GAChC,MAAM,IAAI,CAeZ"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Keep the tab and the canonical link in step with the page on screen.
3
+ *
4
+ * The server, or the build that wrote one file per address, already titled the
5
+ * page it handed out; this is what a move inside the app changes, and what a
6
+ * crawler that renders the page reads afterwards. Every site did the same three
7
+ * things around it — read the address it is on, look it up in its route table,
8
+ * write the head — so all three live here, and a site says only where its
9
+ * address is read and how a change to it is noticed.
10
+ */
11
+ import { writeDocumentMeta } from "./documentMeta.js";
12
+ import { pageDocumentMeta } from "./pageMeta.js";
13
+ /**
14
+ * Write the head of the page on screen, and keep it in step as the page
15
+ * changes.
16
+ *
17
+ * Nothing happens where there is no document — a prerender script, a unit test
18
+ * of the route table — so this is safe to call from a module either of them
19
+ * imports.
20
+ * @param options - The site, its routes, where its address is read and how a
21
+ * change to it is noticed.
22
+ * @returns The function that stops following, which does nothing when nothing
23
+ * was followed.
24
+ * @throws {Error} When the site answers no route, or names an origin that is
25
+ * not an absolute address.
26
+ */
27
+ export function startDocumentMeta(options) {
28
+ if (typeof document === 'undefined')
29
+ return stopNothing;
30
+ const write = () => {
31
+ writeDocumentMeta(pageDocumentMeta({
32
+ site: options.site,
33
+ routes: options.routes,
34
+ url: options.url(),
35
+ origin: options.origin,
36
+ }));
37
+ };
38
+ return (options.follow ?? writeOnce)(write);
39
+ }
40
+ function writeOnce(write) {
41
+ write();
42
+ return stopNothing;
43
+ }
44
+ function stopNothing() {
45
+ // Nothing was followed, so there is nothing to stop.
46
+ }
47
+ //# sourceMappingURL=startDocumentMeta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"startDocumentMeta.js","sourceRoot":"","sources":["../../../src/seo/core/startDocumentMeta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAuBjD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAiC;IAEjC,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO,WAAW,CAAC;IAExD,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,iBAAiB,CACf,gBAAgB,CAAC;YACf,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;YAClB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,SAAS,CAAC,KAAiB;IAClC,KAAK,EAAE,CAAC;IACR,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,WAAW;IAClB,qDAAqD;AACvD,CAAC"}