@dosgato/templating 0.0.119 → 0.0.121
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.
- package/dist/apitemplate.d.ts +13 -2
- package/dist/links.d.ts +5 -5
- package/dist/links.js +12 -9
- package/package.json +2 -2
package/dist/apitemplate.d.ts
CHANGED
|
@@ -70,14 +70,25 @@ export interface APITemplate<DataType> {
|
|
|
70
70
|
name: string;
|
|
71
71
|
/**
|
|
72
72
|
* Each template must provide a function that returns links from its data so that they
|
|
73
|
-
* can be indexed. Only fields that are links need to be returned
|
|
74
|
-
* text will be extracted automatically from any text returned by getFulltext (see below)
|
|
73
|
+
* can be indexed. Only fields that are links need to be returned as links inside rich editor
|
|
74
|
+
* text will be extracted automatically from any text returned by getFulltext (see below).
|
|
75
|
+
* Examples of links to include would be links refereced by `href` and `src` attributes in
|
|
76
|
+
* anchor, image, and video elements.
|
|
77
|
+
* @note You do not need to filter the links returned to ensure they're defined as that can
|
|
78
|
+
* be done by the routine that calls `getLinks`.
|
|
79
|
+
* @note If you are certain of the `LinkDefinition` translations allowed for the string of
|
|
80
|
+
* the link you would return in this array it would be a good idea to go ahead and coerce
|
|
81
|
+
* the string to the full type associated with it.
|
|
75
82
|
*/
|
|
76
83
|
getLinks?: LinkGatheringFn<DataType>;
|
|
77
84
|
/**
|
|
78
85
|
* Each template must provide the text from any text or rich editor data it possesses, so that
|
|
79
86
|
* the text can be decomposed into words and indexed for fulltext searches. Any text returned
|
|
80
87
|
* by this function will also be scanned for links.
|
|
88
|
+
* Examples of text to include would be any text from data that's rendered as visible text content
|
|
89
|
+
* but not things like dates and times.
|
|
90
|
+
* @note You do not need to filter the text elements returned to ensure they're defined as that
|
|
91
|
+
* can be done by the routine that calls `getFulltext`.
|
|
81
92
|
*/
|
|
82
93
|
getFulltext?: FulltextGatheringFn<DataType>;
|
|
83
94
|
/**
|
package/dist/links.d.ts
CHANGED
|
@@ -79,11 +79,11 @@ export interface DataFolderLink {
|
|
|
79
79
|
export type LinkDefinition = AssetLink | AssetFolderLink | PageLink | WebLink | DataLink | DataFolderLink;
|
|
80
80
|
/**
|
|
81
81
|
* This function is used by template definitions to help them identify links inside large blocks
|
|
82
|
-
* of text and return them for indexing, and by render definitions to help replace them with the actual URLs
|
|
83
|
-
|
|
82
|
+
* of text and return them for indexing, and by render definitions to help replace them with the actual URLs.
|
|
83
|
+
* @note This does not mean it finds raw links and converts them but that it finds and returns `LinkDefinition`
|
|
84
|
+
* conformant object strings in the text and returns those. */
|
|
84
85
|
export declare function extractLinksFromText(text: string | undefined): LinkDefinition[];
|
|
85
86
|
/**
|
|
86
|
-
* This function is used by render definitions to replace
|
|
87
|
-
* URLs they point to at render time.
|
|
88
|
-
*/
|
|
87
|
+
* This function is used by render definitions to replace `LinkDefinition` conformant link object text in large
|
|
88
|
+
* blocks with the actual URLs they point to at render time. */
|
|
89
89
|
export declare function replaceLinksInText(text: string, resolved: Map<string, string | undefined>): string;
|
package/dist/links.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import { htmlDecode } from 'txstate-utils';
|
|
2
|
+
const LinkRegex = /{.*"type"\s?:\s?"\w+".*?}/g;
|
|
3
|
+
const HTMLEscapedLinkRegex = /{.*"type"\s?:\s?"\w+".*?}/g;
|
|
2
4
|
/**
|
|
3
5
|
* This function is used by template definitions to help them identify links inside large blocks
|
|
4
|
-
* of text and return them for indexing, and by render definitions to help replace them with the actual URLs
|
|
5
|
-
|
|
6
|
+
* of text and return them for indexing, and by render definitions to help replace them with the actual URLs.
|
|
7
|
+
* @note This does not mean it finds raw links and converts them but that it finds and returns `LinkDefinition`
|
|
8
|
+
* conformant object strings in the text and returns those. */
|
|
6
9
|
export function extractLinksFromText(text) {
|
|
7
10
|
if (!text)
|
|
8
11
|
return [];
|
|
9
|
-
const matches = text.matchAll(LinkRegex);
|
|
10
|
-
|
|
12
|
+
const matches = Array.from(text.matchAll(LinkRegex)).map(m => JSON.parse(m[0]));
|
|
13
|
+
const morematches = Array.from(text.matchAll(HTMLEscapedLinkRegex)).map(m => JSON.parse(htmlDecode(m[0])));
|
|
14
|
+
return matches.concat(morematches);
|
|
11
15
|
}
|
|
12
16
|
/**
|
|
13
|
-
* This function is used by render definitions to replace
|
|
14
|
-
* URLs they point to at render time.
|
|
15
|
-
*/
|
|
17
|
+
* This function is used by render definitions to replace `LinkDefinition` conformant link object text in large
|
|
18
|
+
* blocks with the actual URLs they point to at render time. */
|
|
16
19
|
export function replaceLinksInText(text, resolved) {
|
|
17
|
-
return text.replace(LinkRegex, m => resolved.get(m) ?? 'dg-broken-link');
|
|
20
|
+
return text.replace(LinkRegex, m => resolved.get(m) ?? 'dg-broken-link').replace(HTMLEscapedLinkRegex, m => resolved.get(htmlDecode(m)) ?? 'dg-broken-link');
|
|
18
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dosgato/templating",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.121",
|
|
4
4
|
"description": "A library to support building templates for dosgato CMS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"build": "rm -rf dist && tsc"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"txstate-utils": "^1.8.
|
|
17
|
+
"txstate-utils": "^1.8.8"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "^18.7.11",
|