@dosgato/templating 0.0.19 → 0.0.20

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.
@@ -90,3 +90,15 @@ export interface Migration {
90
90
  }
91
91
  export declare type LinkGatheringFn = (data: any) => LinkDefinition[];
92
92
  export declare type FulltextGatheringFn = (data: any) => string[];
93
+ /**
94
+ * This function is used by API template definitions to help them identify links inside large blocks
95
+ * of text and return them for indexing.
96
+ */
97
+ export declare function extractLinksFromText(text: string): LinkDefinition[];
98
+ /**
99
+ * This function is used by API template definitions to help them identify all the searchable
100
+ * words in a large block of text and return them for indexing.
101
+ */
102
+ export declare function getKeywords(text: string, options?: {
103
+ stopwords?: boolean;
104
+ }): string[];
@@ -1,2 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getKeywords = exports.extractLinksFromText = void 0;
4
+ const stopwords_1 = require("./stopwords");
5
+ /**
6
+ * This function is used by API template definitions to help them identify links inside large blocks
7
+ * of text and return them for indexing.
8
+ */
9
+ function extractLinksFromText(text) {
10
+ const matches = text.matchAll(/{.*"type"\s?:\s+"\w+".*?}/gi);
11
+ return Array.from(matches).map(m => JSON.parse(m[0]));
12
+ }
13
+ exports.extractLinksFromText = extractLinksFromText;
14
+ /**
15
+ * This function is used by API template definitions to help them identify all the searchable
16
+ * words in a large block of text and return them for indexing.
17
+ */
18
+ function getKeywords(text, options) {
19
+ return Array.from(new Set(text
20
+ .toLocaleLowerCase()
21
+ .normalize('NFD').replace(/\p{Diacritic}/gu, '')
22
+ .split(/[^\w-]+/)
23
+ .flatMap(word => word.includes('-') ? word.split('-').concat(word.replace('-', '')) : [word])
24
+ .filter(word => word.length > 2 && (options?.stopwords === false || !stopwords_1.stopwords[word]) && isNaN(Number(word)))));
25
+ }
26
+ exports.getKeywords = getKeywords;
@@ -1,4 +1,5 @@
1
1
  import { EditBarOpts } from './editbar';
2
+ import { LinkDefinition } from './links';
2
3
  import { ResourceProvider } from './provider';
3
4
  /**
4
5
  * This is the primary templating class to build your templates. Subclass it and provide
@@ -18,6 +19,19 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
18
19
  parent?: Component;
19
20
  page?: Page;
20
21
  hadError: boolean;
22
+ /**
23
+ * This function will be provided by the rendering server and should be used inside your fetch,
24
+ * method to convert a link, as input by a user, into a URL suitable for an href, or optionally
25
+ * an absolute URL suitable for a backend http request or non-HTML document like an RSS feed.
26
+ */
27
+ resolveLink: (link: string | LinkDefinition, absolute?: boolean) => Promise<string>;
28
+ /**
29
+ * This function will be provided by the rendering server and should be used inside your fetch
30
+ * method to prepare editor-provided HTML for rendering. It will do things like find and resolve
31
+ * link definitions in the internal dosgato format and clean up tags that were accidentally left
32
+ * open to protect overall page integrity.
33
+ */
34
+ processRich: (text: string) => Promise<string>;
21
35
  /**
22
36
  * The first phase of rendering a component is the fetch phase. Each component may
23
37
  * provide a fetch method that looks up data it needs from external sources. This step
@@ -31,14 +45,14 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
31
45
  */
32
46
  fetch(editMode: boolean): Promise<FetchedType>;
33
47
  /**
34
- * The second phase of rendering a component is the context phase. This step is TOP-DOWN,
35
- * each component will receive the parent component's context, modify it as desired,
36
- * and then pass context to its children.
48
+ * The second phase of rendering a component is the context phase. This step is TOP-DOWN and
49
+ * NON-MUTATING. Each component will receive the parent component's context and then pass a
50
+ * NEW context object to its children.
37
51
  *
38
52
  * This is useful for rendering logic that is sensitive to where the component exists in
39
53
  * the hierarchy of the page. For instance, if a parent component has used an h2 header
40
54
  * already, it will want to inform its children so that they can use h3 next, and they inform
41
- * their children that h4 is next, and so on. (Header level tracking is actually required in
55
+ * their children that h4 is next, and so on. (Header level tracking is supported by default in
42
56
  * dosgato CMS.)
43
57
  *
44
58
  * This function may return a promise in case you need to do something asynchronous based on
package/dist/component.js CHANGED
@@ -45,14 +45,14 @@ class Component extends provider_1.ResourceProvider {
45
45
  return undefined;
46
46
  }
47
47
  /**
48
- * The second phase of rendering a component is the context phase. This step is TOP-DOWN,
49
- * each component will receive the parent component's context, modify it as desired,
50
- * and then pass context to its children.
48
+ * The second phase of rendering a component is the context phase. This step is TOP-DOWN and
49
+ * NON-MUTATING. Each component will receive the parent component's context and then pass a
50
+ * NEW context object to its children.
51
51
  *
52
52
  * This is useful for rendering logic that is sensitive to where the component exists in
53
53
  * the hierarchy of the page. For instance, if a parent component has used an h2 header
54
54
  * already, it will want to inform its children so that they can use h3 next, and they inform
55
- * their children that h4 is next, and so on. (Header level tracking is actually required in
55
+ * their children that h4 is next, and so on. (Header level tracking is supported by default in
56
56
  * dosgato CMS.)
57
57
  *
58
58
  * This function may return a promise in case you need to do something asynchronous based on
package/dist/links.d.ts CHANGED
@@ -63,15 +63,3 @@ export interface DataFolderLink {
63
63
  path: string;
64
64
  }
65
65
  export declare type LinkDefinition = AssetLink | AssetFolderLink | PageLink | WebLink | DataLink | DataFolderLink;
66
- /**
67
- * This function is used by API template definitions to help them identify links inside large blocks
68
- * of text and return them for indexing.
69
- */
70
- export declare function extractLinksFromText(text: string): LinkDefinition[];
71
- /**
72
- * This function is used by API template definitions to help them identify all the searchable
73
- * words in a large block of text and return them for indexing.
74
- */
75
- export declare function getKeywords(text: string, options?: {
76
- stopwords?: boolean;
77
- }): string[];
package/dist/links.js CHANGED
@@ -1,26 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getKeywords = exports.extractLinksFromText = void 0;
4
- const stopwords_1 = require("./stopwords");
5
- /**
6
- * This function is used by API template definitions to help them identify links inside large blocks
7
- * of text and return them for indexing.
8
- */
9
- function extractLinksFromText(text) {
10
- const matches = text.matchAll(/{.*"type"\s?:\s+"\w+".*?}/gi);
11
- return Array.from(matches).map(m => JSON.parse(m[0]));
12
- }
13
- exports.extractLinksFromText = extractLinksFromText;
14
- /**
15
- * This function is used by API template definitions to help them identify all the searchable
16
- * words in a large block of text and return them for indexing.
17
- */
18
- function getKeywords(text, options) {
19
- return Array.from(new Set(text
20
- .toLocaleLowerCase()
21
- .normalize('NFD').replace(/\p{Diacritic}/gu, '')
22
- .split(/[^\w-]+/)
23
- .flatMap(word => word.includes('-') ? word.split('-').concat(word.replace('-', '')) : [word])
24
- .filter(word => word.length > 2 && (options?.stopwords === false || !stopwords_1.stopwords[word]) && isNaN(Number(word)))));
25
- }
26
- exports.getKeywords = getKeywords;
@@ -0,0 +1,5 @@
1
+ import { ContextBase } from './component';
2
+ export declare function printHeader(ctx: ContextBase, content: string): string;
3
+ export declare function advanceHeader(ctx: ContextBase, content?: string): {
4
+ headerLevel: number;
5
+ };
package/dist/render.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.advanceHeader = exports.printHeader = void 0;
4
+ const txstate_utils_1 = require("txstate-utils");
5
+ function printHeader(ctx, content) {
6
+ if ((0, txstate_utils_1.isBlank)(content))
7
+ return '';
8
+ const level = (ctx.headerLevel ?? 0) + 1;
9
+ if (level < 1)
10
+ return `<h1>${content}</h1>`;
11
+ if (level > 6)
12
+ return `<h6>${content}</h1>`;
13
+ return `<h${level}>${content}</h${level}>`;
14
+ }
15
+ exports.printHeader = printHeader;
16
+ function advanceHeader(ctx, content) {
17
+ const ret = { ...ctx };
18
+ if (!(0, txstate_utils_1.isBlank)(content))
19
+ ret.headerLevel = (ret.headerLevel ?? 0) + 1;
20
+ return ret;
21
+ }
22
+ exports.advanceHeader = advanceHeader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "exports": {
6
6
  "require": "./dist/index.js",