@dosgato/templating 0.0.98 → 0.0.100

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.
@@ -82,16 +82,14 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
82
82
  * going to render anything. For instance, if we are rendering an '.ics' variation and this component
83
83
  * is not an event, it will not be participating and we'd like to avoid doing the work in the fetch().
84
84
  *
85
- * This method returns a map of extensions where we SHOULD run fetch(). The default is only run fetch
85
+ * This method returns true for extensions where we SHOULD run fetch(). The default is only run fetch
86
86
  * on 'html'. Components that support other variations should override this method and opt in to more
87
87
  * extensions.
88
88
  *
89
- * The extensions listed should NOT include the preceding dot. In the case of an extended extension like
90
- * '.js.map', you should provide 'js.map'.
89
+ * The extension will NOT include the preceding dot. In the case of an extended extension like
90
+ * '.js.map', you should receive 'js.map'.
91
91
  */
92
- variationsToFetch(): {
93
- html: boolean;
94
- };
92
+ shouldFetchVariation(extension: string): boolean;
95
93
  /**
96
94
  * Some components may be inheritable to subpages within the same site. For instance, a site's
97
95
  * social media links may appear on every page's footer. To accomplish this in your template,
@@ -575,6 +573,22 @@ export declare abstract class Page<DataType extends PageData = any, FetchedType
575
573
  * at any time during fetch, context, or render, to set an HTTP header on the response
576
574
  */
577
575
  addHeader: (key: string, value: string | undefined) => void;
576
+ /**
577
+ * URL for the currently rendering page
578
+ *
579
+ * The URL currently being rendered. For instance, if we are in edit mode it would begin
580
+ * with /.edit/ or in preview mode, /.preview/. Useful for referencing variations of the
581
+ * current page.
582
+ *
583
+ * Does not include hash or querystring.
584
+ *
585
+ * Also see `variationUrl` below.
586
+ */
587
+ url: string;
588
+ /**
589
+ * Get a URL for the current page with a different extension
590
+ */
591
+ variationUrl(extension: string): string;
578
592
  protected passError(e: Error, path: string): void;
579
593
  constructor(page: PageRecord<DataType>, editMode: boolean, extension: string);
580
594
  }
package/dist/component.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { get, isNotBlank, titleCase } from 'txstate-utils';
2
2
  import { ResourceProvider } from './provider.js';
3
3
  function defaultWrap(info) { return info.output; }
4
- const acceptHtmlVariation = { html: true };
5
4
  /**
6
5
  * This is the primary templating class to build your templates. Subclass it and provide
7
6
  * at least a render function.
@@ -71,14 +70,14 @@ export class Component extends ResourceProvider {
71
70
  * going to render anything. For instance, if we are rendering an '.ics' variation and this component
72
71
  * is not an event, it will not be participating and we'd like to avoid doing the work in the fetch().
73
72
  *
74
- * This method returns a map of extensions where we SHOULD run fetch(). The default is only run fetch
73
+ * This method returns true for extensions where we SHOULD run fetch(). The default is only run fetch
75
74
  * on 'html'. Components that support other variations should override this method and opt in to more
76
75
  * extensions.
77
76
  *
78
- * The extensions listed should NOT include the preceding dot. In the case of an extended extension like
79
- * '.js.map', you should provide 'js.map'.
77
+ * The extension will NOT include the preceding dot. In the case of an extended extension like
78
+ * '.js.map', you should receive 'js.map'.
80
79
  */
81
- variationsToFetch() { return acceptHtmlVariation; }
80
+ shouldFetchVariation(extension) { return extension === 'html'; }
82
81
  /**
83
82
  * Inherit components from another page with matching area
84
83
  *
@@ -288,6 +287,12 @@ export class Page extends Component {
288
287
  get title() {
289
288
  return this.pageInfo.data.title ?? titleCase(this.pageInfo.name);
290
289
  }
290
+ /**
291
+ * Get a URL for the current page with a different extension
292
+ */
293
+ variationUrl(extension) {
294
+ return `${this.url.replace(/\.\w+$/, '')}.${extension}`;
295
+ }
291
296
  passError(e, path) {
292
297
  console.warn(`Recoverable issue occured during render of ${this.pageInfo.path}. Component at ${path} threw the following error:`, e);
293
298
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.98",
3
+ "version": "0.0.100",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {