@rr0/cms 0.3.61 → 0.3.62

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.
@@ -25,17 +25,32 @@ export interface CMSGeneratorOptions {
25
25
  };
26
26
  siteBaseUrl: string;
27
27
  /**
28
- * A file holding the part of `netlify.toml` that is NOT derived from `.htaccess` — what a host
29
- * needs that Apache cannot say: a redirect carrying its own status or `force`, one to an absolute
30
- * URL on another domain, a header scoped to anything narrower than the whole site, a build or
31
- * plugin section.
28
+ * Where the redirects read out of `.htaccess` are written, and in which of Netlify's two formats.
32
29
  *
33
- * Without it those lines have nowhere to live but the generated file itself, where every full
34
- * build wipes them — which is exactly how this site's `ufoathome.org` redirects and its CORS
35
- * headers disappeared twice. See ssg-api's HtAccessReplaceCommand for the mechanism; naming a file
36
- * that is not there fails the build rather than dropping it in silence.
30
+ * Defaults to a `netlify.toml` at the repository root, which is what this has always produced.
31
+ *
32
+ * The `redirects` format writes Netlify's plainer `_redirects` instead, and the reason to choose
33
+ * it is WHERE it can be put. `netlify.toml` is read from the CLONE, before any build command runs,
34
+ * so a site built by Netlify from git must keep it in version control — a generated file, tracked,
35
+ * inviting exactly the hand-edit that overwrites itself. `_redirects` and `_headers` are read from
36
+ * the DEPLOYED directory, so they can be build output like everything else and never need to be
37
+ * committed at all.
38
+ *
39
+ * `preambleFile` holds whatever the `.htaccess` cannot say and is emitted ahead of the generated
40
+ * lines: a redirect carrying its own status or `force` (`301!` in the plain format), one from an
41
+ * absolute URL on another domain. Without it those lines have nowhere to live but the generated
42
+ * file itself, where every full build wipes them — which is exactly how one site's `ufoathome.org`
43
+ * redirects and its CORS headers disappeared twice. See ssg-api's HtAccessReplaceCommand; naming a
44
+ * file that is not there fails the build rather than dropping it in silence.
45
+ *
46
+ * Headers have no generator because `.htaccess` here carries no `Header` directive worth
47
+ * translating: in the plain format they are simply a static `_headers` file among the copies.
37
48
  */
38
- netlifyPreambleFile?: string;
49
+ netlify?: {
50
+ format: "toml" | "redirects";
51
+ outputPath: string;
52
+ preambleFile?: string;
53
+ };
39
54
  timeFormat: Intl.DateTimeFormatOptions;
40
55
  directoryPages: string[];
41
56
  ufoCaseDirectoryFile: string;
@@ -5,7 +5,7 @@ import { CaseDirectoryStep, CaseFactory, CaseService } from "./science/crypto/uf
5
5
  import { cities, CityService, CmsOrganizationFactory, countries, departments, DepartmentService, OrganizationService, regions, RegionService } from "./org/index.js";
6
6
  import { RR0ContextImpl } from "./RR0Context.js";
7
7
  import { HtmlTable } from "./util/index.js";
8
- import { ClassDomReplaceCommand, CopyStep, DomReplaceCommand, HtAccessToNetlifyConfigReplaceCommand, HtmlFileContents, Ssg, SsiIncludeReplaceCommand } from "ssg-api";
8
+ import { ClassDomReplaceCommand, CopyStep, DomReplaceCommand, HtAccessToNetlifyConfigReplaceCommand, HtAccessToNetlifyRedirectsReplaceCommand, HtmlFileContents, Ssg, SsiIncludeReplaceCommand } from "ssg-api";
9
9
  import { AuthorReplaceCommand, PeopleDirectoryStepFactory, PeopleReplacerFactory } from "./people/index.js";
10
10
  import { PersistentSourceRegistry, SourceFileCounter, SourceIndexStep, SourceRenderer, SourceReplacer, SourceReplacerFactory } from "./source/index.js";
11
11
  import { NoteFileCounter, NoteRenderer, NoteReplacer, NoteReplacerFactory } from "./note/index.js";
@@ -75,6 +75,7 @@ export class CMSGenerator {
75
75
  this.timeService = new TimeService(dataService, timeOptions);
76
76
  }
77
77
  async generate(args) {
78
+ var _a;
78
79
  const timeContext = new TimeContext();
79
80
  const context = new RR0ContextImpl(this.options.locale, timeContext, this.config, undefined, undefined, undefined, this);
80
81
  context.setVar("mapsApiKey", this.options.googleMapsApiKey);
@@ -134,12 +135,15 @@ export class CMSGenerator {
134
135
  return HtmlTable.create(obj, headers);
135
136
  }
136
137
  }();
138
+ const netlify = (_a = this.options.netlify) !== null && _a !== void 0 ? _a : { format: "toml", outputPath: "netlify.toml" };
137
139
  const htAccessToNetlifyConfig = {
138
140
  replacements: [
139
- new HtAccessToNetlifyConfigReplaceCommand(this.options.siteBaseUrl, this.options.netlifyPreambleFile)
141
+ netlify.format === "redirects"
142
+ ? new HtAccessToNetlifyRedirectsReplaceCommand(this.options.siteBaseUrl, netlify.preambleFile)
143
+ : new HtAccessToNetlifyConfigReplaceCommand(this.options.siteBaseUrl, netlify.preambleFile)
140
144
  ],
141
145
  roots: [".htaccess"],
142
- getOutputPath: (_context) => "netlify.toml"
146
+ getOutputPath: (_context) => netlify.outputPath
143
147
  };
144
148
  const contentRoots = this.options.contentRoots;
145
149
  const contentStepOptions = {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@rr0/cms",
3
3
  "type": "module",
4
4
  "author": "Jérôme Beau <rr0@rr0.org> (https://rr0.org)",
5
- "version": "0.3.61",
5
+ "version": "0.3.62",
6
6
  "description": "RR0 Content Management System (CMS)",
7
7
  "exports": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",